Skip to content

Instantly share code, notes, and snippets.

View pzaich's full-sized avatar

Paul Zaich pzaich

View GitHub Profile
@pzaich
pzaich / restangular_config.js
Created November 13, 2014 18:22
configure camelize under_underscore translation
.config(function (RestangularProvider) {
RestangularProvider.addResponseInterceptor(function (data, operation, what, url, response, deferred) {
return humps.camelizeKeys(data);
});
RestangularProvider.addRequestInterceptor(function (data, operation, what, url, response, deferred) {
return humps.decamelizeKeys(data);
});
});
{ "helloWorld": true }
@pzaich
pzaich / localytics ng temp
Created September 22, 2014 20:10
localytics style ng-template
# app/helpers/application_helper.rb
# Render a partial into a script tag so Angular
# sticks it into $templateCache
def load_ng_template(partial)
content_tag :script, type: 'text/ng-template', id: "#{partial}.html" do
render partial
end
end
@pzaich
pzaich / regex_benchmarking.rb
Last active August 29, 2015 14:06
Ruby regexes: benchmarking scan vs =~
r = /bobcat|sky track|framing|forklift|demolition|plumbing|drywall|concrete|RF & magnetic shielding|electrian|bossman|boss man|fencing|farm equipment|equipment|steel|a job|my job|ur job|working|building|adding onto|18 wheeler|nuclear|powerplant|equipment|work station|my work|motor|fitting|fittin|stainless steal|stainless steel|mechanic|pipe|pipe welding|7018|6010|boiler|tool box|toolbox|tool|grinder|underpaid|repair|Mike Rowe|Miller Electric Welding|manufacturing|metals|forestry & logging|commercial & industrial equipment|industrials|mining materials|tools equipment|trade school|clutch|cylinder|roof|day at the office|carpenter|driver|maintenanceweld|weldor|tig|mig|gmaw|line out|welder|welding|weldin|welding hood|weldin hood/i
string = "my work station in nashville. over $20,000 of equipment sitting on that table"
# =~
position_time = Benchmark.realtime do
1000.times do
string =~ r
end
end
@pzaich
pzaich / my_custom_serializer.rb
Created September 11, 2014 18:19
my_custom_serializer
class MyCustomSerializerClass < ActiveModel::Serializer
class << self
# customize the associated object to the serializer
def model_class
SomeOtherClass
end
end
end
@pzaich
pzaich / performance_geocoding_comparison.rb
Last active August 29, 2015 14:02
performance comparison ESRI vs Bing
cities = [] #1081 california cities
t = Benchmark.realtime do
cities.each { |c| Geocoder.coordinates(" #{c}, ca") }
end
t
## esri 349.3133
## bing 204.9491
@pzaich
pzaich / california_cities.rb
Created June 10, 2014 18:24
california_cities
['ACTON','ADELANTO','AGOURA HILLS','ALAMEDA','ALAMO','ALBANY','ALHAMBRA','ALISO VIEJO','ALMANOR','ALONDRA PARK','ALPAUGH','ALPINE','ALPINE VILLAGE','ALTADENA','ALTA SIERRA','ALTURAS','ALUM ROCK','AMADOR CITY','AMERICAN CANYON','AMESTI','ANAHEIM','ANDERSON','ANGELS CITY','ANGWIN','ANTIOCH','APPLE VALLEY','APTOS','APTOS HILLS-LARKIN VALLEY','ARBUCKLE','ARCADIA','ARCATA','ARDEN-ARCADE','ARMONA','ARNOLD','AROMAS','ARROYO GRANDE','ARTESIA','ARVIN','ASHLAND','ATASCADERO','ATHERTON','ATWATER','AUBERRY','AUBURN','AUGUST','AVALON','AVENAL','AVERY','AVOCADO HEIGHTS','AZUSA','BAKERSFIELD','BALDWIN PARK','BANNING','BARSTOW','BAY POINT','BAYVIEW','BAYVIEW-MONTALVIN','BAYWOOD-LOS OSOS','BEALE AFB','BEAR VALLEY','BEAR VALLEY SPRINGS','BEAUMONT','BECKWOURTH','BELDEN','BELL','BELLFLOWER','BELL GARDENS','BELMONT','BELVEDERE','BENICIA','BEN LOMOND','BERKELEY','BERMUDA DUNES','BERTSCH-OCEANVIEW','BETHEL ISLAND','BEVERLY HILLS','BIG BEAR CITY','BIG BEAR LAKE','BIG BEND','BIGGS','BIG PINE','BIG RIVER','BIOLA','BISHOP','BLACKHAWK-C
SELECT "pid","application_name", "backend_start", "xact_start", "query_start", "state_change", "state" FROM pg_stat_activity;
@pzaich
pzaich / gist:9352790
Last active August 29, 2015 13:57
clear sidekiq scheduled jobs
jobs = Sidekiq.redis { |r| r.zrange("schedule", 0, -1, {withscores: true}) }
Sidekiq.redis { |r| jobs.each {|j| r.zrem "schedule", j } }
Sidekiq.redis { |r| r.FLUSHDB }
@pzaich
pzaich / sidekiq_delayed_paperclip.rb
Created August 5, 2013 16:56
Delayed_paperclip setup using Sidekiq
###gemfile
gem 'paperclip' ## 3.5.1, also 3.4.2 previously
gem 'delayed_paperclip'
gem 'sidekiq', '2.6.4'
### image.rb
attr_accessible :photo_processing
has_attached_file :photo,
styles: {