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 --summary

If you want to restore some of them see this.

If you don’t want all the information about which commit they were removed in, you can just add a grep delete in there.

git log --diff-filter=D --summary | grep delete

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

Update a Wordpress site url

There are a couple methods available to change the url of a WordPress site from an old address to a new one without having to manually dig through a database dump.

You can either add some code to your config.php file or your theme's functions.php file.

update_option('siteurl','http://your.site.url:port/yourblog');
update_option('home','http://your.site.url:port/yourblog');

There is also "relocate" functionality by adding define('RELOCATE',true); to your wp-config.php

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

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.

info for ubuntu

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.

namespaced.object.method.apply(namespaced.object, [arguments]);

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(arguments[i] !== undefined) {
      args.push(arguments[i]);
    }
  }

  if(typeof this[method] !== 'undefined') {
    this[method].apply(this, args);
  }
}

You can call the method like this:

this.methodToWrap = function(one, two){
  console.log([one, two]);

...

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']);

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

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 your Rails layouts to tell jQuery to ignore any animations:

<%= javascript_tag '$.fx.off = true;' if Rails.env.test? %>