Skip to content

Instantly share code, notes, and snippets.

@danscan
danscan / logs.md
Last active August 29, 2015 14:18
Connect-redis sails crash logs w/ NODE_DEBUG=net

Crash / process exit at the bottom.

Apr 07 22:32:50 ip-10-21-1-100.ec2.internal sh[7031]: Tue, 07 Apr 2015 22:32:49 GMT compression size below threshold
Apr 07 22:32:50 ip-10-21-1-100.ec2.internal sh[7031]: Tue, 07 Apr 2015 22:32:49 GMT compression no compression
Apr 07 22:32:50 ip-10-21-1-100.ec2.internal sh[7031]: Tue, 07 Apr 2015 22:32:49 GMT connect:redis SETEX "sess:h9C9rNrB2VlWjSsiw7dBbHxzTZMMA3ka" ttl:31535999 {"cookie":{"originalMaxAge":31535999998,"expires":"2016-04-06T22:32:49.971Z","httpOnly":true,"path":"/"},"user":"550b26dd80fd0a07009a658f"}
Apr 07 22:32:50 ip-10-21-1-100.ec2.internal sh[7031]: NET 6: onread -4095
Apr 07 22:32:50 ip-10-21-1-100.ec2.internal sh[7031]: NET 6: EOF
Apr 07 22:32:50 ip-10-21-1-100.ec2.internal sh[7031]: NET 6: onSocketEnd { objectMode: false,
Apr 07 22:32:50 ip-10-21-1-100.ec2.internal sh[7031]: highWaterMark: 16384,
@danscan
danscan / PointSequence.swift
Created June 8, 2015 14:29
PointSequence.swift
//
// PointSequence.swift
// ThoughtPad
//
// Created by Daniel Scanlon on 6/5/15.
// Copyright (c) 2015 Present. All rights reserved.
//
import UIKit
@danscan
danscan / nav.md
Created June 25, 2015 00:55
Modeling navigation in React Native

Router Nav

# (Not REST... Pages/Views (like a website)) ... or maybe resourceful with scaffolding
* * *

/ -> session.user ? /activity : /authenticate

# Main Nav
/activity
@danscan
danscan / index.js
Created August 30, 2015 21:16
Animated Bar
import React from 'react-native'
const { Animated, View } = React
import styles from './styles'
// Configuration Constants
const INITIAL_VALUE_SCALE = 0
const DESTINATION_VALUE_SCALE = 1
const VALUE_SCALE_SPRING_FRICTION = 5
export default class Bar extends React.Component {
@danscan
danscan / idea.js
Created September 3, 2015 20:43
Safely expressing schema remapping in legacy APIs as append-only write streams.
// Writes: Append-Only Stream
{ operation: 'write', key: 'users.e36a7c158ee2a92143967b7a860f4ea5.first_name', value: 'Dan', date: 'yesterday', clientVersion: 'yesterday' }
{ operation: 'write', key: 'users.e36a7c158ee2a92143967b7a860f4ea5.first_name', value: 'Daniel', date: 'yesterday', clientVersion: 'yesterday' }
{ operation: 'write', key: 'users.e36a7c158ee2a92143967b7a860f4ea5.first_name', value: 'Daniel', date: 'yesterday', clientVersion: 'yesterday' }
{ operation: 'rename key', key: 'users.*.first_name', name: 'users.*.firstName', date: 'today' }
{ operation: 'write', key: 'users.e36a7c158ee2a92143967b7a860f4ea5.first_name', value: 'Esteban', date: 'today', clientVersion: 'yesterday' }
{ operation: 'write', key: 'users.e36a7c158ee2a92143967b7a860f4ea5.first_name', value: 'Justin', date: 'today', clientVersion: 'today' }
// Present-Time value of `users.e36a7c158ee2a92143967b7a860f4ea5`
{ firstName: 'Esteban', first_name: 'Justin' }
@danscan
danscan / .babelrc
Last active November 18, 2015 20:32
react-native-charts example .babelrc
{
"retainLines": true,
"compact": true,
"comments": false,
"stage": 1,
"whitelist": [
"es6.arrowFunctions",
"es6.blockScoping",
"es6.classes",
"es6.destructuring",
@danscan
danscan / deepProperties.js
Created October 12, 2013 07:23
I was looking for a short, simple way to set and get deep properties in a single line in javascript, and after not finding anything I decided to see how short I could make these methods. Enjoy.
// Set deep property
function setProperty(p,v){p=p.split('.'),i=0,w=("string"===typeof v?'"'+v+'"':v);while(p[i])eval(p.slice(0,++i).join('.')+'='+(p[i]?"{}":w));return v}
// Example
setProperty('some.really.deep.property', 'now exists'); // "now exists"
// Get deep property
function getProperty(p){p=p.split('.'),v=this;while(p[0]&&v){v=v[p.shift()]}return v}
// Example
getProperty('some.really.deep.property'); // "now exists"
@danscan
danscan / gist:7537577
Created November 18, 2013 23:56
My dream-code (just an idea) for how video append request failure can be handled.

Post Sequence

A dream-class that handles sequential-request streaming.

Features

  • POSTs multipart request bodies
  • Caches all requests
  • Failed request are retried immediately within a specified time window
  • If >10% of requests fail during the stream, the entire post sequence is cached for later retry under conditions of greater reliability.
@danscan
danscan / TimedFunction.js
Last active January 4, 2016 06:39
A simple way to execute a function with a time limit and an isolated context – useful for maintaining resource availability on platforms that allow multiple HTTP APIs to share infrastructure.
(function generateContext() {
var _startTime = Date.now(),
_timeout = 10000,
_timedOut = false,
_finish = function(error) {
clearTimeout(_timeoutTimeout);
_endTime = Date.now();
_totalExecutionTime = _endTime - _startTime;
@danscan
danscan / policy.js
Created January 25, 2016 16:55
Policy function
const db = {
usersBySessionToken: {
'1': {
id: 1,
name: 'Dan',
},
},
postsById: {
'2': {