how to fix this error TypeError [ERR_INVALID_CALLBACK]: Callback must be a function

Fs.writeFile() according to the documentation here takes ( file, data[, options]and callback ) params so your code will be like this : var fs = require(‘fs’); fs.readFile(‘readMe.txt’, ‘utf8’, function (err, data) { fs.writeFile(‘writeMe.txt’, data, function(err, result) { if(err) console.log(‘error’, err); }); });

setUserVisibleHint called before onCreateView in Fragment

// create boolean for fetching data private boolean isViewShown = false; @Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); if (getView() != null) { isViewShown = true; // fetchdata() contains logic to show data when page is selected mostly asynctask to fill the data fetchData(); } else { isViewShown = false; } } Use isViewShown instance … Read more

Python subprocess: callback when cmd exits

You’re right – there is no nice API for this. You’re also right on your second point – it’s trivially easy to design a function that does this for you using threading. import threading import subprocess def popen_and_call(on_exit, popen_args): “”” Runs the given args in a subprocess.Popen, and then calls the function on_exit when the … Read more

Using ResultReceiver in Android

You need to make custom resultreceiver class extended from ResultReceiver then implements the resultreceiver interface in your activity Pass custom resultreceiver object to intentService and in intentservice just fetch the receiver object and call receiver.send() function to send anything to the calling activity in Bundle object. here is customResultReceiver class : public class MyResultReceiver extends … Read more

A very simple multithreading parallel URL fetching (without queue)

Simplifying your original version as far as possible: import threading import urllib2 import time start = time.time() urls = [“http://www.google.com”, “http://www.apple.com”, “http://www.microsoft.com”, “http://www.amazon.com”, “http://www.facebook.com”] def fetch_url(url): urlHandler = urllib2.urlopen(url) html = urlHandler.read() print “‘%s\’ fetched in %ss” % (url, (time.time() – start)) threads = [threading.Thread(target=fetch_url, args=(url,)) for url in urls] for thread in threads: thread.start() … Read more

Wait till a Function with animations is finished until running another Function

You can use jQuery’s $.Deferred var FunctionOne = function () { // create a deferred object var r = $.Deferred(); // do whatever you want (e.g. ajax/animations other asyc tasks) setTimeout(function () { // and call `resolve` on the deferred object, once you’re done r.resolve(); }, 2500); // return the deferred object return r; }; … Read more

Implementing a method taking a block to use as callback

You can call a block like a regular function: BOOL finished = …; if (completion) { completion(finished); } So that means implementing a complete block function using your example would look like this: + (void)myMethod:(UIView *)exampleView completion:(void (^)(BOOL finished))completion { if (completion) { completion(finished); } }

What are the benefits to using anonymous functions instead of named functions for callbacks and parameters in JavaScript event code?

I use anonymous functions for three reasons: If no name is needed because the function is only ever called in one place, then why add a name to whatever namespace you’re in. Anonymous functions are declared inline and inline functions have advantages in that they can access variables in the parent scopes. Yes, you can … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)