Skip to content

Instantly share code, notes, and snippets.

View renatocassino's full-sized avatar

Renato Cassino renatocassino

View GitHub Profile
# NOTICE: to get Nginx+Unicorn best-practices configuration see the gist https://gist.github.com/3052776
$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.2.1.tar.gz
$ tar xzvf ./nginx-1.2.1.tar.gz && rm -f ./nginx-1.2.1.tar.gz
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
$ tar xzvf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz
$ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
@renatocassino
renatocassino / ToSlug.php
Last active December 16, 2016 11:49
Title to slug
<?php
function toSlug($text)
{
$text = preg_replace(
['/(à|á|ã|â)/','/(é|è|ẽ|ê)/','/(í|ì|ĩ|î)/','/(ó|ò|õ|ô)/','/(ú|ù|û)/','/ç/','/ /'],
['a','e','i','o','u','c','-'],
strtolower($text)
);
$text = preg_replace('/([^a-z0-9-])/','',$text);
sudo dd if=/dev/zero of=/swapspace bs=1M count=4000
sudo mkswap /swapspace
sudo swapon /swapspace
# To check
cat /proc/swaps
# Next, add the following line to /etc/fstab to activate the new swap at boot:
/swapspace none swap defaults 0 0
module ApplicationHelper
def spaceless(&block)
contents = capture(&block)
# Note that string returned by +capture+ is implicitly HTML-safe,
# and this mangling does not introduce unsafe changes, so I'm just
# resetting the flag.
if Rails.env.production? then
contents.strip.gsub(/>\s+</, '><').html_safe
# Show only ids to an especific id | Possible commands
docker ps -a | grep mongo --color | sed -e 's/^\([a-z0-9]*\).*/\1/' # With grep
docker ps -a | sed -n /mongo/p | sed -e 's/^\([a-z0-9]*\).*/\1/'
docker ps -a | awk '/mongo/ {print $1}' # Using AWK
# Download list of m4a from an xml via curl
wget -i $(curl http://vip.aersia.net/roster.xml\?296 | sed -e '/location/!d' -e 's/\<location\>\(.*\)\<\/location\>/\1/g' -e 's/^[^a-z]*//g')
# Insert with sed
sed '/regex/i\
# 3697
# Syntax
awk '/pattern/ { commands }' textfile
## System variables
# FS = Field Separator (Define the separator for variables)
# NF = Number Fields (Number of fields getted by a field separator)
# RS = Record Separator (Record separator is a new line by default "\n")
# FILENAME = The name of the file that awk is reading
# BEGIN = Run command and change vars before the script
@renatocassino
renatocassino / use_share_x-clipboard_on_emacs_for_ubuntu_and_mac_os_x.lisp
Created February 18, 2017 14:41
Using the same clipboard (x-clipboard) for ubuntu and mac os X in the same script for emacs.
;;;;; Add in your ~/.emacs.d/init.el
;;;; Clipboard for ubuntu
(defun copy-from-ubuntu (text &optional push)
(interactive)
(if (display-graphic-p)
(progn
(message "Yanked region to x-clipboard!")
(call-interactively 'clipboard-kill-ring-save)
)
mkdir ~/docker
chmod 777 ~/docker
# Create network to all containers
docker network create dockernet
# Mongo
docker run -v ~/docker/mongo/data:/data/db -p 27017:27017 --name mongodb --network dockernet -d mongo
# CouchDB
@renatocassino
renatocassino / init.el
Last active July 30, 2018 21:26
Emacs
(global-set-key (kbd "C-x q") 'neotree-toggle)
(setq js2-basic-offset 2)
@renatocassino
renatocassino / 2048-game.js
Last active August 16, 2018 03:17
2048 game
const readlineSync = require('readline-sync');
const printBoard = (board) => {
const f = (n) => {
const size = n.toString().length;
const spaces = 5-size;
return ' '.repeat(spaces) + n.toString() + ' ';
};
textToPrint = [];