Skip to content

Instantly share code, notes, and snippets.

View avand's full-sized avatar

Avand Amiri avand

View GitHub Profile
def mongo_up?
connection_string = "..."
connection = Mongo::Connection.from_uri connection_string
connection.db('...').stats['ok'] == 1.0
rescue
false
end
def memcached_up?
client = Dalli::Client.new('...', :username => '...', :password => '...')
client.get('test').nil?
rescue
false
end
@avand
avand / csv.rake
Created June 30, 2011 04:54
CSV Model Exporter Task
namespace :csv do
task :export, :model, :attributes, :scope, :needs => :environment do |task, args|
raise ArgumentError, "Specify a model (e.g. rake sqoot:csv:export[User])" if args[:model].blank?
model = args[:model].constantize
models = model.send(args[:scope] || :all) # e.g. User.with_email || User.all
file_name = "#{args[:model].tableize}#{'_' + args[:scope] if args[:scope]}.csv" # e.g. users_with_email.csv
file = File.join(Rails.root, 'tmp', file_name)
columns = args[:attributes].try(:split, ',') || model.send(:new).attributes.keys
<style>
#sqoot-search form.sqoot-search label { display: inline; margin-right: 5px; }
#sqoot-search form.sqoot-search input[type=text] { width: 70px; margin-right: 10px; }
</style>
<script>
function after_sqoot_search_loaded() {
var hiddenLocationField = $('.sqoot-search #location');
var searchLabel = $('.sqoot-search label');
var queryField = $('.sqoot-search #query');
.bundle/gems/ruby/1.9.1/gems/geocoder-1.0.2/lib/geocoder/results/freegeoip.rb:7:in `+'
.bundle/gems/ruby/1.9.1/gems/geocoder-1.0.2/lib/geocoder/results/freegeoip.rb:7:in `address'
[PROJECT_ROOT]controllers[PROJECT_ROOT]lication_controller.rb:53:in `geocode_and_persist_location'
[PROJECT_ROOT]controllers[PROJECT_ROOT]lication_controller.rb:39:in `initialize_location'
.bundle/gems/ruby/1.9.1/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:436:in `_run__2678261678559900510__process_action__4540721125657822695__callbacks'
.bundle/gems/ruby/1.9.1/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
.bundle/gems/ruby/1.9.1/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.0.3/lib/abstract_controller/callbacks.rb:17:in `process_action'
.bundle/gems/ruby/1.9.1/gems/actionpack-3.0.3/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
.bundle/gems/ruby/1.9.1/gems/activesu
Rebuilding searches
> Sep 1, 2011: 18322 searches
> Sep 2, 2011: 19447 searches
> Sep 3, 2011: 16539 searches
> Sep 4, 2011: 17484 searches
> Sep 5, 2011: 18901 searches
> Sep 6, 2011: 20274 searches
> Sep 7, 2011: 20194 searches
> Sep 8, 2011: 19527 searches
> Sep 9, 2011: 39158 searches
gem install capybara-webkit -v '0.6.1'
Building native extensions. This could take a while...
ERROR: Error installing capybara-webkit:
ERROR: Failed to build gem native extension.
/Users/avand/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
Gem files will remain installed in /Users/avand/.rvm/gems/ruby-1.9.2-p290/gems/capybara-webkit-0.6.1 for inspection.
Results logged to /Users/avand/.rvm/gems/ruby-1.9.2-p290/gems/capybara-webkit-0.6.1/./gem_make.out
@avand
avand / food.markdown
Created January 12, 2012 21:41
Sqoot Hack-a-party!
~/Code/mojotech/nest4less (master)> curl -I http://email.bundle.com/wf/click?upn=gMlMZDpny0NyxfcTpX-2FOTgznA3blqr7Xyk3Pj5MjLSrawHJ4fG0gs-2BL24GLvvLkEHodX-2BuxA2AjB9Z-2Bc-2BYs2lyhj4WdTbC11G0yX8g0-2FCxvEjZkllCc6pgHou3gkRTiBklefyIWUQlm6ZxyFluUALnGwNk8XZP-2B9F3hnd5KvPRmFRmw5RcBA75ADU-2FJX26MC_a0CozdHDIYk-2F-2FE-2BofPglZi7HZO6rcrJkzskqWFxaNOTEmdXQlpAf7sk6XcGUbd0Kwx4-2FvIbv8-2Bq1Y2-2FzWldNER8OUtpjXhi4SPSQYAEOokgHazsazEoSocu5cgkLvivDaZ6jhL6XdkZt7m8kX9fy0H3lX-2BNi-2Ftx0vo3L4aBZBaELm3svfRr62owbzjDyn4QWI-2FwlPahQcGE9YYEcqFC5SF3b2tPArApa0Bg3NSkGkjFA27gdZHYsI2qnQ2IGLM8UZZh-2FKM-2BOIgUMxBi3xjKlxHHuKMssi8O7nyDwIfFuycLjrIcK1WQibk16e5-2BdvkNCBBl5PSGrIdp-2FDdGoLhtXYQ-3D-3D
HTTP/1.1 302 Found
Date: Thu, 19 Jan 2012 23:27:32 GMT
Server: Apache
X-Powered-By: PHP/5.3.2-1ubuntu4.7
Location: https://www.saveology.com/deals/national/tax-return-center?utm_source=AFF&utm_medium=CJ&utm_campaign=3155797&sub_id=3155797&aff_id=53
Vary: Accept-Encoding
Connection: close
Content-Type: text/html; charset=utf-8
require 'httparty'
class YahooApi
include HTTParty
# http://developer.yahoo.com/geo/placefinder/guide/responses.html#address-quality
ACCEPTABLE_ADDRESS_QUALITIES = [87, 85]
class RequestFailed < StandardError
def initialize(response)