Skip to content

Instantly share code, notes, and snippets.

@amichal
amichal / merge.rb
Created January 13, 2012 22:17
active record bulk merge
class ActiveRecord::Base
# Bulk merge a bunch of records
#
# we expect most of the records to import to represent updates
# so this method tries to be efficent with database queries
# by using a single query to find any existing records matching the key_attributes
# updating those records and finally inserting each remaining record
#
# It DOEST NOT use a transaction or lock. callers responsibilty to
# add that if desired
@amichal
amichal / bulk_merge.rb
Created August 2, 2012 18:12
csv export and bulk load any rails scope
# Bulk merge a bunch of records
#
# we expect most of the records to import to represent updates
# so this method tries to be efficent with database queries
# by using a single query to find any existing records matching the key_attributes
# updating those records and finally inserting each remaining record
#
# It DOEST NOT use a transaction or lock. callers responsibilty to
# add that if desired
#
/*
drawDial(
value:
renderTo:
)
*/
function drawDial(options) {
var renderTo = options.renderTo,
value = options.value,
@amichal
amichal / README
Created September 26, 2012 15:24
GitHub Tweaks
To use on OSX:
1.allow extension installs from github
$defaults write com.google.Chrome ExtensionInstallSources -array "https://*.github.com/*"
2. restart Chrome
3. come back here and click the 'raw' link for github_gr.user.js
4. allow Chrome to install the script above as a user extension
5. go to github issues list.
#asset pipeline on
config.assets.enabled = true
#dont load the whole damn app and connect to the db to precompile
config.assets.initialize_on_precompile = false
# turn off compression entirely
config.assets.compress = false
#OR for css/js explicitly
@amichal
amichal / select2_input.rb
Created May 6, 2013 17:20
select2 integration with simple_form
class Select2Input < SimpleForm::Inputs::CollectionSelectInput
def input
options[:include_hidden] ||= false
options[:include_blanks] ||= false
options[:input_html][:id] ||= "#{@builder.options[:as]}_#{attribute_name}"
dom_selector = "##{options[:input_html][:id]}"
if select2_options = options.delete(:select2)
options[:collection] = [] + Array(@builder.object.send(attribute_name))
end
<?php
$survey = array(
'Q0' => array(
'number' => false,
'prompt' => 'Email Address:',
'type' => 'email',
'input_attribs' => 'type="email" placeholder="e.g. [email protected]" required autofocus'
),
'Q1' => array(
before_filter do
if request.user_agent =~ /bingbot/
render :status => 503, :text=>'Too busy to server spiders now'
return false
end
end
gem 'lograge'
@amichal
amichal / application_controller.rb
Last active March 27, 2017 18:46
Server-side Google Analytics tracking in rails
class ApplicationController
around_filter :track_with_google_analytics
private def track_with_google_analytics
start = Time.now
yield
# Track API hits server-side using Google's Measurement Protocol
# https://developers.google.com/analytics/devguides/collection/protocol/v1/
if ENV['GA_TRACKING_CODE'].present?
finish = Time.now