Skip to content

Instantly share code, notes, and snippets.

View bdotdub's full-sized avatar

Benny Wong bdotdub

View GitHub Profile
@bdotdub
bdotdub / sort_and_vectorize.pl
Created January 9, 2009 18:15
Comparison between perl and ruby code. Ruby wins in my book
@tuples = sort { $a->[0] <=> $b->[0] } @tuples;
my $dates = map { $_->[0] } @tuples;
my $values = map { $_->[1] } @tuples;
function click(theFunction) {
// Something happens
theFunction(event);
}
// Example 1
$('a').click(alert('hi'));
// Example 2: this does the same thing as example 1
alert_result = alert('hi');
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>test</title>
<!-- JQUERY -->
<script type="text/javascript" charset="utf-8">
@bdotdub
bdotdub / gist:70317
Created February 25, 2009 17:54
Equivalent?
filter(P, [H|T]) ->
case P(H) of
true -> [H|filter(P, T)];
false -> filter(P, T)
end;
filter(P, []) ->
[].
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#!/usr/bin/ruby
require 'aws/s3'
class GitRepoArchiver
attr_reader :repo_name, :repo_dir, :bucket
def init(args)
# Change the current working directory
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