Skip to content

Instantly share code, notes, and snippets.

View devongovett's full-sized avatar

Devon Govett devongovett

View GitHub Profile
@devongovett
devongovett / succ.js
Created July 13, 2011 20:39
An implementation of Ruby's string.succ method in JavaScript
/*
* An implementation of Ruby's string.succ method.
* By Devon Govett
*
* Returns the successor to str. The successor is calculated by incrementing characters starting
* from the rightmost alphanumeric (or the rightmost character if there are no alphanumerics) in the
* string. Incrementing a digit always results in another digit, and incrementing a letter results in
* another letter of the same case.
*
* If the increment generates a carry, the character to the left of it is incremented. This
@devongovett
devongovett / Usage.coffee
Created July 30, 2011 17:52
Asynchronous if statements in CoffeeScript
Async.IF somecondition, ->
doSomething()
.ELSEIF someothercondition, ->
doSomethingElse()
.ELSE ->
anotherThing()
@devongovett
devongovett / CSSTransform.coffee
Created August 4, 2011 20:15
WebKitCSSTransform for all browsers
class CSSTransform
constructor: ->
@m11 = @m22 = @m33 = @m44 = 1
@m12 = @m13 = @m14 = 0
@m21 = @m23 = @m24 = 0
@m31 = @m32 = @m34 = 0
@m41 = @m42 = @m43 = 0
if arguments.length
@setMatrix arguments...
class Test
method: ->
setTimeout ->
super
# ...
, 10
function getElementsByClassName(oElm, strTagName, strClassName){
var arrElements = (strTagName == "*" && oElm.all)? oElm.all :
oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
strClassName = strClassName.replace(/\-/g, "\\-");
var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
var oElement;
for(var i=0; i<arrElements.length; i++){
oElement = arrElements[i];
if(oRegExp.test(oElement.className)){
###
# An implementation of the msgpack serialization format - http://msgpack.org/
# By Devon Govett
# MIT LICENSE
###
class MsgPack
idx = 0
@pack: (data, byteArray = false) ->
@devongovett
devongovett / columns.coffee
Created August 17, 2011 01:49
PDFKit examples 3
loremIpsum = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in...'
doc.text loremIpsum, columns: 2
#
# Hyphenator - a fast hyphenation algorithm
# By Devon Govett
# MIT LICENSE
#
# Based on:
# 1. The algorithm described by Frank Liang and used in TeX - http://tug.org/docs/liang/liang-thesis.pdf
# 2. Hyphenator.js - http://code.google.com/p/hyphenator
# 3. Hypher.js - https://github.com/bramstein/Hypher/
#
<!DOCTYPE html>
<html>
<head>
<title>WebSocket test</title>
</head>
<body>
<script src="http://localhost:8080/socket.io/socket.io.js"></script>
<script>
var server = 'smtp.example.com',
port = 587,