Skip to content

Instantly share code, notes, and snippets.

View foxnewsnetwork's full-sized avatar

Thomas Chen foxnewsnetwork

View GitHub Profile
@foxnewsnetwork
foxnewsnetwork / gist:0eee1fc5602a162b81c4
Created December 2, 2014 06:07
basic resque 2.0.0.pre.1 usage

Resque is great, but the README.md on github (as of 12/1/2014) continues to cause butthurt to folks who are trying to setup resque.

The current README (wrongly) states:

To define some work, make a job. Jobs need a work method:

class ImageConversionJob
  def work
 # convert some kind of image here
@foxnewsnetwork
foxnewsnetwork / component-store.coffee
Created January 22, 2015 16:42
Emberjs initializer to get the store in your components
initialize = (ctn, app) ->
app.inject "component", "store", "store:main"
ComponentStoreInitializer =
name: 'component-store'
initialize: initialize
# Then, wherever you're creating your app, do the following:
Ember.Application.initializer ComponentStoreInitializer
Just watched Lucy (2014)
Plot TL;DR: Koreans invent a drug that, if taken, makes someone God. They then attempt to smuggle and sell said drug and are surprised when Lucy takes the drug, becomes God, and turns the tables on them.
@foxnewsnetwork
foxnewsnetwork / gist:a87092819f8d268f2ab3
Created March 23, 2015 19:01
Ember data models in nested dir

Often, in big Ember projects where you have a lot of models, it makes sense to put model files into their own directories.

For example, instead of:

app
  -- models
    -- dog.js
    -- cat.js
 -- bat.js
@foxnewsnetwork
foxnewsnetwork / gist:d4c1dbbbbf1e1f40e2e7
Created May 4, 2015 05:49
Ember js cross domain adapter configuration

The problem

Using a heavy front-end framework like EmberJS and separate api services from joints like imgur, twitter, tumblr, github, etc., makes it possible to host a rich-feature website statically... but the horrid obstacle of the browser's Access-Control header (CORS) stands in your way:

XMLHttpRequest cannot load http://api.service.co/freedb. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://foxnewsnetwork.github.io' is therefore not allowed access. 

The Why

@foxnewsnetwork
foxnewsnetwork / gist:727f47e6bb480390e98d
Created May 15, 2015 23:18
EmberJS controller promise state

The Problem

I use EmberJS a lot in my day-to-day work, and one of the things I find myself constantly doing is writing acceptance tests (aka integration tests) that click through my application to ensure the various planned out user workflows are operating as expected.

However, because controller must handle user interaction and map that to necessarily async ajax (or websocket) calls, EmberJS's standard suite of acceptance test helpers are sometimes not enough to ensure proper waiting.

For example:

Suppose I have a very complex DS.Model which, at creation, must not only create itself in my rails back-end via ajax, but also communicate to a firebase server somewhere using websockets.

@foxnewsnetwork
foxnewsnetwork / gist:622810064e340fd73ed4
Created May 19, 2015 18:49
Switching to Elixir Ecto from rails activerecord and dealing with timestamps

TL;DR, ActiveRecord's timestamps macro creates :created_at and :updated_at but Ecto's timestamps creates :inserted_at and :updated_at. If you already have a database setup and now want to switch from ActiveRecord rails to Ecto Elixir, you'll no doubt run into the following error:

(1054): Unknown column 'a0.inserted_at' in 'field list'

You can resolve this by going into your model file and making the following edit:

# models/appointments.ex
defmodule Appointment do
@foxnewsnetwork
foxnewsnetwork / gist:3675adbf20b744fc6cf3
Created May 20, 2015 18:40
d3 element click events not working

The Problem

You're using the d3 library, and you do something like the following:

.enter()
.append "rect"
.attr "fill", "none"
.attr "stroke", "black"
... # other stuff
@foxnewsnetwork
foxnewsnetwork / exposition.markdown
Last active August 29, 2015 14:21
Complex Front End Data Models in Emberjs

The Motivation

EmberJS is a full-featured front-end javascript framework for building (as they put it) ambitious apps. Being ambitious, I wanted to build an app that had data models that were queryable like those of SQL, realtime like it was on Websockets, I wanted to do it without building my own customized REST-over-websockets-on-Elixir server stack. Why would I want to do this? Mostly because so many cuts on the server-side reduces devops costs (to 0) and allows me to piggyback on the extremely well-staffed architecture that runs places like Github and Google (so I don't have to ever worry computer-level details like disk IO rate, server RAM, database backup, SSL, geographic distribution, etc.; all of that I would get for free).

TL;DR: so I can build a globally scalable app that I can maintain just by myself (because there is no maintainence)

The Problem

Using Javascript to do heavy client-side data-management means I am either condemned to Calback Hell or (since it's 2015), Promise Monad Hell (y

@foxnewsnetwork
foxnewsnetwork / query.ex
Created August 5, 2015 01:57
Postgres order_by select count column missing group_by
bad_query = from a in Appointment,
where: is_nil(a.deleted_at),
order_by: [desc: a.expected_at],
select: count(a.id)
good_query = from a in Appointment,
where: is_nil(a.deleted_at),
select: count(a.id)
Repo.one bad_query # throws ** (Postgrex.Error) ERROR (grouping_error): column "a0.expected_at" must appear in the GROUP BY clause or be used in an aggregate function