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
typedef void (^myblock)();
myblock[10] makeblocks()
{
__block double foo;
myblock[10] = malloc(sizeof(myblock) * 10);
for (int i = 0; i<10; ++i) {
myblock[i] = Block_copy(^{
foo = foo + 1;
//
// core_main.c
// love
//
// Created by Erich Ocean on 11/10/10.
// Copyright (c) 2010 __MyCompanyName__. All rights reserved.
//
#include "core.h"
#include <Block.h>
@erichocean
erichocean / gist:673484
Created November 12, 2010 00:09
Coding with Erich's SproutCore-style C application framework.
//
// core_main.c
// FOHR
//
// Created by Erich Ocean on 11/10/10.
// Copyright (c) 2010 Erich Atlas Ocean. All rights reserved.
//
#include "core.h"
#include <string.h> // strcmp
@erichocean
erichocean / gist:741440
Created December 15, 2010 00:58
proof-of-concept: allows you to write <key>Update: functions instead of putting all your code inside update()
// Add this to your custom view or render delegate (see comment below for the rest).
update: function(jquery) {
var fn, key, displayProperties = this.getChangedDisplayProperties() ;
for (key in displayProperties) {
if (!displayProperties.hasOwnProperty(key)) continue ;
if (fn = this[key+'Update']) fn.call(this, jquery, displayProperties[key]) ;
}
}
sc_require('controllers/mailboxes');
sc_require('controllers/messages');
SC.mixin(OI, {
registerStatechartObservers: function() {
var fun = this.folderSelectionDidChange ;
OI.foldersController.addObserver('selection', this, fun) ;
this.__mailboxesControllers__ = {} ;
@erichocean
erichocean / gist:745609
Created December 17, 2010 20:04
query-based to many relationship
messages: SC.RecordAttribute.create({
toType: function(record, key, value) {
var ary = record._messages ;
if (!ary) {
console.log('creating a messages query for Mailbox[%@]'.fmt(record.get('guid')));
CoreOI.Record.messages++ ;
ary = record._messages = record.get('store').findAll(SC.Query.create({
recordType: 'CoreOI.Message',
conditions: "mailbox = %@",
parameters: [record],
@erichocean
erichocean / gist:765713
Created January 5, 2011 00:26
SC.Binding.all
// Add Bindings
this.bindings = []; // will be filled in by the bind() method.
if (keys = this._bindings) {
for(loc=0, keysLen = keys.length; loc < keysLen;loc++) {
// get propertyKey
key = keys[loc] ; value = this[key] ;
propertyKey = key.slice(0,-7) ; // contentBinding => content
this[key] = this.bind(propertyKey, value) ;
}
}
@erichocean
erichocean / BUILD
Created January 5, 2011 02:12
fast sproutcore building
# An ordered list of files in ../src that are concatenated to produce hub.js,
# one file per line. Lines beginning with # are skipped. On node.js, the
# index.js file uses the contents of this file to assemble hub.js dynamically
# during development.
#
# To generate a custom build of hub.js, modify this BUILD file to include the
# list of files you need/want in the correct order.
#
# NOTE: In a production build, lines matching /^development[/].*/ will be
# skipped, and calls to hub_assert(), hub_precondition(), hub_postconditon(),
@erichocean
erichocean / strip_assertions.js
Created January 5, 2011 05:01
removes hub_assert() and friends from the parse tree and outputs the results
// ==========================================================================
// Project: hub.js - cloud-friendly object graph sync
// Copyright: ©2010 Erich Ocean.
// Portions ©2006-2009 Sprout Systems, Inc. and contributors.
// Portions ©2008-2009 Apple Inc. All rights reserved.
// License: Licensed under an MIT license (see license.js).
// ==========================================================================
function Program(str){
var tbl=[],pos=0,l=str.length+1;while(l--)tbl.push([]);l=str.length;
@erichocean
erichocean / peg.js
Created January 5, 2011 05:03
PEG grammar output for ECMAScript_unified.peg
/* PEG → JavaScript parser generator, with its dependencies.
* See http://inimino.org/~inimino/blog/peg_first_release */
var sys = require('sys') ;
;(function(exports){
exports.generateParser=generateParser
exports.generateParserThrowing=generateParserThrowing