Skip to content

Instantly share code, notes, and snippets.

@HotFusionMan
HotFusionMan / gist:6386156
Created August 30, 2013 03:48
How to expire just one view fragment from the Rails cache

In the following code, I assume there's a cache_key_for method defined in ApplicationHelper that's being used by the Rails app to compute the key used for caching the asset objects. If that isn't the case in your app, you won't need the helper calls, but you'll need to supply whatever code you're actually using for determining cache key values.

in Rails console:

controller = ApplicationController.new
controller.expire_fragment(helper.cache_key_for(asset))

in other code (where the "helper" method is not defined):

include ApplicationHelper
controller = ApplicationController.new

controller.expire_fragment(cache_key_for(asset))

@HotFusionMan
HotFusionMan / Git_tips.md
Last active December 18, 2015 02:09
Git tips

how to list commits that are on one branch but not another (from http://stackoverflow.com/questions/1710894/using-git-show-all-commits-that-are-in-one-branch-but-not-the-others ): git log <branch_you_want_to_look_at> ^<branch_you_want_to_ignore> --no-merges You can specify multiple branches to ignore by adding more ^branchname arguments.

how to list branches that contain a given commit ("git branch --contains", "git cherry"): http://stackoverflow.com/questions/1419623/git-how-to-list-branches-that-contain-a-given-commit

The Illustrated Guide to Recovering Lost Commits with Git http://www.programblings.com/2008/06/07/the-illustrated-guide-to-recovering-lost-commits-with-git/

@HotFusionMan
HotFusionMan / .irbrc
Last active July 26, 2016 08:31
A useful Rails 4 .irbrc file (for use with Rails-project-specific .irbrc file loading capability from http://railsbros.de/2010/11/29/a-custom-irbrc-for-rails-3.html ). See earlier revisions for Rails 3 version.
def show_controller_action_callbacks
_process_action_callbacks.map(&:filter)
end
alias :action_callbacks :show_controller_action_callbacks
def recognize_path(path, environment = { :method => 'GET', :extras => {} })
(@named_routes ||= Rails.application.routes).recognize_path(path, environment)
end
alias :recognize_route :recognize_path
@HotFusionMan
HotFusionMan / activerecord_base_to_sql.rb
Last active December 11, 2015 04:09
ActiveRecord::Base instances don't know how to dump themselves out as SQL. Here's a method to do so (tested only for PostgreSQL).
class ActiveRecord::Base
def to_sql
columns = self.class.columns
values_list = []
columns.each do |column|
value = self.__send__( column.name.to_sym )
case column.type
when :string, :text, :datetime, :timestamp, :time, :date
@HotFusionMan
HotFusionMan / gist:3693902
Created September 10, 2012 21:14
A way to edit the methods of the actual Time class for testing purposes. Useful in situations where a fake class (e.g., https://gist.github.com/3672210 ) can't be substituted, such as when third-party code that uses Time is involved.
# Redefine Time.now to be one day earlier than the real thing.
# N.B. Using the "alias" keyword does not work correctly -- in the following, it would cause infinite stack recursion. Cf. http://www.ruby-forum.com/topic/135598
class Time
class << self
alias_method :original_now, :now
def now
original_now - 86400
end
@HotFusionMan
HotFusionMan / gist:3672210
Created September 8, 2012 05:51
Use Clock wherever you would use Time. Edit as needed for testing purposes.
# Use Clock wherever you would use Time. Edit as needed for testing purposes. N.B. Remember that .now is a class method!!!
class Clock < Time
#def self.now
#super #.advance( :days => -1, :seconds => -1 ) # #advance is available in a Rails or ActiveSupport environment
#end
end
@HotFusionMan
HotFusionMan / gist:2992151
Created June 25, 2012 23:47
run only one Rails test class via Rake
test_type=unit
test_class_name=active_record
rake test:${test_type}s TEST=test/${test_type}/${test_class_name}_test.rb
@HotFusionMan
HotFusionMan / gist:2968572
Created June 21, 2012 21:13
Mac OS X network preference files to delete when Wi-Fi connection does not stay up
cd /Library/Preferences/SystemConfiguration
sudo rm com.apple.airport.preferences.plist com.apple.network.identification.plist
cd ~/Library/Preferences
rm com.apple.internetconfigpriv.plist com.apple.internetconfig.plist
@HotFusionMan
HotFusionMan / gist:2766541
Created May 22, 2012 04:23
command line for installing mysql gem on 64-bit Mac OX X 10.{6,7}
env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-dir=/usr/local/mysql/lib/ --with-mysql-config=/usr/local/mysql/bin/mysql_config
@HotFusionMan
HotFusionMan / installed_jailbreak_packages.txt
Created December 28, 2011 18:48
jailbreak packages currently installed on my iPhone 3GS; follow instructions at http://j.mp/u51urf to install all these packages via command line
actionmenu install
applist install
apr-lib install
apt install
apt7 install
apt7-key install
apt7-lib install
apt7-ssl install
backgrounder install
base install