Skip to content

Instantly share code, notes, and snippets.

View shawndumas's full-sized avatar

Shawn Dumas shawndumas

View GitHub Profile
@shawndumas
shawndumas / logicGates.js
Created August 8, 2011 13:06
Starting with NAND only...
var logicGates = {
nand: function (a, b) {
return !(a && b);
},
not: function (a) {
return this.nand(a, a);
},
and: function (a, b) {
return this.not(this.nand(a, b));
},
@shawndumas
shawndumas / logicGates.fs
Created August 8, 2011 13:10
Starting with NAND only...
type LogicGate =
| ON
| OFF
| NAND of LogicGate * LogicGate
| NOT of LogicGate
| AND of LogicGate * LogicGate
| OR of LogicGate * LogicGate
| NOR of LogicGate * LogicGate
| XOR of LogicGate * LogicGate
| XNOR of LogicGate * LogicGate
@shawndumas
shawndumas / TreeWalker.js
Created August 8, 2011 15:49
A JavaScript Implementation of TreeWalker
var NodeFilter = {
FILTER_ACCEPT: 1,
FILTER_REJECT: 2,
FILTER_SKIP: 3,
SHOW_ALL: -1,
SHOW_ELEMENT: 1,
SHOW_ATTRIBUTE: 2,
SHOW_TEXT: 4,
SHOW_CDATA_SECTION: 8,
SHOW_ENTITY_REFERENCE: 16,
@shawndumas
shawndumas / types.js
Created August 10, 2011 23:22
Surefire Type Detection
var typs = {};
(function (self) {
var values = [
'Function',
'Object',
'Array',
'String',
'Number',
'Date',
@shawndumas
shawndumas / ready.js
Created August 12, 2011 12:46
Cross Browser DOMReady
// http://www.dustindiaz.com/smallest-domready-ever
var ready = function (f) {
(/complete|loaded|interactive/.test(document.readyState)) ?
setTimeout('ready(' + f + ')', 9) :
f();
};
@shawndumas
shawndumas / mkrepo.sh
Created September 9, 2011 18:13
Git init the current directory and create a new remote bare repository for it (on g:\ in this case)
#!/bin/sh
CURRENT_DIR=${PWD##*/}
git init
git add .
git commit -m "first commit"
pushd $1
mkdir "$CURRENT_DIR.git"
cd "$CURRENT_DIR.git"
@shawndumas
shawndumas / XSSTextBox.vb
Created September 16, 2011 12:35
(Partial) XSS Fix For ASP.NET
' In the web.config
'
'<pages>
' <tagMapping>
' <clear />
' <add tagType="System.Web.UI.WebControls.TextBox"
' mappedTagType="XSSTextBox"/>
' </tagMapping>
'</pages>
@shawndumas
shawndumas / identity.sql
Created September 27, 2011 15:38
IDENT_CURRENT, @@IDENTITY, & SCOPE_IDENTITY
/*
* IDENT_CURRENT returns the last identity value generated for a specific table in any session and any scope.
* @@IDENTITY returns the last identity value generated for any table in the current session, across all scopes.
* SCOPE_IDENTITY returns the last identity value generated for any table in the current session and the current scope.
*/
IF OBJECT_ID(N't6', N'U') IS NOT NULL
DROP TABLE t6 ;
GO
@shawndumas
shawndumas / nextFibonacci.js
Created September 30, 2011 20:43
Next Fibonacci
var r = [],
n = 0,
a = 0,
b = 1,
next;
function nextFibonacci() {
next = a + b;
return b = (a = b, next);
@shawndumas
shawndumas / soundex.js
Last active February 21, 2024 11:47
Soundex in JavaScript
var soundex = function (s) {
var a = s.toLowerCase().split(''),
f = a.shift(),
r = '',
codes = {
a: '', e: '', i: '', o: '', u: '',
b: 1, f: 1, p: 1, v: 1,
c: 2, g: 2, j: 2, k: 2, q: 2, s: 2, x: 2, z: 2,
d: 3, t: 3,
l: 4,