Skip to content

Instantly share code, notes, and snippets.

View psobot's full-sized avatar

Peter Sobot psobot

View GitHub Profile
@psobot
psobot / NSDate+Extensions.swift
Created June 23, 2015 04:08
Swift NSDate Comparison Extension
// NSDate doesn't include overrides for standard comparison operators in Swift.
// This extension adds <, >, <=, >=, and ==, using NSDate's built-in `compare` method.
// MIT licensed.
func <=(lhs: NSDate, rhs: NSDate) -> Bool {
let res = lhs.compare(rhs)
return res == .OrderedAscending || res == .OrderedSame
}
func >=(lhs: NSDate, rhs: NSDate) -> Bool {
let res = lhs.compare(rhs)
@psobot
psobot / bouncer.py
Last active June 8, 2023 02:42
Logic Pro X Project Bounce script
import os
import sys
import time
import atomac
import subprocess
if len(sys.argv) < 2:
print "Usage: bouncer.py <path_to_logic_project> (<path_to_logic_project>)"
os.exit(1)
@psobot
psobot / phone_prefixes.json
Last active February 2, 2022 11:02
Mapping of phone number prefixes to geographic coordinates, countries and regions.
{
"+1": [[63.004759, -99.392855], "Canada"],
"+1242": [[26.215829, -98.187851], "Bahamas"],
"+1246": [[13.186666, -59.55727], "Barbados"],
"+1264": [[18.217056, -63.050923], "Anguilla"],
"+1268": [[17.08682, -61.796431], "Antigua and Barbuda"],
"+1284": [[18.719042, -64.326495], "British Virgin Islands"],
"+1340": [[33.282206, -117.185162], "US Virgin Islands"],
"+1345": [[19.323764, -81.195721], "Cayman Islands"],
"+1441": [[32.301277, -64.77506], "Bermuda"],
@psobot
psobot / keybase.md
Created March 29, 2014 23:57
keybase prove github

Keybase proof

I hereby claim:

  • I am psobot on github.
  • I am psobot (https://keybase.io/psobot) on keybase.
  • I have a public key whose fingerprint is B8C4 380D 42A7 C58C 9528 93AD 66BD 052C A0BF 6065

To claim this, I am signing this object:

@psobot
psobot / Makefile
Last active August 29, 2015 13:57 — forked from jlfwong/Makefile
.PHONY: run
run: test
./$<
test: test.o runtime.o
gcc -arch i386 $^ -o $@
%.o: %.asm
nasm -f macho $< -o $@
@psobot
psobot / format_stacktrace_from_strace.py
Last active October 31, 2022 12:58
Dump a stack trace of a Go process without stderr attached. This is a super dirty hack, but it uses strace, pgrep and python to send QUIT to a Golang process, intercept its system calls to stderr, and format them nicely for humans. Tested on Ubuntu with Go 1.1.
import sys
import re
output = sys.stdin.readlines()
r = re.compile(r'write\(2, "(.+?)", \d+\)\s+= \d+')
print "".join([x.replace(r'\n', "\n").replace(r'\t', "\t") for x in sum([r.findall(o) for o in output], [])])
@psobot
psobot / json_list_incrby.lua
Created October 1, 2013 14:03
Atomic Redis INCRBY on a specific field of all JSON-encoded elements of a Redis list.
-- Let's say you've got a Redis list that's composed of JSON values:
-- -- {"a": 5.2, "b": "something blah blah"}
-- -- {"a": 4.3, "b": "something blah blah"}
-- -- {"a": 125.2, "b": "something blah blah"}
-- And let's say that you want to increment all of the "a" fields by n.
-- Call the below script with:
-- -- KEYS = [key_of_list_to_update]
-- -- ARGV = [json_key_to_incr, value_to_add]
local num = redis.call('llen', KEYS[1])
@psobot
psobot / terminatablethread.py
Created September 13, 2013 15:47
A terminatable thread class that automatically joins all threads with the main thread on exit. Based on work by Tomer Filiba (http://tomerfiliba.com/recipes/Thread2/) but updated and tested on Python 2.7.1.
import atexit
import ctypes
import inspect
import threading
"""
Any instances of TerminatableThread that are running when the program exits
(due to normal interpreter shutdown, KeyboardInterrupt, SystemExit, etc.)
will have SystemExit raised within their next 100 Python bytecode executions,
allowing them to possibly catch the SystemExit and clean up as necessary.
@psobot
psobot / bad_scoping.py
Created March 12, 2013 21:27
Python Scoping Pitfalls
class MyClass(object):
def __init__(self):
self.foo = "I'm the correct variable!"
def do_something(self):
# Whoops, I forgot to write this as "self.foo".
print foo
if __name__ == "__main__":
foo = "Herp derp, I'm the wrong variable."

So you want to use Node.js…

Current status: incomplete draft.

Speed

  • Computation: V8 very fast; significantly faster than most interpreted languages. The one very big exception is PyPy, which is in the same ballpark