Nginx: mass permanent redirects

When I say “mass”, I mean reasonable amount of redirects, like a couple of thousands. I had to migrate a blog to a new URL structure. This migration led to create about 600+ unique redirects without any shared patterns. To solve this, I used a nginx configuration file containing all the redirects and I included … 

 

Android: center text horizontally and vertically in a TextView

By default, text appears on the top left of a TextView. To center it vertically, you need to use the gravity property : In your xml layout file, add the following property : android:gravity=”center_vertical” To center the text vertically and horizontally : Use the following property : android:gravity=”center” To do it programmatically, use the following syntax : … 

 

Install gem as user on OSX 10.10 Yosemite

Use case : install a specific version of capistrano to deploy stuff somewhere Let’s say you need to install capistrano 2.* to be able to use your deploy scripts. In this case, I’m running a fresh Yosemite install. Let’s say we’ll need to setup a specific ruby version with a specific gem version. To do … 

 

Ubuntu: start sphinxsearch with specific options

By default, on Ubuntu, SphinxSearch is using /etc/sphinxsearch/sphinx.conf and /etc/default/sphinxsearch to start/stop daemon. If you need to use specific command line options (like -c ), you need to update your /etc/init.d/sphinxsearch In the do_start() function, change the line : start-stop-daemon –start –pidfile $PIDFILE –chuid www-data –exec ${DAEMON} with start-stop-daemon –start –pidfile $PIDFILE –chuid www-data –exec ${DAEMON} … 

 

Install a specific version of sphinxsearch on Ubuntu 14.04

Current version of sphinx on Ubuntu 14.04 is 2.0.* If you need a more recent version, you can find a .deb package directly on Sphinx website : http://sphinxsearch.com/downloads/release/ Pick-up your package and install it locally : $ wget http://sphinxsearch.com/files/sphinxsearch_2.2.6-release-0ubuntu12~trusty_amd64.deb $ dpkg -i sphinxsearch_2.2.6-release-0ubuntu12~trusty_amd64.deb $ searchd -h Sphinx 2.2.6-id64-release (r4843) Copyright (c) 2001-2014, Andrew Aksyonoff Copyright … 

 

How to configure HTTPS/SSL under Apache and OSX

My setup : OSX : 10.8.5 Apache : # httpd -V Server version: Apache/2.2.26 (Unix) Server built: Dec 10 2013 22:06:35 Server’s Module Magic Number: 20051115:33 Server loaded: APR 1.4.5, APR-Util 1.3.12 Compiled using: APR 1.4.5, APR-Util 1.3.12 Architecture: 64-bit Server MPM: Prefork threaded: no forked: yes (variable process count) Server compiled with…. -D APACHE_MPM_DIR=”server/mpm/prefork” … 

 

Create a chrooted ssh user with Ubuntu and jailkit

I have a website hosted in /var/www/mydomain I want to create a chrooted ssh account to give access to a shell to my developers to execute commands and check logs. This is just a raw transcript how I did it with jailkit : $ apt-get install build-essential autoconf automake libtool flex bison debhelper binutils-gold $ … 

 

Using Symfony and xip.io in dev environment

The default app_dev.php in symfony only allow connexion from localhost. Code is as follow: if (isset($_SERVER[‘HTTP_CLIENT_IP’]) || isset($_SERVER[‘HTTP_X_FORWARDED_FOR’]) || !in_array(@$_SERVER[‘REMOTE_ADDR’], array(‘127.0.0.1’, ‘fe80::1’, ‘::1’)) ) { header(‘HTTP/1.0 403 Forbidden’); exit(‘You are not allowed to access this file. Check ‘.basename(__FILE__).’ for more information.’); } If you want to use xip.io to test your local instance with devices … 

 

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.