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
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
@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);
# 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
# 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\
@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-creating-board.js
Created August 6, 2018 12:39
2048-creating-board.js
const board = [
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
];
// Important, when you see this matix in code,
// you are seeing the board rotated 90 deg to left,
// because the first value is column and the second value is the line
// board[column, line]
@renatocassino
renatocassino / 2048-getEmptyBlocksNonFuncional.js
Last active August 6, 2018 13:11
2048-getEmptyBlocksNonFuncional.js
// Funcion non Functional
const getEmptyBlocksNonFunctional = (currentBoard) => {
const positions = []; // Variable with positions
for(let i = 0; i < currentBoard.length; i++) { // Iterate in columns
for(let j = 0; j < currentBoard[i].length; j++) { // Iterate in lines
if(currentBoard[i][j] === 0) {
positions.push([i, j]); // Append in pushes when 0
}
}
}
@renatocassino
renatocassino / getEmptyBlocks.js
Last active August 7, 2018 14:50
getEmptyBlocks.js
const getEmptyBlocks = (board) => (
board.reduce((lineData, line, idxColumn) => { // Iterate over columns
const result = line.reduce((data, row, idx) => { // Iterate over lines
if (row !== 0) return data; // If value is different of zero, response last iterate
return [[idxColumn, idx], ...data]; // Join last iterate (or default value) with new data
}, []); // Default value to reduce in line
return [...lineData, ...result]; // Join old value with new value and return to next reduce
}, []) // Default value to reduce in column
);