Skip to content

Instantly share code, notes, and snippets.

View derricw's full-sized avatar
🎤
supergreen

Derric Williams derricw

🎤
supergreen
  • Seattle, WA
View GitHub Profile
#/bin/bash
color=$(gdbus call --session --dest org.gnome.Shell.Screenshot --object-path /org/gnome/Shell/Screenshot --method org.gnome.Shell.Screenshot.PickColor)
echo "COLOR: $color"
numbers=$(echo $color | sed 's/[^0-9,.]*//g')
echo "FLOAT: $numbers"
rgb=$(echo $numbers | awk -F',' '{ print $1 * 255, $2 * 255, $3 * 255 }')
echo "RGB: $rgb"
@derricw
derricw / awk_fizbuzz
Last active June 15, 2023 21:01
awk_fizzbuzz.sh
seq 50 | awk 'NR%3!=0 && NR%5!=0 { print } NR%3==0 && NR%5!=0 { print "FIZZ" } NR%5==0 && NR%3!=0 { print "BUZZ" } NR%15==0 { print "FIZZBUZZ" }'
@derricw
derricw / progress_bar.py
Created July 20, 2018 23:19
progress_bar
def print_progress_bar (iteration, total, prefix='', suffix='', decimals=1, length=100, fill='█'):
"""
Call in a loop to create terminal progress bar
@params:
iteration - Required : current iteration (Int)
total - Required : total iterations (Int)
prefix - Optional : prefix string (Str)
suffix - Optional : suffix string (Str)
decimals - Optional : positive number of decimals in percent complete (Int)
length - Optional : character length of bar (Int)
@derricw
derricw / chunk2hdf5.py
Created August 20, 2015 16:17
Pack data into hdf5 1GB at a time.
import logging
import numpy as np
import h5py
def get_fileobj_size(file_obj):
"""
Gets the size of an open file object.
@derricw
derricw / random_youporn_comment.py
Created July 24, 2015 05:21
prints a random youporn comment
from random import randrange
import re
import urllib
for i in range(5):
sock = urllib.urlopen("http://www.youporn.com/random/video/")
htmlSource = sock.read()
sock.close()
result = re.findall('<p class="message">((?:.|\\n)*?)</p>', htmlSource)
@derricw
derricw / ring_buffer.py
Last active August 29, 2015 14:25
simple ring buffer
from collections import deque as dq
class RingBuffer(dq):
"""
Simple ring buffer.
Args:
size (int): number of items
"""
@derricw
derricw / rebin_ndarray.py
Created April 9, 2015 15:46
Rebin an arbitrary numpy ndarray in N dimensions
import numpy as np
def bin_ndarray(ndarray, new_shape, operation='sum'):
"""
Bins an ndarray in all axes based on the target shape, by summing or
averaging.
Number of output dimensions must match number of input dimensions.
Example