Skip to content

Instantly share code, notes, and snippets.

View dallonf's full-sized avatar

Dallon Feldner dallonf

View GitHub Profile
@dallonf
dallonf / gist:3900008
Created October 16, 2012 15:32
Relationships in Deployd
// On GET /users
// Get all the todos that this user owns
if (query.includeTodos) { // Always make something like this a custom query; otherwise it's easy to bog down your server with unnecessary db calls
dpd.todos.get({userId: this.id}, function(res, err) { // Assuming that the userId property of a todo is set when you create it
this.todos = res;
});
}
@dallonf
dallonf / route-event.js
Created October 15, 2012 15:21
Route Event resource
var Resource = require('deployd/lib/resource')
, Script = require('deployd/lib/script')
, util = require('util');
function RouteEvent() {
Resource.apply(this, arguments);
}
util.inherits(RouteEvent, Resource);
RouteEvent.label = "Route Event";
@dallonf
dallonf / gist:3827586
Created October 3, 2012 15:30
AwaitScript concept
require 'fs';
require 'path';
// Check recursively if any files from this directory have been modified since a certain date
async function isRecentlyModified(dir, since) {
var files;
try {
files = await fs.readdir(dir);
} catch (ex) {
console.error("Warning: " + dir + " does not exist")
@dallonf
dallonf / get-departments.js
Created September 27, 2012 16:13
Managing groups with events
// departments has string parentId, string name
// On GET /departments
if (this.parentId) {
// Recursively build an array of parents
dpd.departments.get({id: parentId, $limitRecursion: 64}, function(parentDep) {
if (parentDep) {
this.parents = [parentDep.name];
if (parentDep.parents) {
this.parents = parentDep.parents.concat(this.parents);
}
@dallonf
dallonf / index.html
Created October 6, 2015 21:11
React can't render SVG under PhantomJS
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<svg id="svgRoot">
<g id="gElement">
</g>
declare module 'co' {
interface ICoStatic {
<T>(coroutine: () => IterableIterator<any>): Promise<T>
wrap<T>(coroutine: (...args: any[]) => IterableIterator<Promise<any>>): (...args: any[]) => Promise<T>
}
var co: ICoStatic;
export default co;
}
@dallonf
dallonf / index.html
Created October 14, 2011 14:38
Facebook Photo Selector with Knockout.js
<!DOCTYPE html>
<html>
<head>
<title>Knockout Demo</title>
<script type="text/javascript" src="jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="jquery.tmpl.js"></script>
<script type="text/javascript" src="knockout.js"></script>
<style type="text/css">
.selected {
border: #FFFF00 3px solid;
@dallonf
dallonf / jsonify-bootstrap.js
Created August 4, 2015 16:01
Experiment: render Bootstrap variables to JSON file
let fs = require('fs');
let path = require('path');
let less = require('less');
let bluebird = require('bluebird');
let css = require('css');
async function execute() {
let variablesLess = await bluebird.fromNode(cb => fs.readFile(path.join(__dirname, 'less/variables.less'), 'utf-8', cb));
let [parseResult] = await bluebird.fromNode(cb => less.parse(variablesLess, cb));
let varNames = parseResult.rules
@dallonf
dallonf / gist:3f365373ae971d278706
Created May 1, 2015 17:26
React FloatingElement
var FloatingElement = React.createClass({
propTypes: {
children: React.PropTypes.element.isRequired,
floatingClassName: React.PropTypes.string
},
getDefaultProps() {
return {
floatingClassName: 'floating'