Skip to content

Instantly share code, notes, and snippets.

View fcastellanos's full-sized avatar

Fernando Castellanos fcastellanos

View GitHub Profile
@runningferret
runningferret / gist:8fc78086595f9f0967e1
Created April 22, 2015 03:53
Use Minitest and ActiveRecord4 to load fixtures, without Rails
Bulk of this snagged from: https://gist.github.com/guilleiguaran/56a3879da5f6b6f467ce
Fixtures bit snagged from: https://github.com/cucumber/cucumber/wiki/Fixtures
require 'active_record'
require 'active_record/fixtures'
class MiniTest::Spec
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => "./db/development.sqlite3"
)
@anhldbk
anhldbk / get_public_ip.py
Created October 13, 2014 07:23
Get public IP with Python & Requests
import requests
r = requests.get(r'http://jsonip.com')
ip= r.json()['ip']
print 'Your IP is', ip
@seyhunak
seyhunak / cache.rb
Created April 30, 2014 08:17
Get & Set To Redis Cache - Rails 4
def get_from_cache(uid, key)
redis_available = true
Sidekiq.redis do |connection|
begin
objects = Rails.cache.read("user:#{uid}:#{key}") if connection
rescue Redis::CannotConnectError
ExceptionNotifier.notify_exception(e)
redis_available = false
end
end
@schickling
schickling / Rakefile
Last active January 31, 2024 23:00
Activerecord without Rails
require "active_record"
namespace :db do
db_config = YAML::load(File.open('config/database.yml'))
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'})
desc "Create the database"
task :create do
ActiveRecord::Base.establish_connection(db_config_admin)
@kidpollo
kidpollo / script.rb
Created August 1, 2012 22:18
Generic pattern for handling account trial states and notifications
tn = TrialNotification.new(@account, Notifier)
tn.assm_current_state
# :trial
tn.send_first_notification!
tn.assm_current_state
# :first_notification_sent
tn.send_second_notification!
tn.assm_current_state
# :second_notification_sent
tn.send_third_notification!
@amolbrid
amolbrid / gist:709442
Created November 22, 2010 02:36
Using ActiveRecord without Rails
require 'rubygems'
require 'active_record'
dbconfig = YAML::load(File.open('database.yml'))
ActiveRecord::Base.establish_connection(dbconfig)
ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a'))
class Employee < ActiveRecord::Base
end
@dnagir
dnagir / rspec-syntax-cheat-sheet.rb
Created November 5, 2010 09:29
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@Sutto
Sutto / _maps.sass
Created March 17, 2010 15:21
Unobtrusive Gmaps w/ html5 data attributes and rails 3
.gmap.map-preview
:width 540px
:height 400px
:margin 5px auto
:border 5px solid #DDD
:background #F1F1F1 url('/images/map-placeholder.jpg') center center no-repeat