Skip to content

Instantly share code, notes, and snippets.

@lancejpollard
lancejpollard / list-files.md
Created February 6, 2013 04:14
node benchmarks
var tfs = require('tfs')
  , cp = require('child_process');

suite.add('recursively iterate through files', function(deferred) {
  tfs.glob('node_modules/**/*.js', function() {
    deferred.resolve();
  });
}, options);
@darylteo
darylteo / Test.java
Created December 20, 2012 13:07
Testing asynchronous code.
import org.junit.BeforeClass;
import org.junit.Test;
import org.vertx.java.core.Handler;
import org.vertx.java.core.Vertx;
import org.vertx.java.deploy.impl.VertxLocator;
public class PromiseTests {
private Object lock = new Object();
@jewelsea
jewelsea / FruitComboController.java
Created December 12, 2012 10:33
JRuby + JavaFX with FXML demonstration
package org.jewelsea.examples.jruby.fruit;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
/** JavaFX fxml controller for fruit combo fxml demo application. */
public class FruitComboController {

Basic Strategy

Take a match block and add routes to a RouteRecognizer:

match("/posts").to("posts", function(match) {
  match("/").to("postIndex")
  match("/:id").to("showPost");
  match("/edit").to("editPost");
@thehydroimpulse
thehydroimpulse / package.coffee
Created November 30, 2012 02:49
Tower Package Example
# Register a new package:
Tower.Package.register ->
# Require some core modules:
fs = require("fs")
path = require("path")
# Add information to the package.
@info
name: "Auth"
@ryanb
ryanb / issues_with_modules.md
Created November 29, 2012 22:38
Points on how modules can make code difficult to read.

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article < ActiveRecord::Base
@max-mapper
max-mapper / helloworld.js
Created November 27, 2012 06:55
droneduino
var serialport = require('node-serialport')
var sp = new serialport.SerialPort("/dev/ttyO3", {
parser: serialport.parsers.raw,
baud: 9600
})
sp.on('data', function(chunk) {
console.log(chunk.toString('hex'), chunk.toString(), chunk)
})
# Original version is here: https://gist.github.com/1358093
require 'jrubyfx'
require 'jrubyfx/dsl'
class AnalogClock
include JRubyFX
include JRubyFX::DSL
def start(stage)
@ehaliewicz
ehaliewicz / flip-flop.lisp
Last active October 12, 2015 08:27
A flip-flop operator for lisp
(defmacro flip-flop (left right)
"Evaluates to false until the left test is satisfied. Then evaluates to true until the right test is satisfied, etc."
;; create a collision-safe name for our state variable
(let ((state-var (gensym)))
;; create a toplevel variable to keep state of flip-flop
`(progn
(defvar ,state-var nil))
@doublerebel
doublerebel / example.js
Created October 11, 2012 17:55
How to get Titanium Mobile API autocomplete with CoffeeScript in Sublime Text 2
/* Step 1:
** Place (only one) Titanium API lib (from jsca2js package) in:
** /path/to/project_root/.codeintel/libs
*/
/* Step 2:
** Create text file: /path/to/project_root/.codeintel/config
*/
{
"JavaScript": {