This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def extract_options! | |
last.is_a?(::Hash) ? pop : {} | |
end | |
end | |
def match(*args) | |
rules = args.extract_options! | |
if rules.has_key?(*args) | |
rules[*args].call |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
date(created_at) as ordered_date, | |
sum(price) as total_price | |
FROM | |
orders | |
GROUP BY | |
date(created_at) | |
HAVING | |
sum(price) > 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
char* reverse(char *s) | |
{ | |
int i, placeholder; | |
int l = strlen(s) - 1; | |
for(i = 0; i < (l / 2); i++){ | |
placeholder = *(s+i); | |
*(s+i) = *(s+l-i); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ClientDashboard::Application.routes.draw do | |
namespace :admin do | |
resources :brands | |
resources :email_messages | |
resources :users | |
resources :memberships do | |
post 'new_by_brand', :on => :collection | |
end | |
resources :clients do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
respond_to :json | |
def index | |
if params[:secret].eql? SOME_API_TOKEN | |
respond_with Company.all_with_users_and_projects | |
else | |
render { head :forbidden } and return | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ companies: [ | |
{ name: “company name” | |
, users: [ | |
{ id: 1 | |
, first_name: “rob” | |
, last_name: “sterner” | |
, project_ids: [1,2,3,4] | |
} | |
] | |
, projects: [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int | |
mbtowc(wchar_t *p, char *s, size_t n) | |
{ | |
long l; | |
int c0, c, nc; | |
Tab *t; | |
if(s == 0) | |
return 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe RegistrationsController do | |
describe "Forgetful user gets to the user page. He should have a forgot password link" do | |
it "should display a template containing the string t('sessions.new.forgot_password')" do | |
end | |
end | |
describe "User provides an email address" do | |
it "should display a page containg an appropriate text field and a submit button" do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module StaffPlan::JsonSerializer | |
def serialize(*args) | |
options = args.extract_options! | |
if args.first.is_a?(Array) or args.first.is_a?(ActiveRecord::Relation) | |
serialize_collection(args.first, options) | |
else | |
serialize_instance(args.first, options) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.class_eval do | |
def extract! | |
if block_given? | |
[].tap do |rejects| | |
delete_if do |element| | |
yield(element) and rejects << element | |
end | |
end | |
else | |
self |