Skip to content

Instantly share code, notes, and snippets.

View cbetta's full-sized avatar
👨‍💻
Pouring some Gr4vy

Cristiano Betta cbetta

👨‍💻
Pouring some Gr4vy
View GitHub Profile
@cbetta
cbetta / gist:1393974
Created November 25, 2011 17:00
How to fix a segfault for Nokogiri on Ruby 1.8.7 on OS X
# First install libxslt and libxml2 using Homebrew
brew install libxslt
brew install libxml2
# Now rebuild nokogiri with these new libs (make sure to update version numbers if your homebrew installed a different version)
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
@cbetta
cbetta / gist:2006770
Created March 9, 2012 14:38
A better way handle Omniauth identity failed logins
OmniAuth.config.on_failure = -> env do
env[ActionDispatch::Flash::KEY] ||= ActionDispatch::Flash::FlashHash.new
env[ActionDispatch::Flash::KEY][:error] = "Either your email or password was not recognised. Please try again."
SessionsController.action(:new).call(env) #call whatever controller/action that displays your signup form
end
@cbetta
cbetta / new.html.erb
Created April 12, 2012 15:31
Omniauth Identity: T&C Step 1
<div class="field">
<%= label_tag :conditions %><br>
<%= check_box_tag :conditions %>
</div>
@cbetta
cbetta / identity.rb
Created October 9, 2012 15:25
Step 2 - Add terms & conditions validation to Omniauth Identity
class Identity < OmniAuth::Identity::Models::ActiveRecord
...
validates :conditions, acceptance: true, allow_nil: false, on: :create
attr_accessor :conditions
...
end
@cbetta
cbetta / omniauth.rb
Created October 9, 2012 15:26
Step 3 - Add terms & conditions validation to Omniauth Identity
Rails.application.config.middleware.use OmniAuth::Builder do
provider :identity, fields: [:email, :conditions]
end
@cbetta
cbetta / case.sh
Created October 17, 2012 17:02
How to change the case of a filename in Git
git mv readme.md readme.md.temp
git mv readme.md.temp README.md
def namedObjectsNear(lat: Double, long: Double): Seq[Venue] = {
def call(lat: Double, long: Double, distances: List[Int]): Seq[Venue] = {
var res = List[Venue]()
var remainingDistances = distances
while (distance.tail.size != 0 && res.size <= 20)
res = API.getResults(lat, long, distance)
remainingDistances = remainingDistances.tail
res
}
@cbetta
cbetta / rspec.rb
Created January 4, 2013 13:46
How to cleanup after yourself in rspec. Just put this in a support file in spec/support/*.rb
RSpec.configure do |config|
config.after(:all) do
# do something
end
end
require 'bloomfilter'
bf = BloomFilter.new({ 'bits' => 0xff, 'salts' => %w(z A) })
bf.add("foo")
bf.test("foo")
#=> true
bf.to_json
@cbetta
cbetta / update.rb
Last active December 12, 2015 04:28
apt-get update before puppet
stage { 'preinstall':
before => Stage['main']
}
class apt_get_update {
exec { 'apt-get -y update': }
}
class { 'apt_get_update':
stage => preinstall