Skip to content

Instantly share code, notes, and snippets.

View wkrsz's full-sized avatar

Wojtek Kruszewski wkrsz

View GitHub Profile
@wkrsz
wkrsz / usher.rb
Created May 7, 2010 14:16
hack to support post_url(@post)
require 'rubygems'
require 'usher'
# according to README should be:
# Usher::Util::Rails.activate
# but above gives an error: vendor/plugins/usher/lib/usher/util/rails.rb:13: class definition in method body (SyntaxError)
# - so instead we load appropriate interface manually:
ActionController::Routing.module_eval "remove_const(:Routes); Routes = Usher::Interface.for(:rails23)"
diff --git a/lib/caboose/acts/paranoid.rb b/lib/caboose/acts/paranoid.rb
index 608169d..fc6199b 100644
--- a/lib/caboose/acts/paranoid.rb
+++ b/lib/caboose/acts/paranoid.rb
@@ -171,6 +171,7 @@ module Caboose #:nodoc:
unless new_record?
self.class.update_all self.class.send(:sanitize_sql, ["#{self.class.deleted_attribute} = ?", (self.deleted_at = self.class.send(:current_time))]), ["#{self.class.primary_key} = ?", id]
end
+ @destroyed = true
freeze
@wkrsz
wkrsz / gist:756086
Created December 27, 2010 12:01
Google App Script - import calendar events into a spreadsheet
function import_calendar( start_date, end_date, cal_name, spreadsheet, sheet_name) {
var sheet = spreadsheet.getSheetByName(sheet_name);
var cal = CalendarApp.getCalendarsByName(cal_name)[0];
sheet.clear();
events = cal.getEvents( start_date, end_date );
irow = 2;
for( i in events ) {
evt = events[i];
var date = evt.getStartTime();
@wkrsz
wkrsz / gist:1404434
Created November 29, 2011 11:10
Retrieve Gmail Thread IDs
# Code example for http://wojt.eu/post/13496746332/retrieving-gmail-thread-ids-with-ruby
def patch_net_imap_response_parser(klass = Net::IMAP::ResponseParser)
klass.class_eval do
def msg_att
match(T_LPAR)
attr = {}
while true
token = lookahead
case token.symbol
@wkrsz
wkrsz / README.md
Created May 3, 2012 13:43 — forked from dsokolowski/README.md
Integration capybara with minitest

##Integration capybara with minitest

Requirements:

  • ruby 1.9
  • gem capybara

All you have to do is to require file test_helper.rb at the beginning of your test files.

@wkrsz
wkrsz / gist:2761871
Created May 21, 2012 11:16
Tddium post-build-hook to deploy to EngineYard
# Setup:
# tddium config:add suite EY_API_TOKEN xxxxxxxx
# (take EY_API_TOKEN value from ~/.eyrc)
# tddium config:add suite EY_DEPLOY_KEY yyyyyyy
# (EY_DEPLOY_KEY value is Base64-encoded content of your ~/.ssh/id_rsa OR any other ssh key authorised for a given EY env)
require 'timeout'
require 'etc'
require 'base64'
Enumerable.module_eval do
def select_by(attribute_name, value)
detect do |item|
item.send(attribute_name) == value
end
end
def select_by!(attribute_name, value)
select_by(attribute_name, value) \
or raise StandardError.new("can't find item with #{attribute_name} equal to #{value} in #{self.inspect}")
@wkrsz
wkrsz / devise.rb
Created January 9, 2013 11:48
Support for token HTTP header authentication in Devise
#config/initializers/devise.rb
config.warden do |manager|
manager.strategies.add :token_header_authenticable, TokenHeaderAuthenticable
manager.default_strategies(:scope => :user).unshift :token_header_authenticable
end
@wkrsz
wkrsz / monkey_patch.rb
Created March 3, 2013 15:39
add with_association_target to ActiveRecord Relation class
ActiveRecord::Relation.class_eval do
def with_association_target(targets)
@association_target = (@association_target||{}).merge(targets)
self
end
def load_with_association_targets(*args)
load_without_association_targets(*args).tap do
@records.each{|record| set_association_targets(record) }
end
@wkrsz
wkrsz / config-application.rb
Last active September 19, 2018 00:36
Example on how to extract Devise user ID for Rails TaggedLogger.
config.log_tags = [
:remote_ip,
->(req){
if user_id = WardenTaggedLogger.extract_user_id_from_request(req)
"#" + user_id.to_s
else
"guest"
end
}
]