Skip to content

Instantly share code, notes, and snippets.

View arodbits's full-sized avatar

Anthony Rodriguez arodbits

View GitHub Profile
@arodbits
arodbits / frequency.js
Last active March 30, 2021 16:29
ASCII frequency graph
//sample data
let yAxis = [5,15]
let xAxis = [140, 190]
let dataSet = [
[140,150,15],
[160,170,10],
[170,180,8],
[180,190,5],
]
@arodbits
arodbits / run.sh
Last active April 10, 2019 14:21
reload a running php-fpm in a docker container
docker exec -it container_name kill -USR2 1
@arodbits
arodbits / add_column_rows.sh
Created September 30, 2018 00:13
add up all column values
res=0; for dir in $a; do val=$(du -s /dir_path | awk '{ print $1 }'); res=$(($val+$res)); done;
#The result is in KB by default
@arodbits
arodbits / filesystems-resizing.sh
Last active September 29, 2018 23:09
Dealing with filesytems resizing
# 1 - Report file system disk space usage
# note: -h: human readable. print sizes in power of 1024.
$ df -h
# would print:
# Filesystem Size Used Avail Use% Mounted on
# udev 7.7G 0 7.7G 0% /dev
# tmpfs 1.6G 9.0M 1.6G 1% /run
# /dev/nvma1n1p1 59G 34G 25G 59% /
@arodbits
arodbits / traffic.js
Created September 3, 2018 04:26
a traffic light system
let states = {
'red': {'nextSlot':'green', 'await':10000, 'exec':function(element){
element.className = 'red'
setTimeout(function(){
element.className = ''
states.green.exec(document.getElementById(states.red.nextSlot))
}, states.red.await)
}},
'green': {'nextSlot':'yellow','await':10000, 'exec':function(element){
@arodbits
arodbits / git-blame-a-set-of-lines.sh
Last active July 28, 2018 19:38
Git blame a set of lines in a file
git blame -L 2014,+20 -- <file path>
@arodbits
arodbits / securesshcopy.sh
Created July 19, 2018 19:26
Copy files over ssh using secure ssh (scp)
scp -r -i mykey.pem [from_directory_or_file] [host_name]:[destination_location]
@arodbits
arodbits / redis-insert-unique-value.sh
Last active May 18, 2018 19:16
Store in a sorted set in Redis all unique values from keys matching a pattern using a shell command
redis="redis-cli -h host_name" \
$redis keys "*matching_key_pattern*" | awk -F':' '{print $2}' | awk '!x[$0]++' | xargs -I{} $redis zadd temp-user_ids {} {}
@arodbits
arodbits / awk-remove-duplicated.sh
Created May 18, 2018 19:10
remove duplicates with awk
$ awk '!x[$0]++'
#which is a shorthand for:
$ awk ' !seen[$0] { print $0 } 1 { seen[$0]++ }'
@arodbits
arodbits / server.sh
Last active May 4, 2018 19:04
NGINX: Handle request with different PHP version driven by the URI resource name
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ^~ /endpoint {
alias /home/www/html;
try_files $uri $uri/ @nested;