Skip to content

Instantly share code, notes, and snippets.

View jasonblanchard's full-sized avatar

Jason jasonblanchard

View GitHub Profile
@jasonblanchard
jasonblanchard / gist:7487826
Last active December 28, 2015 10:39
Factory Girl Mongoid Associations
# This doesn't actually update the user.thing.user_id field.
factory :user_with_a_thing, class User do
association :thing, Factory :thing
end
# So later, a call to user.thing will return nil
# of if you inspect Thing.last, its user_id field will be nil
# This seems to persist it
factory :user_with_a_thing, class User do
@jasonblanchard
jasonblanchard / ActiveRecord relations
Last active December 30, 2015 12:29
Sensor data sent to rails server
class Site
has_many nodes
has_many node_readings, :through => nodes
end
class Node
belongs_to site
has_many node_readings
end
def new
@garment = Garment.new(params[:id])
@garment.save
if ImageSaver.new(@garment).save_garment_with_image
respond_to do |format|
format.html
end
end
end
def in_production?
if Rails.env.production?
yield
end
end
@jasonblanchard
jasonblanchard / .irbrc
Last active August 29, 2015 13:56
show mongoid queries in rails console
if defined? Mongoid
Mongoid.logger = Logger.new($stdout)
end
@jasonblanchard
jasonblanchard / get-meets
Last active August 29, 2015 13:57
GET [root-api-url]/org/:org_id/meets
{
"meets":
[
{
"id": "5321a679374c100b81000019",
"created_at": "2014-01-07 19:54:28 +0000",
"name": "Assignment #1",
"description": "adf asdfasdfasdfasdf",
"summary": "ad asdf asdf asdf asdf asdf ......",
"status_description": "Submit Now",
@jasonblanchard
jasonblanchard / post-submission-response
Last active August 29, 2015 13:57
POST [root-api-url]/meet/:id/subimssions
{
"submission": {
"id": '5321a6f6374c100b81000020',
"video": {
"mp4": "http://video.store/1234.mp4",
"webm": "htt[://video.store/1234.webm",
"transloadit_assembly_id": "1215b8b88b341cef1b602f085d1a51fd",
"transloadit_assemby_url": "http://tranloadit/assembly/1341234",
"status": 4
}
@jasonblanchard
jasonblanchard / authenticate
Created March 19, 2014 20:03
POST [api-root-url]/sessions
{
"user": {
"id": "52cace83374c10105e000005",
"email": "[email protected]",
"first_name": "Jason",
"last_name": "Blanchard",
"authentication_token": "HTjy9Qpm9XVvtjUJRTkH",
"organizations": [
{
"id": "52cc5b74374c10355b000001",
curl -v -X POST -d 'email=jason%40apprennet.com&password=testpass' 'http://localhost:3000/api/v1/users/authenticate'
@jasonblanchard
jasonblanchard / gist:11293963
Last active August 29, 2015 14:00
count characters
s = "This is a string with letters"
s.split('').inject(Hash.new(0)) do |memo, value|
memo[value.downcase] += 1
memo
end
# {"t"=>5, "h"=>2, "i"=>4, "s"=>4, " "=>5, "a"=>1, "r"=>2, "n"=>1, "g"=>1, "w"=>1, "l"=>1, "e"=>2}