Skip to content

Instantly share code, notes, and snippets.

View bdotdub's full-sized avatar

Benny Wong bdotdub

View GitHub Profile
class Archiver
def initialize(directory)
@directory = directory
end
def tar_and_gzip
# Go into the directory
Dir.chdir @directory
# Since this will be the fully qualified directory
@bdotdub
bdotdub / gist:107225
Created May 5, 2009 21:41
iPhone Obj-C code to use different UITableViewCells in one UITableView
/*
* Author: Benny Wong - http://bwong.net/
*
* Code for this Stack Overflow question:
* http://stackoverflow.com/questions/819019/how-do-i-add-2-or-more-customized-uitableviewcell-to-nsmutable-array/820195
*
*/
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
@bdotdub
bdotdub / gist:108228
Created May 7, 2009 17:52
get the unique id of an iphone
NSString *id = [[UIDevice currentDevice] uniqueIdentifier];
(function($) {
$.fn.konami = function(callback, code) {
if (keySequence == undefined)
keySequence = "38,38,40,40,37,39,37,39,66,66";
return this.each(function() {
var keysPress = [];
$(this).keydown(function(e){
keysPressed.push( e.keyCode );
@bdotdub
bdotdub / error_handler.rb
Created June 17, 2009 03:47
Hoptoad notifier for Sinatra
error do
exception = request.env['sinatra.error']
Hoptoad::Notifier.send_error exception, params, request.env if %w(staging production).include?(ENV['RACK_ENV'])
erb :five_hundred
end
- (id)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// Record the starting point
UITouch *touch = [touches anyObject];
self.tapStartPoint = [touch locationInView:self];
self.tapStartPointWithinImageView = [touch locationInView:self.imageView];
// Pass to superclass
[super touchesBegan:touches withEvent:event];
}
# Quickie shell script that will tell you how long your Mac has been asleep
ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'
#pragma mark UIWebViewDelegate methods
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
NSURL *loadURL = [[request URL] retain]; // retain the loadURL for use
if (([[loadURL scheme] isEqualToString: @"http"] || [[loadURL scheme] isEqualToString: @"https"] || [[loadURL scheme] isEqualToString:@"mailto"]) &&
(navigationType == UIWebViewNavigationTypeLinkClicked)) // Check if the scheme is http/https. You can also use these for custom links to open parts of your application.
return ![ [ UIApplication sharedApplication ] openURL: [ loadURL autorelease ] ]; // Auto release the loadurl because we wont get to release later. then return the opposite of openURL, so if safari cant open the url, open it in the UIWebView.
@bdotdub
bdotdub / rebase_branch
Created October 21, 2009 20:31
rebasing git branches
#!/bin/bash
# MAIN_BRANCH will use the first parameter or default to 'master'
MAIN_BRANCH=${1-master}
BRANCH=`git symbolic-ref HEAD | sed 's#refs/heads/##'`
BRANCH_HAS_DIRTY_FILES=`git diff-index --name-only HEAD --`
if [[ $MAIN_BRANCH = $BRANCH ]]; then
echo "You are already on the $BRANCH branch"

Norc on Dreamhost

Norc is a Task Management System that replaces Unix cron developed by Darrell Silver for use at Perpetually.com. Norc on Dreamhost gives you a basic template to get Norc up and running on Dreamhost.

To read more about Norc: http://github.com/darrellsilver/norc

Installation

The installation process involves a few steps. Before we get started, make sure you have shell access for your user. To check this, go to Users > Manage Users in your Dreamhost Web Panel.