Skip to content

Instantly share code, notes, and snippets.

View koos's full-sized avatar
💭
Coding

Jan koos

💭
Coding
View GitHub Profile
Factory :run do
# [...]
distances {|distances| [distances.association(:distance)]}
# [...]
end
distance_a = Factory.create(:distance) # only created to pass the Run model's validations
distance_b = Factory.create(:distance)
Factory.create(:run, :distances=>[distance_a, distance_b])
Factory.create(:run)
<html><body><div style='width:7.5cm;height:4.5cm;border:1px dashed black;margin-bottom:1cm;margin-right:1cm;float:left'>Nerd Level: 3<br/>Which one is the fastest sorting algorithm? <br/>a1: Selection Sort<br/>a2: Quick Sort<br/>a3: Bubble Sort<br/>a4: All the same<br/></div><div style='width:7.5cm;height:4.5cm;border:1px dashed black;margin-bottom:1cm;1cm;float:left;'><p style='margin:0px auto'>a2</p></div><br style='clear:left' /><div style='width:7.5cm;height:4.5cm;border:1px dashed black;margin-bottom:1cm;margin-right:1cm;float:left'>Nerd Level: 2<br/>What's the average run time of a search in a Binary Search Tree? <br/>a1: O(n)<br/>a2: O(n log n)<br/>a3: O(log n)<br/>a4: O(1)<br/></div><div style='width:7.5cm;height:4.5cm;border:1px dashed black;margin-bottom:1cm;1cm;float:left;'><p style='margin:0px auto'>a3</p></div><br style='clear:left' /><div style='width:7.5cm;height:4.5cm;border:1px dashed black;margin-bottom:1cm;margin-right:1cm;float:left'>Nerd Level: 2<br/>How to call the last command after sub
<html>
<head>
</head>
<body>
<div style="width:7.5cm;height:5.5cm;border:1px dashed black;margin-bottom:1cm;margin-right:1cm;float:left"></div>
<div style="width:7.5cm;height:5.5cm;border:1px dashed black;margin-bottom:1cm;1cm;float:left;"></div>
<br style="clear:left" />
</body>
</html>
@koos
koos / gist:1180703
Created August 30, 2011 11:30
json schema
{
"type": "object",
"title": "user",
"description": "a user",
"properties": {
"id": {
"type": "string",
"description": "The User Id",
"identity": true,
"required": true,
@koos
koos / gist:1180702
Created August 30, 2011 11:29
json schema controller
class Api::UsersController < ApiController
def show
respond_with(object_as_json(User.find_by_slug(params[:id])))
end
end
@koos
koos / gist:1180701
Created August 30, 2011 11:29
index.rabl
# app/views/posts/index.rabl
collection @posts
attributes :id, :title, :subject
child(:user) { attributes :full_name }
node(:read) { |post| post.read_by?(@user) }
The result of this is a JSON (or XML) looking like this:
[{ post :
{
@koos
koos / gist:1180699
Created August 30, 2011 11:29
app.rb rabl
# app/app.rb
get "/posts", :provides => [:json, :xml] do
@user = current_user
@posts = Post.order("id DESC")
render "posts/index"
end
@koos
koos / gist:1176858
Created August 28, 2011 16:18
as_json
render :json => { :success => true, :user => @user.as_json(:only => [:email]) }