Skip to content

Instantly share code, notes, and snippets.

View rojotek's full-sized avatar

Rob Dawson rojotek

  • ConsenSys
  • Australia
View GitHub Profile
@rojotek
rojotek / application.rb
Created November 29, 2011 06:59
Include root in json setting
...
ActiveRecord::Base.include_root_in_json = false
...
@rojotek
rojotek / controller.rb
Created November 29, 2011 07:12
render json in a controller.
# code to retrieve the collection - the to_json filtering works on a collection, or a single model record
render :json => collection.to_json(:only => [ :id, :name, :another_attribute])
@rojotek
rojotek / file1.sh
Created January 20, 2012 04:24
Ruby with OpenSSL on OSX 10.7
rvm pkg install openssl
rvm remove 1.9.3
rvm install 1.9.3 --with-openssl-dir=$rvm_path/usr --with-gcc=clang
@rojotek
rojotek / gist:1955943
Created March 2, 2012 05:36
Ruby code to detect the language of a webpage.
# gem install nokogiri
# gem install cld
# Use CLD, a wrapper around the google Compact Language Detector to detect the language that a
# webpage is in. Use Nokogiri to pull out the text of the page.
require 'cld'
require 'open-uri'
require 'nokogiri'
@rojotek
rojotek / DataManager.h
Created April 11, 2012 20:59 — forked from NachoMan/DataManager.h
Core Data singleton manager class capable of being run from a static library - updated for ARC.
// DataManager.h
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
extern NSString * const DataManagerDidSaveNotification;
extern NSString * const DataManagerDidSaveFailedNotification;
@interface DataManager : NSObject {
}
@rojotek
rojotek / format_time.m
Created April 22, 2012 23:47
ObjectiveC format time snippet
+ (NSString *)formatTime: (NSTimeInterval)totalSeconds {
int totalMinutes = (int) (totalSeconds / 60);
int hours = totalMinutes / 60;
int minutes = totalMinutes % 60;
int seconds = (int) (totalSeconds) % 60;
if (hours > 0) {
return [NSString stringWithFormat:@"%02i:%02i:%02i", hours, minutes, seconds];
} else {
return [NSString stringWithFormat:@"%02i:%02i", minutes, seconds];
@rojotek
rojotek / gist:3618157
Created September 4, 2012 07:49
shoulda matchers
it {should have_many(:items).through(:order_items)}
it {should have_db_column(:description).of_type(:string)}
@rojotek
rojotek / gist:3618181
Created September 4, 2012 07:52
simple_matcher
RSpec::Matchers.define :be_less_than do |expected|
match do |actual|
actual<expected
end
end
specify "5 should be less than 10" do
5.should be_less_than 10
end
describe 10 do
it {should be_less_than 11}
end