Skip to content

Instantly share code, notes, and snippets.

View peterwmwong's full-sized avatar

Peter Wong peterwmwong

View GitHub Profile
@peterwmwong
peterwmwong / vowsTeardown.js
Created January 11, 2011 05:40
Vows teardown test case with console.log
vows.describe("Vows with teardowns").addBatch({
"A context": {
topic: function () {
return { flag: true };
},
"And a vow": function (topic) {
assert.isTrue(topic.flag);
},
"And another vow": function (topic) {
assert.isTrue(topic.flag);
@peterwmwong
peterwmwong / SuperCrapCode001.java
Created March 25, 2011 23:49
The author of this code will NEVER be For-given
public static int writePhraseTree(PhraseTree tree, Connection conn) throws Exception {
int affectedRows = 0;
for (int z_i = 0; z_i < tree.getZoneCount(); z_i++) {
Zone z = tree.getZone(z_i);
affectedRows += writePhraseNodeType(z, conn);
for (int c_i = 0; c_i < z.getCategoryCount(); c_i++) {
Category c = z.getCategory(c_i);
@peterwmwong
peterwmwong / storyTemplate.coffee
Created July 17, 2011 22:52
Example of new cell / R templating in CoffeeScript and equivalent JSP
R '.story',
R 'a.num', storynum
R LabeledCounts, class: 'tasks' # Render LabeledCounts cell
R 'ul.aList',
for a in [0...10]
R 'li', a
if exampleCondition
R '.ifTrue'
else
R '.ifFalse'
@peterwmwong
peterwmwong / cell-render-haml.coffee
Created August 3, 2011 05:34
Cell Rendering: HTML-ish/HAML-ish (pick your poison)
# HAML-ish
define
render: (_)-> [
_ 'input#newtodo', type:'text', placeholder:'... new todo'
_ 'ul.todos',
for todo in window.todoList
_ 'li', todo
]
@peterwmwong
peterwmwong / livejs4-track-dynamic-js-css-adds.patch
Created August 11, 2011 02:16
livejs 4 patch to track dynamically added JS & CSS
@@ -34,12 +34,12 @@
var Live = {
// performs a cycle per interval
heartbeat: function () {
if (document.body) {
- // make sure all resources are loaded on first activation
- if (!loaded) Live.loadresources();
+ // Look for resources to track
+ Live.loadresources();
@peterwmwong
peterwmwong / Results_ubuntu_10.04__node_0.5.10.txt
Created October 30, 2011 19:34
fs.watch/fs.writeFileSync win vs ubuntu
$ node lib/test.js
fs.writeFileSync: /tmp/test.txt
fs.watch: /tmp/test.txt
fs.writeFileSync: /tmp/test.txt
>> fs.watch CALLBACK: change test.txt
FSWatcher.close()
define( function() {
return {
initialize: function() {
this.$el
.attr( 'name', this.options.property )
.addClass( this.options.property );
},
render_el: function(__) { return [
@peterwmwong
peterwmwong / spec.coffee
Created November 14, 2012 14:34
require.js spec plugin
define (require)->
_ = require 'underscore'
modulesConfigString =
"""
require.config({
baseUrl:'src',
paths: {
'backbone-validation': '../node_modules/backbone-validation/dist/backbone-validation-amd',
cell: '../vendor/cell',
backbone: '../node_modules/backbone/backbone',
@peterwmwong
peterwmwong / spec-runner-index.html
Created November 14, 2012 21:15
spec-runner index.html
<!DOCTYPE HTML>
<html>
<head>
<title>Spec Runner</title>
<link rel="shortcut icon" type="image/png" href="/vendor/jasmine/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="/vendor/jasmine/jasmine.css">
<link rel="stylesheet" type="text/css" href="./jasmine-override.css">
</head>
<body>
<script src="../vendor/sinon.js"></script>
@peterwmwong
peterwmwong / gist:4078510
Created November 15, 2012 12:55
disable mac agents
launchctl unload -w /System/Library/LaunchAgents/com.apple.CalendarAgent.plist
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist