Skip to content

Instantly share code, notes, and snippets.

View dokipen's full-sized avatar

Bob Corsaro dokipen

  • Medium.com
  • Newburyport, MA
View GitHub Profile
@dokipen
dokipen / luhns.js
Created January 7, 2010 21:40
Luhn's on Prototype
/**
* Luhn's algorithm in javascript with prototype.
*
* This is used for credit card number validation.
*
* You'll have to scrub the number before passing it in. If any
* non-numeric characters are passed then this will fail.
*
* @see http://en.wikipedia.org/wiki/Luhn_algorithm
*/
@dokipen
dokipen / usher static files
Created April 16, 2010 14:26
Deprecated usher file mounting
# I'm using this
base = File.expand_path(File.join(File.dirname(__FILE__)))
app = Rack::File.new(base)
routes = Usher::Interface.for(:rack) do
add("/static/(js|css|img)/:file").to(app)
end
# It would be nice to use this. I made the paths different
Sometimes, when adding a branch like so:
`fetch = path/to/branch:refs/remotes/git-svn/mynewbranch`
the path to the branch is mispelt.
You then go ahead and do a `$ git svn fetch` and git finds nothing. You realize what an incredible dolt you are and fix the path,
`fetch = realpath/to/branch:refs/remotes/git-svn/mynewbranch`
@dokipen
dokipen / prototype-pub-sub.js
Created April 26, 2010 16:16
Generic pub-sub in Prototype
PubSub = {
initPubSub: function() {
this._dummy = new Element('span');
},
fire: function(event, memo) {
this._dummy.fire(event, memo);
},
observe: function(event, handler) {
this._dummy.observe(event, handler);
}
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<head>
<title>Test</title>
<script type="text/javascript" src="/static/js/jquery.js"></script>
<script type="text/javascript" src="/static/js/jquery-svg/jquery.svg.js"></script>
@dokipen
dokipen / dinc_connect.sh
Created June 20, 2010 16:49
Ad-Hoc wifi on Gentoo
#!/bin/sh
pkill wpa
iwconfig wlan0 mode Ad-Hoc
iwconfig wlan0 essid AndroidTether
iwconfig wlan0 ap <incredible wifi mac address>
ifconfig wlan0 up
@dokipen
dokipen / multi-version-jquery.js
Created July 8, 2010 15:38
Multi-Version jQuery on Crack
function(my_selector) {
var old_jQuery = jQuery;
var doWork = function() {
var my_jQuery = jQuery.noConflict();
jQuery = old_jQuery;
// load up myplugin on my_jQuery
my_jQuery(my_selector).myplugin({...});
}
#!/bin/sh
# Ideas taken from http://www.mikerubel.org/computers/rsync_snapshots/
#
# This increments all backup numbers and deletes or moves the last one
# to a monthly backup depending on the date.
#
# WARNING: This code breaks badly if you try and backup to dirs with the
# same basename! There is no safety mechanism.
# where backups are stored
(function($) {
$('a');
})(YAHOO.util.Selector.query);
@dokipen
dokipen / gist:706070
Created November 19, 2010 02:58
Home value appreciation
$PER_YEAR = 1.07
def appreciate(value, years)
return value if years == 0
appreciate(value * $PER_YEAR, years - 1)
end
# my home was sold for 52k in 95'
puts appreciate(52000, 16)
# >> 153512.514925401