Skip to content

Instantly share code, notes, and snippets.

View benstiglitz's full-sized avatar

Benjamin Stiglitz benstiglitz

View GitHub Profile
(gdb) po mSavedInvocation
Some day, NSInvocation will have a useful debug description
@benstiglitz
benstiglitz / futures.rb
Created December 15, 2009 22:15 — forked from patrickt/futures.rb
now with threads
include Dispatch
class Future
def initialize(&block)
@@queue_count ||= 0
Thread.current[:futures_queue] ||= Queue.new("org.macruby.futures-#{Thread.current.object_id}")
@group = Group.new
Thread.current[:futures_queue].async(@group) { @value = block[] }
end
@benstiglitz
benstiglitz / sys_param-better.h
Created August 11, 2011 15:37
Hygenic and shadow-safe MIN.
#define MIN_PASTE(A,B) A##B
#define MIN_IMPL(A,B,L) ({ __typeof__(A) MIN_PASTE(__a,L) = (A); __typeof__(B) MIN_PASTE(__b,L) = (B); MIN_PASTE(__a,L) < MIN_PASTE(__b,L) ? MIN_PASTE(__a,L) : MIN_PASTE(__b,L); })
#define MIN(A,B) MIN_IMPL(A,B,__COUNTER__)
@benstiglitz
benstiglitz / gist:1211929
Created September 12, 2011 17:58
Pulling one repository into a subtree of another and pushing to SVN.
git remote add -f tp file:///Volumes/Sources/tp.git/
INITIAL_COMMIT=`git rev-list tp/master --reverse | head -n1`
git checkout -b nb-merge
for MCH in `git rev-list --reverse $INITIAL_COMMIT..tp/master`
do
git merge --squash -s subtree --no-commit $MCH && git commit -C $MCH
done
git filter-branch --msg-filter "sed 's/^/[new-branch] /'" master..HEAD
git svn branch new-branch -m "[new-branch] Creating branch."
git rebase refs/remotes/new-branch
#define is_signed(T) ({ intmax_t __s = -1; T __t = (T)__s; __t < 0; })
#define maxofint(T) (is_signed(T) == 0 ? \
((uintmax_t)1 << (sizeof(T) * 8)) - 1 : \
((uintmax_t)1 << (sizeof(T) * 8 - 1)))
@benstiglitz
benstiglitz / netstring.sh
Created October 30, 2013 18:43
Today’s bad shell script idea: netstrings.
#!/bin/bash
encode() {
local data
OLDIFS="${IFS}"; IFS=""
read -d "" data
IFS="${OLDIFS}"
echo -n $(echo -n "$data" | wc -c)
echo -n ":$data"
echo -n ","
@benstiglitz
benstiglitz / EvilCast.h
Last active December 27, 2015 00:29
Safe bounded casting between types.
#if __has_extension(c_generic_selections) && __has_extension(c_static_assert)
#import "EvilCastImpl.h"
// Returns the value of s, clamping it to the bounds of type t. s and d must either both be integers
// or both be floating-point values.
#define EvilBoundedCheckedCast(t, s) __EvilChecked(t, s, Cast)
// Tries to assign the value of s to d, returning 1 if s is within the bounds of s and 0 if not.
// s and d must either both be integers or both be floating-point values.
#define EvilCheckedAssign(d, s) __EvilChecked(d, s, Assign)
#else
@benstiglitz
benstiglitz / tarripper
Created December 17, 2013 16:49
Create a sha256 catalog of a tar file passed on stdin.
#!/bin/bash
# tarripper
# takes a tar file on stdin
# outputs a sha256 catalog of the tar file on stout
#
# public domain
set -e
while true; do
@benstiglitz
benstiglitz / raw_strings.c
Last active August 29, 2015 13:56
Hacked up raw NSStrings in C.
#define raw_paste(...) #__VA_ARGS__
#define raw_fix(...) raw_paste(__VA_ARGS__)
#define raw_join(x,y) x##y
#define raw_str_h(z, ...) ({char *raw_join(__raw_x, z) = raw_fix(raw_paste(__VA_ARGS__)); [[[NSString alloc] initWithBytes:raw_join(__raw_x, z) + 1 length:strlen(raw_join(__raw_x, z)) - 2 encoding:NSUTF8StringEncoding] autorelease];})
#define raw_str(...) raw_str_h(__COUNTER__, __VA_ARGS__)
/* totally doesn't work with embedded single or double quotes */
@import Foundation;
int main(int argc, char **argv) {
Phone
30 minute simple tech screen
45 minute manager info about job team company and answer questions
30 minute talk about a project you've done
Make decision to interview
In person with coworkers
45–60 minute portfolio/presentation (avoids resume questions in other sessions)
90 minutes coding project with a partner answering questions and helping