Skip to content

Instantly share code, notes, and snippets.

View treygriffith's full-sized avatar

Trey Griffith treygriffith

View GitHub Profile
@treygriffith
treygriffith / forever.js
Created July 25, 2012 17:50
Auto-restart Nodejs server and notify Airbrake
// Auto-restart Nodejs server a few times so a random error doesn't kill everything
var forever = require('forever-monitor');
// set up airbrake for notifications when the server dies
var airbrake = require('airbrake').createClient("CLIENT_ID");
var server = new (forever.Monitor)('server.js', {
max: 5,
silent: false,
@treygriffith
treygriffith / gist:4599048
Created January 22, 2013 22:12
Demonstrate behavior of MongoDB $in on primitive properties
toy1 = {
color: 'red'
};
toy2 = {
color: 'pink'
}
Toys.find({color: { $in: ['red', 'green', 'blue'] }}, cb);
// finds toy1, but not toy2
@treygriffith
treygriffith / gist:4599072
Created January 22, 2013 22:14
Demonstrate behavior of MongoDB $in on Array properties
toy1 = {
color: ['red', 'purple']
};
toy2 = {
color: ['pink', 'orange']
}
Toys.find({color: { $in: ['red', 'green', 'blue'] }}, cb);
// finds toy1, but not toy2
@treygriffith
treygriffith / immutable_dict.py
Created October 18, 2014 18:44
An Immutable Dictionary in python - a tuple with real keys
class ImmutableDict:
"""A tuple with non-index keys"""
def __init__(self, dict):
self._keys = tuple(dict.keys())
self._values = tuple(dict.values())
def __len__(self):
return len(self._keys)
@treygriffith
treygriffith / application_serializer.js.coffee
Last active August 29, 2015 14:09
Async Polymorphic BelongsTo Fix in Ember
Teleborder.ApplicationSerializer = DS.ActiveModelSerializer.extend
serializePolymorphicType: (record, json, relationship) ->
key = relationship.key
belongsTo = record.get(key)
jsonKey = "#{key}_type".underscore()
if relationship.options.async
belongsTo = belongsTo.content
if Ember.isNone(belongsTo)
@treygriffith
treygriffith / sample_async_belongsto_save.js.coffee
Created November 11, 2014 02:51
Saving an Ember record with an async belongsTo relationship
comment = @store.createRecord('comment', {
author: @get('currentUser')
# snip
})
comment.get('author').then ->
# comment.author is now resolved, safe to save
comment.save()

Keybase proof

I hereby claim:

  • I am treygriffith on github.
  • I am tgriff3 (https://keybase.io/tgriff3) on keybase.
  • I have a public key ASCPR31q17gz3kciMUmPWdACY4WRSmMXIw1w3LooYDurvwo

To claim this, I am signing this object:

@treygriffith
treygriffith / Dockerfile
Created August 13, 2020 03:35
Dockerfile for building a release for Amazon Linux on EC2
# Building an Phoenix (Elixir) Release targeting Amazon Linux for EC2
# By https://github.com/treygriffith
# Original by the Phoenix team: https://hexdocs.pm/phoenix/releases.html#containers
#
# Note: Build context should be the application root
# Build Args:
# OTP_VERSION - the OTP version to target, like 23.0
# ELIXIR_VERSION - the Elixir version to target, like 1.10.4
#
# If you have other environment variables in config/prod.secret.exs, add them as `ARG`s in this file
@treygriffith
treygriffith / xkit-catalog-react.tsx
Created January 29, 2021 22:14
Using the Xkit Embedded Catalog with React
import * as React from 'react'
import * as ReactDOM from 'react-dom'
interface IntegrationsProps {
path?: string
}
class Integrations extends React.Component<IntegrationsProps> {
private ref = React.createRef()
import * as React from 'react'
import createXkit from '@xkit-co/xkit-catalog.js'
const xkit = createXkit('viable.xkit.co')
interface IntegrationsProps {
path?: string
}
class Integrations extends React.Component<IntegrationsProps> {