Skip to content

Instantly share code, notes, and snippets.

View jnstq's full-sized avatar

Jon Stenqvist jnstq

  • Equipe AB
  • Helsingborg, Sweden
View GitHub Profile
@jnstq
jnstq / ackrc
Created December 20, 2011 10:20
My .ackrc file
--type-add=ruby=.haml
--type-add=css=.sass
--type-add=css=.scss
--type-add=css=.less
--type-set
coffeescript=.coffee
--ignore-dir=node_modules
class TicketsController < ApplicationController
def index
@order = Order.paid.find_by_permalink!(params[:user_order_id])
ticket_report = TicketReport.new
ticket_report.order = @order
respond_to do |format|
format.pdf do
# excute the given block, retying only when one of the given exceptions is raised
module RetryOnFailure
def retry_on_failure(*exception_list)
retry_count = 5
begin
yield
rescue *exception_list => e
if retry_count > 0
retry_count -= 1
puts "Exception, trying again #{retry_count} more times"
it "normalize swedish cell phone number" do
user = Factory.build(:user, :cell_phone => "0707-293274")
described_class.new(:recipient => user).recipient_normalized_cell_phone.should == "0046707293274"
user = Factory.build(:user, :cell_phone => "+46707-293274")
described_class.new(:recipient => user).recipient_normalized_cell_phone.should == "0046707293274"
user = Factory.build(:user, :cell_phone => "0046707293274")
described_class.new(:recipient => user).recipient_normalized_cell_phone.should == "0046707293274"
end
@jnstq
jnstq / bitly.rb
Created May 3, 2011 20:06 — forked from jehiah/bitly.rb
# Bit.ly API implementation - thanks to Richard Johansso http://gist.github.com/112191
require 'httparty'
class Api::Bitly
include HTTParty
base_uri 'api.bit.ly'
format :json
# Usage: Bitly.shorten("http://example.com")
def self.shorten(url)
Surround these with : e.g. :calling:
+1
-1
bulb
calling
clap
cop
email
feet
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "konferensen",
:authentication => "plain",
:user_name => "[email protected]",
:password => "password",
:enable_starttls_auto => true
require 'rubygems'
require 'madmimi'
mimi = MadMimi.new("email", "key")
options = {
"promotion_name" => "Test Promotion",
"recipients" => "",
"from" => "",
@jnstq
jnstq / ar.rb
Created January 20, 2011 19:22
# http://avdi.org/devblog/2011/01/14/activerecord-golf
require 'active_record'
class Monster < ActiveRecord::Base
establish_connection :adapter => 'sqlite3',
:database => ':memory:'
connection.create_table( :monsters ) { |t| t.string :name }
after "deploy:stop", "delayed_job:stop"
after "deploy:start", "delayed_job:start"
after "deploy:restart", "delayed_job:restart"
namespace :delayed_job do
desc "Stop the delayed_job process"
task :stop, :roles => :app do
run "cd #{current_path}; script/delayed_job -e #{rails_env} stop"
end