Skip to content

Instantly share code, notes, and snippets.

View pzaich's full-sized avatar

Paul Zaich pzaich

View GitHub Profile
@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 / 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 / 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 / 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
{ "helloWorld": true }
@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);
});
});
@pzaich
pzaich / pojo.js
Created April 19, 2015 17:17
pojo_constructor
var Library = function (books) {
var books = [];
this.searchBooks = function (query) {
// return books that match query
}
}
var books = [];
var library = new Library(books);
@pzaich
pzaich / factory_encapsulation.js
Last active August 29, 2015 14:19
factory encapsulation
angular.module('example', [])
.factory('libraryFactorySingleton', function () {
var books = [];
return {
searchBooks: function (query) {
// return books that match query
}
};
})
@pzaich
pzaich / service_encapsulation.js
Created April 19, 2015 17:40
service encapsulation
angular.module('example', [])
.service('libraryService', function () {
var books = [];
this.searchBooks = function () {
// return books that match query
}
});
var library = libraryService;
@pzaich
pzaich / gist:38ece4135c37c149e474
Created May 3, 2015 16:14
library_controller.js
angular.module('example', [])
.controller('libraryController', function (Books) {
var initialize = function () {
$scope.books = Books
}
$scope.removeBook = function () {
// accessible to scope
}