Skip to content

Instantly share code, notes, and snippets.

@tvon
tvon / eval_in_file.rb
Created January 7, 2014 21:57
Dump code to be eval'd in a file so as to get a useful traceback if/when it fails.
def eval_in_file(source, options={})
suffix = options[:suffix] || Time.now.strftime("%s%N")
path = options[:path] || "/tmp/"
result = nil
filename = "#{path}eval-#{suffix}.rb"
file = File.new(filename, 'w+')
file.write(source)
file.rewind
begin
@tvon
tvon / moby.sh
Last active December 15, 2015 07:39
Concatenate header files from frameworks in the iOS 6.1 SDK, as described in Mark Dalrymple's talk on headers.
#!/bin/bash
OUTDIR=~/Desktop/moby
BASE="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks"
mkdir -p ${OUTDIR}
cd ${BASE}
for dir in *
do
[UIView transitionWithView:self.view
duration:0.25
options:UIViewAnimationOptionsTransitionCrossDissolve
animations:^{
[self.view addSubview:overlay];
}
completion:nil];
@tvon
tvon / raw-client.rb
Created August 29, 2011 20:42
raw api file upload
#!/usr/bin/env ruby
require "net/http"
require "uri"
url = 'http://example.com/submissions.json'
token = 'TOKEN HERE'
boundary = "pop-pop"
uri = URI.parse(url)
@tvon
tvon / pow.sh
Created April 8, 2011 18:52
"pow" shell function for quick linking of directories to ~/.pow (if using http://pow.cx)
function pow {
if [ -d "`cd $1; pwd`" ]; then
ln -s "`cd $1; pwd`" ~/.pow/
fi
}
@tvon
tvon / homebrew-macvim.sh
Created April 8, 2011 18:48
Use homebrew installation of macvim for terminal vim command.
if [ -x `which brew` ]; then
macvim_version=`brew list --versions macvim | sed 's/.* \([0-9\.\-]*\)$/\1/'`
if [ -n "${macvim_version}" ]; then
alias vim=`brew --prefix`/Cellar/macvim/${macvim_version}/MacVim.app/Contents/MacOS/Vim
fi
fi
@tvon
tvon / freeciv.net-bootstrap.sh
Created March 7, 2011 21:18
A script to bootstrap (and build) freeciv.net on Ubuntu 10.10
#!/bin/bash
basedir="${HOME}/freeciv-build"
srcdir="${basedir}/freeciv-web"
destdir="${basedir}/build"
# User will need permissions to create a database
mysql_user="root"
mysql_pass="changeme"
#!/bin/sh
#
# Copyright (c) 2002-2004 Michael Telahun Makonnen. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
@tvon
tvon / admin.py
Created April 16, 2009 13:47
Customizing User list view and edit form in Django
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from forms import UserChangeForm
class UserAdmin(BaseUserAdmin):
list_display = ('username', 'last_name', 'first_name', 'is_superuser', 'is_staff')
#!/usr/bin/env python
"""
This script aims at providing a simple way to bootstrap a self-contained django project.
In short, it makes a few trivial decisions for you.
To those who use the Django framework this may seem a bit unecessary, but I believe that
it could be easier to get started with django, without having to impose minor decisions
on new users such as where to place templates and basic media files.