Skip to content

Instantly share code, notes, and snippets.

@davepeck
davepeck / FlickDynamics.h
Created April 24, 2009 00:26
Objective-C code that mimics the flick-to-scroll behavior found in iPhone scrolling views. This code is independent of coordinate system, animation rate, and the specific UI context you're working with -- perfect especially for getting good scrolling beha
//
// FlickDynamics.h
// (c) 2009 Dave Peck <davepeck [at] davepeck [dot] org>
// http://davepeck.org/
//
// This code is released under the BSD license. If you use my code in your product,
// please put my name somewhere in the credits and let me know about it!
//
// This code mimics the scroll/flick dynamics of the iPhone UIScrollView.
// What's cool about this code is that it is entirely independent of any iPhone
@davepeck
davepeck / BinaryDataScanner.h
Created April 27, 2009 04:35
Two simple Objective-C classes that make it crazy easy to read data from sequential binary files.
//
// BinaryDataScanner.m
//
// Copyright 2009 Dave Peck <davepeck [at] davepeck [dot] org>. All rights reserved.
// http://davepeck.org/
//
// This class makes it quite a bit easier to read sequential binary files in Objective-C.
//
// This code is released under the BSD license. If you use it in your product, please
// let me know and, if possible, please put me in your credits.
@davepeck
davepeck / yubnub.sh
Created August 31, 2009 00:05
On OSX, invoke yubnub directly from the command line. (I alias this file to 'y' so, for example, 'y gim dave peck')
#!/bin/bash
open "http://www.yubnub.org/parser/parse?command=$(echo -n "$*")"
#!/bin/sh
## script POMODORO for OSX! ##
# #
# requires the GNU gdate command to format dates #
# it's available through macports, in the coreutils package #
# this script also requires Growl to display notifications #
# #
# Times are coded as follows: #
# @ long break : 30 minutes #
@davepeck
davepeck / git-confusion.md
Created April 29, 2010 01:43
What is git trying to tell me?

I don't understand Git.

Why am I told I'm ahead of origin/master by 1 commit?

Why does it go away after what appears to be a no-op git push?

Here's an example interaction with git:

dave@machine ~/dev/project > git status

@davepeck
davepeck / what.md
Created January 15, 2011 02:27
Neato

Foo bar biz bazz!

@davepeck
davepeck / extractors.py
Created January 22, 2011 00:45
A scrapy link extractor that uses BeautifulSoup
import re
from scrapy.link import Link
from urlparse import urljoin
from BeautifulSoup import BeautifulSoup
class SoupLinkExtractor(object):
def __init__(self, *args, **kwargs):
super(SoupLinkExtractor, self).__init__()
allow_re = kwargs.get('allow', None)
@davepeck
davepeck / using_libarchive.m
Created February 1, 2011 17:20
How to use libarchive to unextract on iOS
/* call processNextArchiveEntry in some kind of loop! */
- (int)processNextArchiveEntry:(struct archive *)archive
{
struct archive_entry *entry = NULL;
int result = ARCHIVE_OK;
result = archive_read_next_header(archive, &entry);
if (result == ARCHIVE_OK)
{
@davepeck
davepeck / mass_assignment_sucks.rb
Created February 17, 2011 21:33
Shove this in your Rails 3 config/initializers/ to raise exceptions on bad mass assignment attempts
unless Rails.env.production?
module ActiveModel
class IllegalMassAssignment < StandardError
end
module MassAssignmentSecurity
module Sanitizer
def warn!(invalid_keys)
raise ActiveModel::IllegalMassAssignment, "You attempted to mass-assign: #{invalid_keys.join(', ')}"
end
@davepeck
davepeck / yaml2json.py
Created March 3, 2011 00:18
My dumb script to convert yaml files to json files. Use stdin/stdout.
#!/usr/bin/env python
import sys
import yaml
import json
# Assumed we want to use stdin and stdout
print json.dumps(yaml.load(sys.stdin.read()), indent=4)