Skip to content

Instantly share code, notes, and snippets.

View erichocean's full-sized avatar

Erich Ocean erichocean

  • Xy Group Ltd
  • North Carolina
View GitHub Profile
; The entire ECMAScript grammar expressed as a single PEG
; Parser rules which share a name with ECMA-262 productions are intended to match the same language.
Program ←
(S? (Statement / FunctionDeclaration))* S?
FunctionBody ←
(S? (Statement / FunctionDeclaration))* S?
@erichocean
erichocean / peg_gen.js
Created January 5, 2011 05:06
How I converted the PEG grammar into source code (which I then modified)
var peg = require('./peg') ;
var sys = require('sys') ;
var posix = require('posix') ;
posix.cat("./ECMAScript_jsdoc.peg").addCallback(function (grammar) {
var parser = peg.generateParser(grammar) ;
sys.puts(parser) ;
});
@erichocean
erichocean / view_controller.js
Created January 13, 2011 18:37
How to do view controllers in SC
MyApp.menuPane.statechart: SC.Statechart.create({
});
MyApp.myPage = SC.Page.design({
menuPane: SC.Pane.design({
// give CoreOI.Server time to load...
SC.ready(function() {
CoreOI.store = SC.Store.create().from(CoreOI.Server.create()) ;
});
@erichocean
erichocean / dag_query.js
Created January 17, 2011 20:33
How to create a DAG of nested queries
var query1 = SC.Query.create( /** omitted */ );
var query2 = SC.Query.create( /** omitted */ );
var joinQuery = SC.Query.create(
// omitted
).from(query1, query2);
valueBinding: SC.Binding.transform(function(value, binding) {
return "how many: %@" .fmt(value);
}).from('MyApp.arrayController.length')
fooBinding: 'MyApp.controller.name',
barBinding: 'MyApp.aryController.length',
value: function() {
return "The array named %@ has length %@".fmt(this.get('foo'), this.get('bar'));
}.property('foo', 'bar').cacheable()
@erichocean
erichocean / cocoa_sc.m
Created January 19, 2011 00:24
SproutCore-style page definition in Cocoa with Core Animation layers.
//
// MainWindow.objc
// PhotoBooth
//
// Copyright 2008 Erich Atlas Ocean. All rights reserved.
//
sc_require( "PhotoBooth" );
@synchronized( PB ) {
contentView: OI.MailboxSourceView.design({
layerId: 'mailbox-list',
classNames: 'mailbox-list'.w(),
// delegate: 'OI*mailboxesController',
contentValueKey: 'name',
contentUnreadCountKey: 'unreadCount',
contentBinding: 'OI*mailboxesController.arrangedObjects',
selectionBinding: 'OI*mailboxesController.selection',
selectOnMouseDown: YES,
acceptsFirstResponder: YES,
@erichocean
erichocean / custom_binding.js
Created January 20, 2011 18:56
How to transform the status property of a content object for use by a view.
valueBinding: SC.Binding.transform(function(value, binding) {
if (value === SC.Record.READY_DIRTY ||
value === SC.Record.READY_NEW) {
return YES;
} else return NO;
}).from('Todos.taskController.status')