Skip to content

Instantly share code, notes, and snippets.

=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')
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
@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 '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 / fizzbuzz.clj
Last active August 29, 2015 13:56
fizzbuzz in clojure
(map #(cond
(= 0 (mod % 15)) "FizzBuzz"
(= 0 (mod % 5)) "Buzz"
(= 0 (mod % 3)) "Fizz"
:else %)
(range 1 101))
@bjhaid
bjhaid / tic_tac.clj
Created March 15, 2014 02:37
tic_tac solve in clojure
(fn [tic_tac]
(first (first (filter #(and (apply = %) (not (.contains % :e)))
((fn [tic_tac] (conj (apply conj tic_tac
((fn [tic_tac] (vec (map (fn[x] (vec (map #((tic_tac %) x) (range 3)))) (range 3)))) tic_tac))
((fn [tic_tac] (vec (map #((tic_tac %) %) (range 3)))) tic_tac)
((fn [tic_tac] (vec (map #((tic_tac (- 2 %)) %) (range 3)))) tic_tac))) tic_tac))))
)
def valid?(tic)
tac = *tic
3.times { |i| tac.push((0..2).map { |x| tic[x][i] }) }
tac.push((0..2).map { |x| tic[x][x] }).push((0..2).map { |x| tic[tic.size - 1 - x][x] })
(tac.select { |x| x.uniq.size == 1 && x.first != :e }).first
end
@bjhaid
bjhaid / fact.clj
Created April 7, 2014 01:12
tail call optimization (factorial)
(defn fact ([n] (fact n 1))
([n mul] (if (< n 1) mul (fact (dec n) (*' n mul)))))

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@bjhaid
bjhaid / sudoku.rb
Last active August 29, 2015 14:01
Sudoku board, with validator logic in 267 characters reduce to 208 characters
A=Array;d=A.new(9){A.new(9,"_")};loop{a,b,c=gets.split(":").map(&:to_i);next(p"invalid")if(d.map{|x|x[b]}+d[a-a%3,3].flat_map{|x|x[b-b%3,3]}+d[a]).include?c;d[a][b]=c;puts d.map{|x|x.join" "}}