Skip to content

Instantly share code, notes, and snippets.

// for node.js
if(typeof require == 'function') {
var load = require;
}
load('../reflect.js');
var RCVR = null;
function test() {
def foo
bar = "bar"
arr = [1, 2, 3]
arr.map {|a|
fizz = "buzz" + a.to_s
# this line is fine, blocks can access the enclosing scope
print bar + "\n"
}
# this throws, fizz is only defined within the local block
print fizz
@polotek
polotek / device.js
Created May 11, 2012 05:27 — forked from rwaldron/device.js
Fat Arrows and Classes-as-Prototype-sugar make a beautiful future for JavaScript
var stream = require("fake-stream-lib"),
Emitter = require("events").EventEmitter,
util = require("util");
// Today...
function Device( opts ) {
this.value = null;
@events =
events: {}
on: (topic, handler, context = this) ->
(@events[topic] or= []).push {handler, context}
trigger: (topic, args...) ->
return unless @events[topic]?
handler.apply(context, args) for {handler, context} in @events[topic]
@polotek
polotek / oojs.md
Created May 5, 2012 00:50
Some thoughts on inheritance and capability checking in js.

I promised some people I would write a little about my ideas on inheritance in js. This is a code snippet from my procstreams lib. https://github.com/polotek/procstreams/blob/chain-state/procstreams.js#L132-145

// this is a process object
if((cmd === process || typeof cmd.spawn == 'function')) {
  // this is already a procstream
  if(procStream.is(cmd)) {
    cmd.on('exit', callback);
    return cmd;
 } else {
./configure --debug --gdb --shared-v8 --shared-v8-libpath="deps/v8" --shared-v8-includes="deps/v8/src"
New blog
* Markdown
* distraction*free writing
* better way to manage data?
* Auto-saving
* substance.io?
* code samples
* upload and insert assets
Javascript
* proxies
@polotek
polotek / HTTPClient.js
Created April 22, 2012 03:37
A node http client that adds things like retry behavior
var request = require('request')
, retry = require('retry')
, httpLog = log4js.getLogger('httpLog');
var HTTPClient = {
defaultOpts: {
, request: {
headers: {
Host: 'paddie'
, 'Content-Type': 'application/javascript'
@polotek
polotek / post.md
Created April 12, 2012 05:51
Thoughts on how we evaluate javascript proposals

I promised some people that I would talk a little about my feelings on ECMAScript proposals. I love javascript as a language. Sure, it has lots of warts, some that aren't easily dismissed. But it also has some really nice constructs that allow for elegant code solutions. My preference for javascript is purely subjective, and I don't mind admitting that. But being that I'm a staunch supporter of the language and the community, I'm also pretty opinionated about where it's going. These are just some of my concerns.

Change is good

I should start by saying that I'm not against progress. Whenever I argue with people about javascript proposals, I always get the eventual argument that we have to move javascript forward and we can't be afraid of change. I want to go on the record as saying I want upgrades to javascript. But I don't think progress is a reason not to challenge ideas that I think are not fully formed or potentially problematic. This tension is good, because it keeps the standards makers on their toe

@polotek
polotek / benchCallbacks.js
Created April 12, 2012 00:24 — forked from bjouhier/benchCallbacks.js
streamline vs. callbacks bench
"use strict";
var fs = require('fs');
var cache = {}, hit = 0, missed = 0;
function load(name, cb) {
var res = cache[name];
if (res) {
process.nextTick(function() {
hit++;
cb(null, res);