closures

Laravel queue Serialization of 'Closure' is not allowed

*爱你&永不变心* 提交于 2019-12-11 06:19:02
问题 I need help to dispatch a job with Laravel, seems the system try to serialize a closure when using queue job so there's this error. How can I fix this problem? I also tried this package https://github.com/jeremeamia/super_closure but it doesn't work in my case. Here is my code: In the controller FacebookController: public function getPosts(\SammyK\LaravelFacebookSdk\LaravelFacebookSdk $fb) //get all post of logged user { dispatch(new SyncFacebook($fb)); } And Job to dispatch: <?php namespace

trying to leverage JSZip to open and then parse a specific file in a .zip

纵然是瞬间 提交于 2019-12-11 05:52:44
问题 Have been trying to use the JSZip library to cycle through files in a .zip, looking for one (here, test.txt ) that I want to parse for content. Have attempted to do a modification of the sample [recommend viewing source on that] that JSZip provides: <!DOCTYPE HTML> <html> <head> <link href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet"> <link href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css"

Function assigning values after it returns Swift

喜夏-厌秋 提交于 2019-12-11 05:41:47
问题 I'm running into a weird bug where my function appends a value to an array AFTER it returns... The code for this is below : func makeUser(first: String, last: String, email: String) -> [User] { var userReturn = [User]() RESTEngine.sharedEngine.registerUser(email, firstName: first, lastName: last, age: 12, success: { response in if let response = response, result = response["resource"], id = result[0]["_id"] { let params: JSON = ["name": "\(first) \(last)", "id": id as! String, "email": email,

python closure local variables

寵の児 提交于 2019-12-11 05:16:21
问题 In this answer a singleton decorator is demonstrated as such def singleton(cls): instances = {} def getinstance(): print len(instances) if cls not in instances: instances[cls] = cls() return instances[cls] return getinstance but instances is 'local' to each class that is decorated, so I tried to be more efficient and use def BAD_singleton(cls): instances = None def getinstance(): if instances is None: instances = cls() return instances return getinstance @BAD_singleton class MyTest(object):

Closure in Velocity template macros

拜拜、爱过 提交于 2019-12-11 04:58:38
问题 I've got a couple Velocity macros like this: #macro(Alpha) #set($p = 1) #@Beta() $p // 1 $bodyContent #end #end #macro(Beta $params) #set($p = 2) $p // 2 $bodyContent #end And I'm using them like so: #set($p = 0) #@Alpha(...) $p // 3 #end I believe this renders like so (ignore formatting): 2, 2, 2 But I'd like to have proper closure behavior, including more locally scoped names hiding parent scope names. In particular, the usage of $p labelled '3' should refer to the value 0, '2' to the value

how can I pass argument (names) to a function operator? (point-free programming)

牧云@^-^@ 提交于 2019-12-11 04:54:30
问题 Background Say, I have a ClassA and ClassB , each of which require their own arguments in the respective constructor functions: ClassA <- function(A_arg1, A_arg2) { # some class-SPECIFIC construction magic happens, say out <- list(A_arg1, A_arg2) # some GENERAL construction magic happens class(out) <- "ClassA" return(out) } ClassB <- function(B_arg1, B_arg2) { # some class-SPECIFIC construction magic happens, say out <- B_arg1 + B_arg2 # some GENERAL construction magic happens class(out) <-

Closures and Loops in Python [duplicate]

柔情痞子 提交于 2019-12-11 04:07:17
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Lexical closures in Python Suppose I have the following code callbacks = [] for i in range(10): callbacks.append(lambda x: i) all functions in callbacks will return the final value of i . How can I create callbacks that return the current value for i at creation time ? 回答1: for i in range(10): callbacks.append(lambda x = i : x) 回答2: In [113]: callbacks=[] In [114]: for i in range(10): callbacks.append(lambda x=i

Haskell permutation library function - please clarify?

我只是一个虾纸丫 提交于 2019-12-11 04:05:42
问题 This is the code for the permutations function in Haskell's Data.List module: permutations :: [a] -> [[a]] permutations xs0 = xs0 : perms xs0 [] where perms [] _ = [] perms (t:ts) is = foldr interleave (perms ts (t:is)) (permutations is) where interleave xs r = let (_,zs) = interleave' id xs r in zs interleave' _ [] r = (ts, r) interleave' f (y:ys) r = let (us,zs) = interleave' (f . (y:)) ys r in (y:us, f (t:y:us) : zs) Can someone take the time to explain to me how this code works? My

“this” keyword inside closure

做~自己de王妃 提交于 2019-12-11 04:04:14
问题 I've seen a bunch of examples but can't seem to get some sample code to work. Take the following code: var test = (function(){ var t = "test"; return { alertT: function(){ alert(t); } } }()); and I have a function on window.load like: test.alertT(); That all works fine. However, when I try to explicitly set the context of t inside the alert() in alertT , I just get undefined. I've tried: var that = this; alert(that.t); //undefined I've tried: return { that: this, alertT: function(){ alert

Closure with conditional logging

眉间皱痕 提交于 2019-12-11 03:44:01
问题 I have a function like this: private downloadAllFiles() { sftpRetriever.listFiles().findAll { filter.isResponse(it) || filter.isResponseTurned(it) }.each { String fileName -> log.info 'Downloading file: {}', fileName sftpRetriever.downloadFile(fileName) log.info 'File downloaded' removeRemoteFile(fileName) } } I am looking for a simple way of modyfing this closure inside of that function so if the size() of findAll is 0 it will simply log 'No more files to download' and .each won't be