This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function toSlug($text) | |
{ | |
$text = preg_replace( | |
['/(à|á|ã|â)/','/(é|è|ẽ|ê)/','/(í|ì|ĩ|î)/','/(ó|ò|õ|ô)/','/(ú|ù|û)/','/ç/','/ /'], | |
['a','e','i','o','u','c','-'], | |
strtolower($text) | |
); | |
$text = preg_replace('/([^a-z0-9-])/','',$text); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(global-set-key (kbd "C-x q") 'neotree-toggle) | |
(setq js2-basic-offset 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
); |
OlderNewer