Skip to content

Instantly share code, notes, and snippets.

$str = "key1=value1&key2=value2&key2=value3&key3=value4";
$params = explode("&", $str);
$output = array();
foreach ($params as $param){
$param = explode("=", $param);
$key = $param[0];
typedef struct node {
int key;
struct node *left;
struct node *right;
} node;
int is_odd(node *n){
// verify the root key
if (n->key % 2 != 0)
return 1;
@mgiacomini
mgiacomini / gearman_install.sh
Created August 27, 2014 13:56
Gearman and your php extension installation in debian dist
#!/bin/bash
# install libs
apt-get install apache2 php5 libapache2-mod-php5 php5-dev
apt-get install gearman-job-server libgearman-dev
apt-get install php-pear
pecl install gearman-1.0.3
# activate Gearman extension for Apache2
echo "extension=gearman.so" > /etc/php5/conf.d/gearman.ini
@mgiacomini
mgiacomini / uninstall_homebrew.sh
Created October 8, 2014 03:00
Uninstalling homebrew
#!/bin/bash
cd `brew --prefix`
git checkout master
git ls-files -z | pbcopy
rm -rf Cellar
bin/brew prune
pbpaste | xargs -0 rm
rm -r Library/Homebrew Library/Aliases Library/Formula Library/Contributions
test -d Library/LinkedKegs && rm -r Library/LinkedKegs
rmdir -p bin Library share/man/man1 2> /dev/null
@mgiacomini
mgiacomini / example.c
Last active August 29, 2015 14:08
c-cli-getopt
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int
main (int argc, char **argv)
{
int aflag = 0;
int bflag = 0;
@mgiacomini
mgiacomini / sync-file.sh
Created November 5, 2014 16:29
Sync files
#!/bin/bash
echo "Sync files"
echo "------------------------------------"
if [ "$1" = "" || $2 = "" ]; then
echo "Source/Dest path can not be null"
exit
fi
@mgiacomini
mgiacomini / .bash_profile
Created January 28, 2015 17:42
Setup GIT completion and repository state on MacOSX
#!/bin/bash
source ~/.git-completion.bash
source ~/.git-prompt.sh
MAGENTA="\[\033[0;35m\]"
YELLOW="\[\033[0;33m\]"
BLUE="\[\033[34m\]"
LIGHT_GRAY="\[\033[0;37m\]"
CYAN="\[\033[0;36m\]"
<form>
<fieldset>
<legend>Newsletter</legend>
<label>Your e-mail:</label>
<input type='email' name='email' required/>
<input type='submit' name='submit'/>
</fieldset>
</form>
@mgiacomini
mgiacomini / deploy.rb
Last active September 2, 2015 17:02 — forked from jbonney/deploy.rb
Mina deployment file to setup new host for Rails applications. Creates the folder structure, fill up the database.yml file, create the associated DB and user and set up new Apache virtual host file.
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rvm'
# Usually mina focuses on deploying to one host and the deploy options are therefore simple.
# In our case, there is a number of possible servers to deploy to, it is therefore necessary to
# specify the host that we are targeting.
server = ENV['server']
# Since the same host can have multiple applications running in parallel, it is necessary to
@mgiacomini
mgiacomini / rails-postgres-backbone-bootstrap-bootswatch
Created August 16, 2017 03:40 — forked from sionc/rails-postgres-backbone-bootstrap-bootswatch
Instructions on creating a new app using Ruby on Rails, Postgresql, Backbone.js, Twitter Boostrap, Bootstwatch
- Check rails version
$ rails -v
- To update rails
$ gem update rails
- Creating a new rails app using postgresql
$ mkdir rails_projects
$ cd rails_projects
$ rails new myapp --database=postgresql