Skip to content

Instantly share code, notes, and snippets.

View luisalima's full-sized avatar

Luisa Lima luisalima

View GitHub Profile
@luisalima
luisalima / shoulda_model.rb
Created December 19, 2012 18:35
Testing models without vs. with shoulda
# without shoulda... tons of code :-)
it "should belong to person" do
Model.reflect_on_association(:person).macro.should == :belongs_to
end
# with shoulda... one-liner!
it{should belong_to(:person)}
@luisalima
luisalima / shoulda_cheat_model.rb
Created December 19, 2012 19:02
Shoulda model testing cheat sheet
# updated from the original @ http://cheat.errtheblog.com/s/rspec_shoulda
# just a subset -- models -- is included here. I'll update this, and create cheat sheets for others, as I go along.
# I marked the ones I added with NEW and also added the links to the corresponding code, as I think it's useful.
# Any comments/corrections are welcome!
# ================= Data and Associations =======================
# https://github.com/thoughtbot/shoulda-matchers/tree/master/lib/shoulda/matchers/active_record
it { should_not have_db_column(:admin).of_type(:boolean) }
@luisalima
luisalima / bla.rb
Created December 20, 2012 20:14
Trying to validate a boolean in ActiveRecord
# == Schema Information
#
# Table name: Bla
# test :boolean
class Bla < ActiveRecord::Base
attr_accessible :test
before_validation :test_present
def test_present
puts "TEST PRESENT"
@luisalima
luisalima / 0_reuse_code.js
Created August 14, 2014 09:59
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@luisalima
luisalima / bit_manipulation_swap.rb
Created April 30, 2016 18:08
Bit manipulation in Ruby
# swapping two integers, without using a temporary variable
a = 5 # 5
b = 7 # 7
a.to_s(2) # "101"
b.to_s(2) # "111"
a ^= b # a is now "010"
b ^= a # b is now "101"
a ^= b # a is now "111"
@luisalima
luisalima / right_left_shift_operators.rb
Created April 30, 2016 18:17
Right and left shift operators
# left shift operator is the equivalent of multiplying by a power of 2.
b = 1
(b << 1).to_s(2) # "10", equivalent to multiplying by 2^1
(b << 4).to_s(2) # "10000", equivalent to multiplying by 2^4
# right shift operator is the equivalent to integer divisin by 2.
b = 32
b.to_s(2) # "100000"
(b >> 1).to_s(2) # "10000", equivalent to dividing by 2
(b>>3).to_s(2) # "100", equivalent to dividing by 2^3
@luisalima
luisalima / debuggingHandlebars
Last active July 7, 2016 15:52
Metalsmith step-by-step
Use `log` from handlebars v3 onwards:
http://stackoverflow.com/a/32218903

Keybase proof

I hereby claim:

  • I am luisalima on github.
  • I am luisalima (https://keybase.io/luisalima) on keybase.
  • I have a public key ASDJhuwOZQX6RCcbovR-py-NVzwoYeO0El1x2XJD_RTspQo

To claim this, I am signing this object:

@luisalima
luisalima / provision-pi.sh
Created February 21, 2019 10:44
A work in progress script to provision a raspberry pi with raspbian
#!/bin/bash
export HOSTNAME='***'
TOOLS="tmux"
COUNTRY="**"
SSID="***"
function change_hostname {
sudo sh -c "echo $HOSTNAME > /etc/hostname"
sudo sed -i "s/raspberrypi/$HOSTNAME/g" /etc/hosts