passing optional arguments in JavaScript
You can call a JavaScript object while passing an array of arguments with the method apply
.
given:
function method(arg1, arg2){
console.log([arg1, arg2]);
}
you can use:
method.apply(this, ['one', 'two']);
Related cards:
wrap a JavaScript method with a different method
You can wrap a JavaScript method with another method by utilizing the apply()
method and arguments
property inside a function.
function wrapMethod(method) {
var args = [];
for(var i = 1; i < arguments.length; i++) {
if...
JavaScript apply() method's context could be important
The apply() method takes two arguments, the context to run the method as, and an array of arguments to pass to the method. If using this
does not give you the results you need, try passing the object chain above the method you are calling.
na...
Send XHR requests in Rspec controller tests
You can send xhr requests in your rspec tests by using xhr
instead of get
or post
followed by a symbol of the submission method like this: xhr :get, :index, :id = 10
List all deleted files in the repository
You might want to restore them, you might want to double check some merge behavior, in any case it’s quite useful to be able to list all the files that have been deleted in your repository. Here’s how to go about it:
git log --diff-filter=D -...
list installed applications on Mac
You can see a list of all installed applications on your Mac by running the following command in Terminal:
mdfind 'kMDItemContentTypeTree == com.apple.application' | sort
Disable jQuery animations during Rails tests
If you have Capybara tests in your project, you might run into sparatic test failures where elements are not available in a state that you think they will be in because of jQuery animations that occur on the elements.
You can add the following to...
Making scripts run at boot time with Debian
update-rc.d blah defaults
where "blah" is the init.d file name. make sure to set "blah"s permissions to 755 as well.
php error_reporting(-1)
error_reporting(-1) at the top of your script during dev to turn on all warnings, notices, etc in all versions of PHP