I don't understand document.body.scrollTop - scrolltop

document.body.scrollTop doesn't work. but document.documentElement.scrollTop works . why?
console.log(document.documentElement.scrollTop);
console.log(document.body.scrollTop);

Related

LUA - Simple code supposed to work isn't working (Roblox)

Simple piece of code, supposed to work isn't working... I really can't understand this.
This is code:
local asd = 1
if not asd == nil then
print("works")
end
That's it, is not printing "works", ;-; sorry if I'm missing something.
Operator precedence fooled you:
if not asd == nil then
is equivalent to
if (not asd) == nil then
Try
if not (asd == nil) then
Sorry, answer was doing
local asd = 1
if asd ~= nil then
print("works")
end
I didn't even knew that ~= is a thing wow

Repeating code, bad practice

I have this piece of code
#liked_tweet = LikedTweet.new
#liked_tweet = #liked_tweet.existing_like( params[:tweet_id], current_user.id )
Is there any better way how to write this? I have a feeling that this is just bad practise. Or is it perfectly ok?
thank you very much for your time
#liked_tweet = LikedTweet.where(tweet_id: params[:tweet_id], user_id: current_user.id).first_or_create
#liked_tweet = #liked_tweet.existing_like( params[:tweet_id], current_user.id ) || LikedTweet.new

How do I test for a hash being a valid set?

I'm putting together some spock tests for a Jenkins plugin and along the way I want to check the build variables match one of some valid ones. These are coming from a MatrixProject
but how do I do that?
I have this but it looks a bit clunky but does work
gen_build.getRuns.every(){
it.getBuildVariables().equals([axis1: 'textz', axis2: 'text1']) ||
it.getBuildVariables().equals([axis1: 'textz', axis2: 'text2']) ||
it.getBuildVariables().equals([axis1: 'texty', axis2: 'text2'])
}
Edit this is the spock spec for the Jenkins job-dsl Matrix Job plugin I'd like useful tests for
def 'CombinationFilter'() {
given:
def job = configure( $/
job(type:MatrixJob){
name "generated"
axis{
text("axis1", ["textz", "texty"])
text("axis2", ["text1", "text2"])
}
steps{
shell('return 255')
}
combinationFilter("axis1=='textz' || axis2=='text2'")
sequential(false)
}
/$)
when:
def job_build = job.scheduleBuild2(0).get()
def gen = rule.getInstance().getItem("generated")
def gen_build = gen.scheduleBuild2(0).get()
def gen_runs = gen_build.getRuns()
then:
job_build.logFile.text.contains("SUCCESS")
gen_build.logFile.text.contains("FAILURE")
gen_runs.every(){it.logFile.text.contains("FAILURE")}
gen_runs.every(){it.getBuildVariables().equals([axis1: 'textz', axis2: 'text1']) || it.getBuildVariables().equals([axis1: 'textz', axis2: 'text2']) || it.getBuildVariables().equals([axis1: 'texty', axis2: 'text2'])}
gen_runs.size() == 3
}
Following code should work. If You expect any further simplifications it would be easier to share more code.
gen_build.getRuns.every { it.buildVariables in [[axis1: 'textz', axis2: 'text1'],[axis1: 'textz', axis2: 'text2'],[axis1: 'texty', axis2: 'text2']]}
You can also revert the assertion:
[[axis1: 'textz', axis2: 'text1'],[axis1: 'textz', axis2: 'text2'],[axis1: 'texty', axis2: 'text2']].containsAll(gen_build.getRuns*.buildVariables)

Ruby when nil or empty string

I have RoR app, and I want to change some lines of my code to be more elegant.
foo = params[:customer][:language].nil? or params[:customer][:language].empty? ? 'es' : params[:customer][:language]
I try with
foo = params[:customer][:language] || 'es'
But it's not the same exactly.
Thanks in advance.
You can use activesupport's Object#presence method, like this:
foo = params[:customer][:language].presence || 'es'

Gmod 13 Lua Error

I am trying to learn Lua and I decided that for my first project I would try to fix a broken script. I have fixed a few of the bugs but I'm stuck now. Can you help me?
function SWEP:PrimaryAttack()
if( CurTime() < self.NextStrike ) then return; end
self.Weapon:EmitSound("player/skick/sparta.mp3")
self.NextStrike = ( CurTime() + 3.5 );
timer.Simple( 1.80, function() self:AttackAnim() end)
-Next line broken-
timer.Simple( 2.40, function() self.Weapon:SendWeaponAnim( ACT_VM_IDLE ) end);
timer.Simple( 2.00, function() self.ShootBullets( self ) end)
self.Owner:SetAnimation( PLAYER_ATTACK1 );
end
function SWEP:ShootBullets()
-Next line Broken-
local trace =Owner:GetEyeTrace();
if trace.HitPos:Distance(self.Owner:GetShootPos()) <= 130 then
if( trace.Entity:IsPlayer() or trace.Entity:IsNPC() or trace.Entity:GetClass()=="prop_ragdoll" ) then
timer.Simple(0, game.ConsoleCommand, "host_timescale 0.1\n")
timer.Simple(0.5, game.ConsoleCommand, "host_timescale 1\n")
self.Owner:EmitSound( self.FleshHit[math.random(1,#self.FleshHit)] );
else
self.Owner:EmitSound( self.Hit[math.random(1,#self.Hit)] );
end
bullet = {}
bullet.Num = 5
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector(0.04, 0.04, 0.04)
bullet.Tracer = 0
bullet.Force = 250
bullet.Damage = 1000000
self.Owner:FireBullets(bullet)
end
I'm getting an error saying Attempting to index field 'Weapon' (a nil value).
Can anyone explain how to fix this?
Im not allowed to post imagesthis is what im getting Error image
The reason you're getting that error is that "Weapon" (specifically self.Weapon) was not initialized. self.Weapon points to nothing, so you can't call any functions on it.
Can you show us the lines that the error messages reference? It looks like the file is shared.lua, lines 84, 85 and 90. The surrounding code would be helpful, too. I'm guessing that you posted it as part of your original question, but it's not helpful without any line numbers!

Resources