Skip to content

Instantly share code, notes, and snippets.

Avatar

Anthony Rodriguez arodbits

View GitHub Profile
@arodbits
arodbits / frequency.js
Last active Mar 30, 2021
ASCII frequency graph
View frequency.js
//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 / binder.php
Last active Jan 20, 2020
Combine binding values into a raw SQL query in Laravel. Debugging in Laravel.
View binder.php
<?php
//example:
$query = Foo::where('id', '=', 1)->where('name', '=', 'bar');
//would produce the following raw query:
//select * from foo where id = ? and name = ?;
dd(vsprintf(str_replace('?', '%s', $query->toSql()), collect($query->getBindings())->map(function($binding){
return is_numeric($binding) ? $binding : "'{$binding}'";
@arodbits
arodbits / run.sh
Last active Apr 10, 2019
reload a running php-fpm in a docker container
View run.sh
docker exec -it container_name kill -USR2 1
@arodbits
arodbits / add_column_rows.sh
Created Sep 30, 2018
add up all column values
View add_column_rows.sh
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 Sep 29, 2018
Dealing with filesytems resizing
View filesystems-resizing.sh
# 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 Sep 3, 2018
a traffic light system
View traffic.js
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 Jul 28, 2018
Git blame a set of lines in a file
View git-blame-a-set-of-lines.sh
git blame -L 2014,+20 -- <file path>
@arodbits
arodbits / securesshcopy.sh
Created Jul 19, 2018
Copy files over ssh using secure ssh (scp)
View securesshcopy.sh
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
Store in a sorted set in Redis all unique values from keys matching a pattern using a shell command
View redis-insert-unique-value.sh
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
remove duplicates with awk
View awk-remove-duplicated.sh
$ awk '!x[$0]++'
#which is a shorthand for:
$ awk ' !seen[$0] { print $0 } 1 { seen[$0]++ }'