Skip to content

Instantly share code, notes, and snippets.

View samuraisam's full-sized avatar

Samuel Sutch samuraisam

View GitHub Profile
### Keybase proof
I hereby claim:
* I am samuraisam on github.
* I am ssutch (https://keybase.io/ssutch) on keybase.
* I have a public key whose fingerprint is CB73 AA67 8197 4715 8413 0169 52F3 85BF 58A0 3967
To claim this, I am signing this object:
constant CURDIR = IO::Spec.splitpath($?FILE)[1];
constant FN = IO::Spec.catdir(CURDIR, 'Proto', 'ql2_13x.proto');
module RethinkDB::Proto {
# classes are generated here
use PB::Model::Generator FN;
}
BEGIN {
for RethinkDB::Proto::.kv -> \sym, \obj {
my $fn = IO::Spec.catdir($?FILE, 'Proto', 'ql2_13x.proto');
use PB::Model::Generator $fn;
# => No such method 'IO' for invocant of type 'Any'
@samuraisam
samuraisam / builder.py
Created June 16, 2014 16:13
Python: Fluent Builder Pattern
class ObjectPermissions(object):
perms_map = {}
specific_object_perms = ()
@classmethod
def require(cls, *new_perms):
class SpecificObjectPermissions(cls):
specific_object_perms = new_perms
return SpecificObjectPermissions
@samuraisam
samuraisam / dyn-form-field.js
Created May 11, 2014 18:44
Dynamic component
var elementMap = {
'char': 'dyn-text-field'
};
var DynamicFormField = Ember.Component.extend({
template: Ember.computed('entry.field', function(key, value) {
var kind = this.get('entry.field.kind');
var helperName = elementMap[kind] || 'dyn-text-field';
var tmpl = '{{' + helperName + ' entry=entry}}';
return Ember.Handlebars.compile(tmpl);
var MyRoute = Ember.Route.extend({
model: function() {
// this will resolve
return Ember.$.ajax().then(function(data) {
// then this will resolve
return Ember.RSVP.Promise.all([
Ember.$.ajax({url: data.item1url}),
Ember.$.ajax({url: data.item2url})
]).then(function(items) {
// and this will be your model in the controller
function extractEmbeddedData(obj, propertyName, store, persistedName) {
var ids = [];
var embeddedObjs = [];
if (!Ember.isNone(obj[propertyName])) {
var subObj = obj[propertyName];
var isArray = Array.isArray(subObj);
if (!isArray) {
subObj = [subObj];
}
subObj.forEach(function(subElement) {
// generalize some of the embedded extraction. transforms merchant.locations into ids and returns a list of locations
function extractEmbeddedData(obj, propertyName) {
var ids = [];
var embeddedObjs = [];
if (!Ember.isNone(obj[propertyName])) {
var subObj = obj[propertyName];
var isArray = Array.isArray(subObj);
if (!isArray) {
subObj = [subObj];
}
//
// ManagedObject.h
//
// Created by Samuel Sutch on 10/21/13.
// Copyright (c) 2013 Steamboat Labs. All rights reserved.
//
#import <CoreData/CoreData.h>
#import <AFNetworking/AFNetworking.h>
#import <JSONKit.h>
@samuraisam
samuraisam / main.m
Created September 30, 2013 03:55
Testing out some different serialization libraries.
//
// main.m
// mdb-bench
//
// Created by Samuel Sutch on 9/29/13.
// Copyright (c) 2013 Steamboat Labs. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <JSONKit/JSONKit.h>