Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import datetime
import sys
def timestamp():
now = datetime.datetime.now()
return (now.strftime('%Y-%m-%d %H:%M:%S.%m') +
".%06d" % now.microsecond)
@gkeramidas
gkeramidas / gist:e2ec1f18d869e5b709a5a226396aa502
Created November 28, 2020 03:50
macOS 11.0 failure to install in /opt/brew
1127 19:45 gkeramidas@gkeramidas-mbp:/opt/brew (master)$ rm -fr .[^.]* *
1127 19:45 gkeramidas@gkeramidas-mbp:~$ git clone https://github.com/Homebrew/brew /opt/brew
Cloning into '/opt/brew'...
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 161723 (delta 6), reused 7 (delta 3), pack-reused 161709
Receiving objects: 100% (161723/161723), 41.42 MiB | 27.67 MiB/s, done.
Resolving deltas: 100% (119886/119886), done.
#!/usr/bin/env python3
import argparse
import sys
def pluralize(count):
return "bugs" if count > 1 else "bug"
@gkeramidas
gkeramidas / gist:282be1d334ca86737462ecf5cc215c7f
Created May 24, 2018 00:44
Random death & rebirth in rule 110
0523 17:42 gkeramidas@gkeramidas-mbp:~$ python cellular.py --sleep 100 --width 210 --rule 110 2>&1 | head -30
('cellular: rule=110 width=210 delay=0.1',)
## # ### ## ###### # ## #### # ### ## ###### # #### # # ## #### # ### #### ### # ### # # # # ## # ## # #### # ## # ## # # ### ## ## # # ## # ## # # # ###
#### # ## ### # #### #### ## ## # ###### ## ### #### ##### # #### # ### ### ##### ## ###### ## ##### ###### #### ######## ## ## # ## ######## ####### ##### #### # ##
## ###### #### # ### ## ######### ## #### ## # ### #### # ## ### ## # ### ##### # ## #### ## # ## # ### ##### ######## # ## # ## # ## # ## #####
### # ### ## ## # ## #### ## ### # ####### # ## # #### ### # ######## ## # #### ### # ## ##### ##### # ## # ### ## ## ### ## ### ## ##### ### # ##
# ## ## # ## ### ######
@gkeramidas
gkeramidas / session.sh
Created July 25, 2017 05:42
mosh/tmux wrapper for named tmux sessions
#!/bin/sh
progname=$(basename $0)
now() {
date '+%m%d %H:%M:%S'
}
err() {
errcode=$1
0918 22:44 gkeramidas@gkeramidas-mbp:~$ ./to-ringtone.sh 00:00 00:30 ~/Music/iTunes/iTunes\ Media/Music/Black\ Sabbath/Heaven\ and\ Hell/01\ Neon\ Knights.mp3 neon.m4r
ffmpeg version 3.1.3 Copyright (c) 2000-2016 the FFmpeg developers
built with Apple LLVM version 7.3.0 (clang-703.0.31)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.1.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libopenh264 --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-libfdk-aac --enable-libx265 --disable-lzma --enable-nonfree --enable-vda
libavutil 55. 28.100 / 55. 28.100
libavcodec 57. 48.101 / 57. 48.101
libavformat 57. 41.100 / 57. 41.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 47.100 / 6. 47.100
libavresample 3. 0. 0 / 3. 0. 0
@gkeramidas
gkeramidas / mp3-to-ringtone.sh
Created September 19, 2016 05:43
Convert a clip of an MP3 file to an AAC encoded ringtone
#!/bin/sh
progname=`basename $0`
err()
{
code="$1"
if test -z "$code" ; then
code=1
fi
@gkeramidas
gkeramidas / gist:c73405246eea374199f0
Created January 26, 2015 04:08
Auto-identify support for ERC and Bitlbee, using .authinfo keys
(defun keramida/erc-bitlbee-auto-identify ()
"Auto-identify for Bitlbee channels using authinfo or netrc.
The entries that we look for in netrc or authinfo files have
their 'port' set to 'bitlbee', their 'login' or 'user' set to the
current nickname and 'server' set to the current IRC server's
name. A sample value that works for authenticating as user
'keramida' on server 'localhost' is:
machine localhost login \"keramida\" password \"****\" port bitlbee"
@gkeramidas
gkeramidas / awk-or-sed.sh
Created February 21, 2014 08:17
AWK or sed for removing the first 'field' of a line
# This should print 'second:third'
echo first:second:third | awk -F: '{ print substr($0, index($0, FS) + 1) }'
# Same here, but shorter code.
echo first:second:third | sed -e 's/^[^:]*://'
# Slightly more verbose awk version for 'second:third' output
@gkeramidas
gkeramidas / PrimeCacheModule.scala
Created September 24, 2013 10:59
Caching the results of primality check, and expiring after a tunable TTL
import java.util.concurrent.atomic.AtomicReference
import collection.immutable.HashMap
/*
* A module which implements a primality cache for integers, with a max-age parameter which controls
* when a primality result will be considered 'expired' and recalculated from scratch.
*/
trait PrimeCacheModule {
/** The current time in milliseconds. Timestamp for cache entries and 'now' */
def now = System.currentTimeMillis