Skip to content

Instantly share code, notes, and snippets.

View philikon's full-sized avatar

Philipp Weitershausen philikon

View GitHub Profile
class WebSocketImage extends React.Component {
state = {
blob: null,
};
componentDidMount() {
let ws = this.ws = new WebSocket(...);
ws.binaryType = 'blob';
ws.onmessage = (event) => {
if (this.state.blob) {
@philikon
philikon / prebound.html
Created July 12, 2011 18:15
Prebound JS methods
<!DOCTYPE html>
<html>
<head>
<script type="application/javascript;version=1.7">
/**
* Proxy handler to automatically bind methods.
*/
function prebound(obj) {
return {
@philikon
philikon / email2username.py
Created June 14, 2011 18:54
Convert email address to Sync username
#!/bin/env python
import base64
import hashlib
import sys
if len(sys.argv) < 2:
print >>sys.stderr, "Usage: %s <email address>" % sys.argv[0]
sys.exit(1)
email = sys.argv[1].lower()
@philikon
philikon / dev-prefs.js
Created May 2, 2011 20:29
Developer prefs
// https://developer.mozilla.org/en/Setting_up_extension_development_environment
user_pref("javascript.options.showInConsole", true);
user_pref("nglayout.debug.disable_xul_cache", true);
user_pref("browser.dom.window.dump.enabled", true);
user_pref("javascript.options.strict", true);
user_pref("extensions.logging.enabled", true);
user_pref("dom.report_all_js_exceptions", true);
user_pref("devtools.errorconsole.enabled", true);
user_pref("services.sync.log.appender.file.logOnSuccess", true);
@philikon
philikon / wtf8.py
Created February 8, 2011 08:22
WTF-8 codec for Python
# wtf8.py
import codecs
def encode(input, errors='strict'):
return input.encode('utf-8', errors).decode('latin-1', errors).encode('utf-8', errors), len(input)
def decode(input, errors='strict'):
return input.decode('utf-8', errors).encode('latin-1', errors).decode('utf-8', errors), len(input)
class StreamWriter(codecs.StreamWriter):
# Start a new chapter by branching the current branch off:
(branch chapter5)$ git checkout -b chapter6
# Make some commits:
(branch chapter6)$ git commit
(branch chapter6)$ git commit
# Oh noez, chapter 3 needs a bugfix
(branch chapter6)$ git checkout chapter3
(branch chapter3)$ git commit -m "Bugfix"
// https://developer.mozilla.org/en/Setting_up_extension_development_environment
user_pref("javascript.options.showInConsole", true);
user_pref("nglayout.debug.disable_xul_cache", true);
user_pref("browser.dom.window.dump.enabled", true);
user_pref("javascript.options.strict", true);
user_pref("extensions.logging.enabled", true);
user_pref("dom.report_all_js_exceptions", true);
// Install jQuery in each XUL window namespace
var wu = require("window-utils");
var module = require("securable-module");
var windowtracker = new wu.WindowTracker({
onTrack: function (window) {
var namespace = {
window: window,
document: window.document,
location: window.location,
/*** Monkey patch vs. evil() ***/
// Consider an object with a method:
var Obj = {
aMethod: function (arg) {
print("Hello " + arg);
}
};
Obj.aMethod("World!");
// Consider a function:
function multiply(a, b) {
return a*b;
}
print(multiply(Math.PI, Math.exp(1)))
// We want to replace it with an "enhanced" version that does some
// stuff before invoking the original, e.g. generate debugging output