Skip to content

Instantly share code, notes, and snippets.

View aabril's full-sized avatar

Albert Abril aabril

View GitHub Profile
@aabril
aabril / MY_Language.php
Created July 7, 2011 15:27
CodeIgniter method that extends Language.php for get the language by browser.
public function get_langname_byBrowser()
{
$this->CI = & get_instance();
// inicializamos, por si no detecta ninguna el navegador
$name = "";
//prepare user language array
$languages = array();
$languages[0] = '';
@aabril
aabril / urlstocsv.sh
Created January 31, 2012 12:02
list archives <5bytes , removes the .html from their name, and print on a csv compatible format
find ./ -type f -size -5 | awk 'BEGIN {FS=".html"}{print $1}' | awk 'BEGIN {FS="./"}{print $2","}' > urls.csv
@aabril
aabril / monitoring_mysql.sh
Created January 31, 2012 12:07
Monitor and force mysql reload if it reaches 90 threads connections.
#!/bin/bash
LOGFILE="ping_mysql.log"
DBUSER="dummyuser"
DBPASS="dummypass"
DBHOST="localhost"
while :
do
mysqladmin ping -u $DBUSER -p $DBPASS -h $DBHOST >> $LOGFILE
mysqladmin status -u $DBUSER -p $DBPASS -h $DBHOST >> $LOGFILE
@aabril
aabril / find_column_name.sql
Created February 2, 2012 12:57
Find on a mysql database, a column named column_name
SELECT TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE column_name LIKE '%column_name%';
@aabril
aabril / web2py_env.py
Created February 2, 2012 13:00
standalone web2py environment
'''
this snippet is used to load a web2py environment
you must install web2py (so gluon.*) from pyeggs : "pip install web2py"
it will read your db.py models from the same directory
'''
# web2py env
from gluon.shell import exec_environment
import MySQLdb
from gluon import DAL, Field
from gluon.template import render
@aabril
aabril / couchpython.py
Created February 2, 2012 14:55
connect and create a couch database from python code
# import
from couchdb.client import Server
# connection
server = Server('http://localhost:5984')
server.resource.credentials('username','password')
# create a database
db = server.create('mycouchdb')
@aabril
aabril / couchdbcheatsheet.sh
Created February 2, 2012 15:09
CouchDB cheatsheet
# CouchDB cheatsheet via REST API
HOST="http://username:password@localhost:5984"
# couchdb
curl -X GET $HOST
# check available databases
curl -X GET $HOST/_all_dbs
@aabril
aabril / gist:1771052
Created February 8, 2012 17:00
nginx rewrite configuration
# nginx configuration
# any access to http://myurl.com/new/blablabla has to load http://myurl.com/old/blablabla without change url
# this is redirecting and changing the url
location ^~ /new/ {
rewrite ^/new/(.*)$ /old/$1 permanent;
}
@aabril
aabril / gist:1789037
Created February 10, 2012 11:54
see clients ip's from a nginx log
# input:
# 2012/02/10 09:32:36 [error] 17798#0: *30890 open() "/var/www/media/icon.png" failed (2: No such file or directory),
# client: 10.10.100.100, server: dev.myserver.com, request: "GET /media/icon.png HTTP/1.1", host: "dev.myserver.com",
# referrer: "http://dev.myserver.com/index"
#
# output
# client: 10.10.100.100
cat error.log | grep client | awk 'BEGIN {FS="client: "}{print "client: "$2}' | cut -d "," -f 1
@aabril
aabril / gist:1885522
Created February 22, 2012 15:22
sorted list of keys on redis, separated by ":" , for a older versions of redis-cli
echo "*" | redis-cli keys | sed "s/\s/\n/g" | cut -d ":" -f 2 | sort -n | more