Skip to content

Instantly share code, notes, and snippets.

{
"openssl_packages" : [
"openssl-1.0.2k-8.el7.x86_64",
"openssl-libs-1.0.2k-8.el7.x86_64"
],
"name" : "cluster124-shard-00-00-iluv4.mmscloudteam.com",
"heracles_version" : "3aa10a7d1bb2a11aeeba7f51ad61cd94fcf759c7",
"chef_last_successful_run" : 1513938607,
"chef_repo_revision" : "87339f3a5b41314acee26445c92b7c5a15f075f9",
"chef_version" : "12.21.3"
include stdio.h
@cailinanne
cailinanne / is_int.py
Created April 12, 2012 20:28
is_int in python
def is_int(s):
try:
int(str(s))
return True
except ValueError:
return False
@cailinanne
cailinanne / mailer.rb
Created March 1, 2012 19:39
Send email via SMS
# 1. In views/mailer, for each whatever.html.erb template file create a corresponding whatever.sms.erb file. It will automatically have access to all the same template variables that are available in the HTML file.
# 2. In the mail method in mailer.rb replace the line "super headers" with something like
if you_want_to_send_via_SMS
sms_body = render :file => "mailer/#{action_name}.sms.erb", :layout => false
# Post to Kanel
else
super headers
end
@cailinanne
cailinanne / basket_controller.rb
Created February 28, 2012 15:43
Toy code for loan matching
def match_loans(basket)
match_basket = nil
total_spent = 0
match_user = # LOAD UP THE MATCHING ACCOUNT
basket.basket_items.each do |item|
loan = item.purchasable
# If this loan qualifies for matching and
@cailinanne
cailinanne / example_helpers.rb
Created November 28, 2011 03:36
Testing cache helpers with Rails 3.1 and Rspec
# spec/support/example_helpers.rb
module ExampleHelpers
module CachingTestHelpers
ActionController::Base.public_class_method :page_cache_path
module ResponseHelper
def action_cached?(request)
request.path.is_action_cached?
end
@cailinanne
cailinanne / cache_book.rb
Created November 28, 2011 03:33
Testing cache clearing with Rails 3.1 and Rspec
#spec/requests/cache_book_spec.rb
require 'spec_helper'
describe "CacheBook" do
# Turn on caching
before do
ActionController::Base.perform_caching = true
ActionController::Base.cache_store = :file_store, "tmp/cache"
FileUtils.rm_rf(Dir['tmp/cache'])
@cailinanne
cailinanne / cache_home.rb
Created November 28, 2011 03:22
Testing cache priming with Rails 3.1 and Rspec
#spec/requests/cache_home_spec.rb
require 'spec_helper'
describe "CacheHome" do
# Enable caching, just for the duration of this test
# Clear the cache
before do
@user = FactoryGirl.create(:user)
ActionController::Base.perform_caching = true
@cailinanne
cailinanne / application.rb
Created November 27, 2011 01:42
Rails 3 Action Sweeper - Advanced Configuration
config.active_record.observers = :books_sweepers
@cailinanne
cailinanne / book_sweeper.rb
Created November 27, 2011 01:17
Rails 3 Action Sweeper - Basic Configuration
class BookSweeper < ActionController::Caching::Sweeper
observe Book
def after_update(book)
expire_cache_for(book)
end
def after_books_share
book = Book.find params[:id]
expire_cache_for(book)