Skip to content

Instantly share code, notes, and snippets.

View danwald's full-sized avatar
💻
coding

Danny Crasto danwald

💻
coding
View GitHub Profile
@danwald
danwald / attrib.py
Last active May 11, 2023 16:37
attribute lookup
import dataclasses
import logging
logging.basicConfig(level='INFO')
logger = logging.getLogger(__name__)
@dataclasses.dataclass
class DictAttrib:
# class attribute
'''
encodes a pair of +ive ints to an int and complementary method
src: http://mathforum.org/library/drmath/view/56036.html
'''
def encode_pair(a: int, b: int) -> int:
'''
implements
[(a + b)^2 + 3a + b]/2
@danwald
danwald / flac2mp3.sh
Created July 27, 2019 10:07
flac to mp3
#!/bin/bash
for a in *.flac; do
ffmpeg -i "$a" -qscale:a 0 "${a[@]/%flac/mp3}"
done
@danwald
danwald / redis_keys_scan_age
Last active August 27, 2018 07:57
scans redis to get key counts
import redis
import sys
ip = '172.35.5.201'
port = 6379
db = 1
sixty_days_back_sec = 5184000
thirty_days_back_sec = sixty_days_back_sec / 2
ten_days_back_sec = thirty_days_back_sec / 3
total=ten_db=thirty_db=sixty_db=deleted=0
@danwald
danwald / fc.sh
Last active February 12, 2017 19:48
Flock commands so scripts/cronjobs don't overrun. Send email on failure.
#!/bin/bash
export from_name=''
lockfile=$1
flock=`which flock`
#uses mandrill-sendmail via @blackdotsh's https://raw.githubusercontent.com/blackdotsh/mandrillapp-cli/master/sendmail.sh
sendmail=$HOME/msendmail.sh
dt=`date`
$flock -xn "/tmp/$lockfile" echo "${@:2}"
@danwald
danwald / dbash.sh
Created July 11, 2015 10:29
open a bash shell in a docker container or latest one
function dbash(){
if test -z "$1"
then
container=`docker ps -lq`
echo "Using last active container $container"
else
container=$1
fi
docker exec -it $container bash
}
@danwald
danwald / a.rb
Created May 3, 2015 00:36
Extract the last timestamp from a logfile and check if it was more than a minute ago
LOG_TS=$(tail -n 1000 __STR__ | grep INFO | tail -n 1 | grep -Po "\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}") && [[ $((`date +%s`-`date +%s -d"$LOG_TS"`)) -lt 60 ]] || echo "More than a minute"
@danwald
danwald / a.rb
Created April 28, 2015 09:35
Get IP address of machine
ifconfig eth0 | grep inet | awk -F: '{print $2; exit}' | cut -d' ' -f1
@danwald
danwald / -
Last active August 29, 2015 14:19
S3: sync last 7 days from bucket to local
#!/bin/bash
set -e
function get_include_string()
{
local str=""
for i in {7..0}
do
str+="--include \""
@danwald
danwald / keybase.md
Last active August 29, 2015 14:10
keybase id proof

Keybase proof [39/9255]

I hereby claim:

  • I am danwald on github.
  • I am danwald (https://keybase.io/danwald) on keybase.
  • I have a public key whose fingerprint is F2C8 CC3B FABD 2C94 441D B2C0 BCFD B00D 122C 2410

To claim this, I am signing this object: