Skip to content

Instantly share code, notes, and snippets.

@clehner
clehner / hashchange.js
Created March 26, 2010 22:35
Simulate onhashchange support
// Simulate onhashchange support in all browsers
"onhashchange" in window || (function () {
var lastHash = '';
function pollHash() {
if (lastHash !== location.hash) {
lastHash = location.hash;
var event = document.createEvent("HTMLEvents");
event.initEvent("hashchange", true, false);
document.body.dispatchEvent(event);
if (typeof onhashchange == "function") {
<head>
<title>swarm!</title>
<script type="text/javascript" language=JavaScript src="buzzWorker.js"></script>
<style>
.thing {
position:absolute;
}
.dying {
color:#ff0000;
font-weight:bold;
@clehner
clehner / append_content.py
Created July 26, 2010 04:21
A better blip.append_content() for python wave robots.
from BeautifulSoup import BeautifulSoup, NavigableString
from waveapi import element
import re
import htmlentitydefs
IMAGE_PLACEHOLDER = '***{{((IMAGE_ELEMENT))}}***'
def append_content_to_blip(blip, content, type=None):
if type == 'text/plain':
# Replace characters that Wave breaks on
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
// one way
foo ? bar.doSomething(el) : bar.doSomethingElse(el);
@clehner
clehner / classy.js
Created October 18, 2010 02:17
Simple and Fast Javascript Inheritance. (No fancy stuff)
/*
Classy - Simple and Fast Javascript Inheritance.
(No fancy stuff)
Inspiration:
http://ejohn.org/blog/simple-javascript-inheritance/
http://valums.com/javascript-oop/
http://www.broofa.com/blog/2009/02/javascript-inheritance-performance/
Example:
@clehner
clehner / accesscode.js
Created April 24, 2011 05:53
Access Code Generator & Validator
// Access Code Generator & Validator
// API:
// string generateAccessCode()
// Boolean validateAccessCode(codeString)
(function () {
// configure:
var difference = 5;
@clehner
clehner / shapemaker.html
Created June 23, 2011 04:56
Draw simple shapes with points.
<!doctype html>
<html>
<head>
<title>Shape Maker</title>
<style type="text/css">
body {
font-family: Helvetica, Arial, sans-serif;
line-height: 1.5em;
font-size: 14px;
}
@clehner
clehner / irssi-growl.sh
Created September 28, 2012 04:27
Growl notifications for remote Irssi
#!/bin/sh
server='127.0.0.1'
log='irclogs/*/*.log'
ssh "$server" "tail -n1 -f $log" | sed -l 's/^[^ ]* < //' | while read line; do
sender="${line%>*}"
msg="${line#*> }"
growlnotify -m "$msg" "$sender"
done
@clehner
clehner / git.sh
Created October 9, 2012 23:22
Simple Interactive Git Shell
#!/bin/bash
# git.sh - Interactive Git Shell
# store command history here
HISTFILE=~/.gitsh_history
control_c() {
# save history before exiting
history -a
# i can't figure out how to make this just break out of the read command
@clehner
clehner / update.coffee
Created November 28, 2012 03:24 — forked from comboy/update.rb
update all your namecoin domains
#!/usr/bin/env coffee
# put this file in the same dir as namecoind executable
child_process = require 'child_process'
child_process.exec './namecoind name_list', (err, stdout, stderr) ->
(JSON.parse stdout).forEach (domain) ->
if domain.expires_in < 5000
command = "./namecoind name_update #{JSON.stringify domain.name} #{JSON.stringify domain.value}"