scope

Trying to add multiple D3 graphs

纵然是瞬间 提交于 2019-12-09 06:07:33
问题 I'm trying to figure out how to include 2 or more graphs on my website. I am currently using the Area Graph and the Pie Graph. If I disable one of them, then the other works fine, but when I try to use both at the same time, it stops working. JS code for the Area Graph var margin = { top: 0, right: 0, bottom: 30, left: 50 }, width = 670 - margin.left - margin.right, height = 326 - margin.top - margin.bottom; var parseDate = d3.time.format("%d-%b-%y").parse; var x = d3.time.scale() .range([0,

Rails 3: Retrieve all child records where parent model attribute equals search key

走远了吗. 提交于 2019-12-09 06:02:49
问题 I want to do a query that returns only the assets that do not have a serial number where the workorder branch equals a number. class Workorder < ActiveRecord::Base belongs_to :user has_many :assets scope :current_branch, where("branch=350").order("wo_date ASC") end class Asset < ActiveRecord::Base belongs_to :workorder scope :needs_serial, :conditions => {:serial => ""} end class AssetsController < ApplicationController def index @assets_needing_serial=??? end end So I want a hash of :assets

Storing nodejs fs.readfile's result in a variable and pass to global variable

ⅰ亾dé卋堺 提交于 2019-12-09 06:02:44
问题 I'm wondering if its possible to pass the contents of fs.readfile out of the scope of the readfile method, and store it in a variable similar to. var a; function b () { var c = "from scope of b"; a = c; } b(); Then I can console.log(a); or pass it to another variable. My question is is there a way to do this with fs.readFile so that the contents (data) get passed to the global variable global_data. var fs = require("fs"); var global_data; fs.readFile("example.txt", "UTF8", function(err, data)

What exactly is a PowerShell ScriptBlock

醉酒当歌 提交于 2019-12-09 05:37:47
问题 A PowerShell ScriptBlock is not a lexical closure as it does not close over the variables referenced in its declaring environment. Instead it seems to leverage dynamic scope and free variables which are bound at run time in a lambda expression. function Get-Block { $b = "PowerShell" $value = {"Hello $b"} return $value } $block = Get-Block & $block # Hello # PowerShell is not written as it is not defined in the scope # in which the block was executed. function foo { $value = 5 function bar {

Why does the UnboundLocalError occur on the second variable of the flat comprehension?

旧巷老猫 提交于 2019-12-09 05:34:43
问题 I answered a question here: comprehension list in python2 works fine but i get an error in python3 OP's error was using the same variables for max range and indices: x = 12 y = 10 z = 12 n = 100 ret_list = [ (x,y,z) for x in range(x+1) for y in range(y+1) for z in range(z+1) if x+y+z!=n ] This is a Python-3 error only, and related to the scopes that were added to the comprehension to avoid the variables defined here "leaking". Changing the variable names fixes that. The error is:

Why should I use nested classes? [closed]

只谈情不闲聊 提交于 2019-12-09 02:20:15
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . When is it feasible to nest classes? The most common advantage of it that I see is "shared scope" (use of variables across classes). Is this less attractive/less a best practice than just putting the nested class in it's own file, and passing the arguments through the

javascript variable scope/closure in loop after timeout

妖精的绣舞 提交于 2019-12-08 22:34:34
问题 It's late and the part of my brain where Douglas Crockford lives is closed. Ive tried a few things but nothing's doing as expected. I've got a canvas where I draw a 2 lines, then fade them out on a timer but only the last line in the loop is being faded out. Here's my fiddle, look down to line 50ish in the JS, to see it in action drag your mouse around in the bottom right pane: http://jsfiddle.net/mRsvc/4/ this is the function, basically the timeout only gets the last value in the loop, I've

In LISP how to inspect free variables in a closure?

这一生的挚爱 提交于 2019-12-08 21:24:18
问题 In lisp I can bind free variables bound in a closure like this... (let ((x 1) (y 2) (z 3)) (defun free-variables () (+ x y z))) (free-variables) results in ... 6 What I want to know is if it is possible to inspect bound closure variables dynamically? E.g. (inspect-closure free-variables) resulting in something like... ((x 1) (y 2) (z 3)) Thanks SO 回答1: Common Lisp Access to the closure's internal variables is only possible from functions in the same scope (See Jeff's answer). Even those can't

Rails 4 - Pundit, Scopes: Getting Started

对着背影说爱祢 提交于 2019-12-08 20:15:30
I am really struggling in my efforts over the past 2+ years to try to learn how to use pundit. I am trying to write scoped policies, so that different users can receive objects based on the scope class that they fit into. I have asked several questions on the same topic previously, but I'm not getting any closer to a solution. My recent questions are: here , here , here , here , here and here . There are several others but these give the general picture, that I am struggling with the fundamentals of how to get started. I have a million problems with getting started and realise that after 4

In Perl, can local() create a variable?

时间秒杀一切 提交于 2019-12-08 19:53:17
问题 I have read many posts in Stackoverflow and in Google which tell that local does not create a variable, instead it works on the existing ones. I have a small piece of code below and I wonder how local is working when there is no such variable already created. #use strict; #use warnings; &func; sub func{ local $temp = 20; print $temp; } This I wrote just to understand the concept and I am relatively new to Perl. 回答1: Unless you declare a variable with my , variables without a full package