Skip to content

Instantly share code, notes, and snippets.

async function track (msg) {
return Promise.resolve(foo) // intentially triggering ReferenceError for undefined `foo`
}
async function process (msg, done) {
try {
const res = await track(msg)
return done(null, res)
} catch (e) {
@ccnixon
ccnixon / process.js
Last active September 20, 2017 20:12
async function track (msg) {
return Promise.resolve(foo) // intentially triggering ReferenceError for undefined `foo`
}
function process (msg, done) {
try {
track(msg).then(res => done(null, reqs)).catch(err => done(err, reqs))
} catch (e) {
err.code = 'INTERNAL'
@ccnixon
ccnixon / fake_segment.py
Created January 24, 2017 16:24
Fake data generator for Segment.com
import analytics
import uuid
import random as r
import time
import fixtures
from faker import Faker
fake = Faker()
analytics.write_key = "CaobGxGZFxAA2UEwfgk8z9OaImSYkPJo"
user_agent_list = ['Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; FSL 7.0.6.01001)','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; FSL 7.0.7.01001)','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; FSL 7.0.5.01003)','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0','Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.8) Gecko/20100723 Ubuntu/10.04 (lucid) Firefox/3.6.8','Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20100101 Firefox/13.0.1','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0','Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.8) Gecko/20100723 Ubuntu/10.04 (lucid) Firefox/3.6.8','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)','Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20100101 Firefox/13.0.1','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/201
@ccnixon
ccnixon / prompt.go
Created December 8, 2016 01:22
Simple Go Command Line prompt
package main
import (
"bufio"
"fmt"
"os"
)
const PROMPT = "go>> "
@ccnixon
ccnixon / balanced_parens.js
Created December 5, 2016 17:22
Balanced Parens
var test = '{[()]}';
function balancedParens(str) {
var parens = {
'{': '}',
'[': ']',
'(': ')'
}
var stack = []
for (var i = 0; i < str.length; i++) {
@ccnixon
ccnixon / merge_sorted.rb
Created November 16, 2016 18:39
Merge two sorted arrays using Ruby in O(n) time
a = [3, 4, 6, 10, 11, 15]
b = [1, 5, 8, 12, 14, 19]
# plan is to create a pipeline and solve using recursion
# going to crunch through each array, testing at each iteration to see
# which value at index 0 of either array is lower, removing that from the array
# and appending that value to the result array.
#
# Finally, check to see if either array is empty
# If so, just going to append the remaining array to the end of the result
@ccnixon
ccnixon / 0_reuse_code.js
Created September 27, 2016 15:44
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ccnixon
ccnixon / middleware.js
Created September 16, 2016 16:32
Segment.com server side page call with Express
import express from 'express'
import Analytics from 'analytics-node'
import { stringify } from 'qs'
const app = express()
const analytics = new Analytics('write-key')
app.use((req, res, next) => {
const { query, cookies, url, path, ip, host } = req
@ccnixon
ccnixon / getParam.js
Created September 14, 2016 22:41
Get and store a specific URL query param
<script type="text/javascript">
function setCookie(name, value, days){
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
var expires = "; expires=" + date.toGMTString();
document.cookie = name + "=" + value + expires + ";path=/";
}
function getParam(p){
var match = RegExp('[?&]' + p + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
@ccnixon
ccnixon / binary_search.c
Created August 5, 2016 05:41
binary search program in c
int binary_search(int value, int values[], int min, int max)
{
if (max < min)
{
return -1;
}
int midpoint = (min + max) / 2;
if (values[midpoint] < value)
{
return binary_search(value, values, midpoint + 1, max);