Skip to content

Instantly share code, notes, and snippets.

@fiznool
fiznool / hashid.js
Created November 16, 2014 09:45
Short 'hash' ID generator.
'use strict';
/**
* The default alphabet is 25 numbers and lowercase letters.
* Any numbers that look like letters and vice versa are removed:
* 1 l, 0 o.
* Also the following letters are not present, to prevent any
* expletives: cfhistu
*/
var ALPHABET =
@choonkeat
choonkeat / diy.cloudmailin.bash
Created August 1, 2012 10:33
receiving (postfix) emails via (rails) http; using file upload (-F) for less verbose Rails log (otherwise use --data-urlencode)
#!/bin/bash
MAILFILE=/tmp/mail.$$
CURLFILE=/tmp/mail.$$.curl
cat > $MAILFILE
curl -i -F message=@$MAILFILE "http://localhost/incoming_messages" > $CURLFILE
if grep 'HTTP/1.1 204 No Content' $CURLFILE
then
rm -f $CURLFILE $MAILFILE
fi
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split("")
base = alphabet.length
exports.encode = (i) ->
return alphabet[0] if i is 0
s = ""
while i > 0
s += alphabet[i % base]
i = parseInt(i / base, 10)
@zumbojo
zumbojo / bijective.rb
Created July 9, 2011 22:09
Simple bijective function (base(n) encode/decode)
# Simple bijective function
# Basically encodes any integer into a base(n) string,
# where n is ALPHABET.length.
# Based on pseudocode from http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener/742047#742047
ALPHABET =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split(//)
# make your own alphabet using:
# (('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a).shuffle.join
@balupton
balupton / README.md
Last active April 20, 2022 13:21
Ajaxify a Website with the HTML5 History API using History.js, jQuery and ScrollTo