Update your git repository remote origin

Let’s say you’re moving from one service to another, to update your origin url use the following command : $ git remote remove origin $ git remote add origin git@github.com:your_account/repository.git If you get an error message like this : You asked me to pull without telling me which branch you Do the following : $ … 

 

How to count words in javascript

my_text is your source string add any character you want to be used as a separator my_text.split(/[\s\.,;]+/).length; Note that depending on your source string, your array could contain empty elements. See http://stackoverflow.com/questions/281264/remove-empty-elements-from-an-array-in-javascript to remove empty elements in an array.

 

Rename files replacing spaces by another character

Let’s say you have a list of files with blank spaces in their name : foie gras final 2-1.eps foie gras step 3.eps foie gras step 4.eps foie gras step 6.eps foie gras step 7.eps If you want to translate blank space to hyphen, use the following command : for file in foie*; do mv … 

 

Remove a file starting with a dash

rm ./-the-file

 

Redmine on Ubuntu 13.10 with Apache2 and Passenger

After a fresh Ubuntu 13.10 install, I encountered the following error [Fri Nov 01 20:06:50.239664 2013] [core:notice] [pid 59440] AH00094: Command line: ‘/usr/sbin/apache2’ [ pid=59448 thr=19153000 file=utils.rb:176 time=2013-11-01 20:06:51.996 ]: *** Exception LoadError in PhusionPassenger::ClassicRails::ApplicationSpawner (Please install the mysql adapter: `gem install activerecord-mysql-adapter` (cannot load such file — mysql)) (process 59448, thread #): I tried … 

 

Remove trailing slash with Apache

With Apache and mod_rewrite, to avoid urls like /page1 and /page1/ to respond with the same content, you can use mod_rewrite with the following syntax: # Remove trailing slash RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

 

Quickly generate a pseudo random token in PHP

public function generate_token($len=32) { return substr(str_shuffle(“0123456789″ .”abcdefghijklmnopqrstuvwxyz” .”ABCDEFGHIJKLMNOPQRSTUVWXYZ” .”0123456789″ .”abcdefghijklmnopqrstuvwxyz” .”ABCDEFGHIJKLMNOPQRSTUVWXYZ” ), 0, $len); }

 

PhantomJS: wait for it

When you want to take screenshots with PhantomJS, you probably need to wait before your page is completely loaded. I mean all resources are loaded and scripts executed. Use the following code to delay your screenshot : var page = new WebPage(); page.open(‘http://stackoverflow.com/’, function (status) { just_wait(); }); function just_wait() { setTimeout(function() { page.render(‘screenshot.png’); phantom.exit(); … 

 

Add a C header include path to compile PECL extensions

I needed to use ImageMagick with PHP on Mac OS X. Using homebrew I added ImageMagick to my system as follow : $ brew install imagemagick And then, add the PHP extension with PECL : sudo pecl install imagick Bad luck… cc -I. -I/private/tmp/pear/temp/imagick -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootSqBVOk/imagick-3.0.1/include -I/private/tmp/pear/temp/pear-build-rootSqBVOk/imagick-3.0.1/main -I/private/tmp/pear/temp/imagick -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g … 

 

Brew: Installing Sphinx search with mysql support on Mac OS X

I consider that you already have Homebrew on your system. Install Mysql brew install mysql start mysql server mysql.server start stop mysql server mysql.server stop Install Sphinx search with mysql support By default, sphinx was configured without mysql support, to fix it, use the following command line : brew install sphinx –mysql  start sphinx searchd -c …