Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View ritec's full-sized avatar

Ri Caragol ritec

View GitHub Profile
@ritec
ritec / NicknamePopulate.rb
Last active October 4, 2016 19:44
This Script will populate the nicknames table from the data in the Nickname and Diminutive Names Lookup Project.
puts "Populate Nickname table"
# Processes file in CSV format from http://code.google.com/p/nickname-and-diminutive-names-lookup/
puts "Truncating nicknames table"
Nickname.delete_all
puts "Downloading nicknames CSV file from http://code.google.com/p/nickname-and-diminutive-names-lookup/"
file = Net::HTTP.get 'nickname-and-diminutive-names-lookup.googlecode.com', '/files/names1.2.csv'
puts "Done"
puts "Parsing file"
@ritec
ritec / gist:9939236
Created April 2, 2014 17:45
Percentage Tracker in Console Example
#from http://brettu.com/category/rails/page/2/
@photos = Photo.all
count = @photos.count
@photos.each_with_index do |photo, idx|
# ... do a bunch of processing
puts "#{(100.0 * idx / count).round(2)}%"
end
# When the script is run we will get a percentage complete counter like:
#=> 0.1%
attachments: parent_id, asset_id
domain_names: organisation_id
event_memberships: user_id, event_id
events: editor_id
group_actions: user_id, group_id
groups: user_id
icons: parent_id
invitations: sender_id
legacy_actions: item_upon_id
news_items: author_id
[
{
"hierarchy1": "Bank Fees",
"hierarchy2": "",
"hierarchy3": "",
"plaid_transaction_category_id": 10000000,
"Inflows": "operating_expenses",
"Outflows": "operating_expenses",
"": 0
},
@ritec
ritec / ruby_tips_and_tricks.rb
Last active August 10, 2017 18:31
Useful and Common Ruby Operations and Tricks
Arrays
# http://stackoverflow.com/questions/7857019/rails-remove-element-from-array-of-hashes
filtered_array = array.reject { |h| blacklist.include? h['email'] }
filtered_array = array.select { |h| !blacklist.include? h['email'] }
# Hstore Tips and Tricks
# Sort based on the Hstore data:
2.1.1 :022 > Post.order("data->'hello' DESC")
@ritec
ritec / zipToCityState.js
Created November 7, 2016 15:16
Get City and State from Zip Code with Google Geo API
window.findAddressFromZip = function(zipcode) {
var city, state, zip;
zip = zipcode.value;
city = '';
state = '';
if (zip.length === 5) {
$.ajax({
type: 'POST',
url: "http://maps.googleapis.com/maps/api/geocode/json?address=" + zip + "?key=XXXXXXXXXXXXXXXXXXXX",
success: (function(_this) {
@ritec
ritec / Git Trips and Tricks
Created June 23, 2017 14:24
Git tips and tricks
# Delete many branches with one command
git branch | grep 'NXT-7' | xargs git branch -d
require 'fileutils'
namespace :spec do
def progress name, x, y
print "\r #{name}: #{x}/#{y} %6.2f%%" % [x.to_f/y * 100]
end
def generate_files name
kind = name.to_s.singularize
collection = Dir.glob Rails.root.join('app',name.to_s,'**','*').to_s
@ritec
ritec / bench_rails_memory_usage.rb
Created December 10, 2017 21:24 — forked from brianhempel/bench_rails_memory_usage.rb
A script to test the memory usage of your Rails application over time. It will run 30 requests against the specified action and report the final RSS. Choose the URL to hit on line 45 and then run with `ruby bench_rails_memory_usage.rb`.
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0
@ritec
ritec / user_agent.sql
Created January 11, 2018 22:12
New Relic Percentage User Agent
select percentage(uniquecount(session), where userAgentName = 'Chrome') as 'Chrome', percentage(uniquecount(session), where userAgentName = 'Firefox') as 'FireFox', percentage(uniquecount(session), WHERE userAgentName='IE') as 'IE' , percentage(uniquecount(session), WHERE userAgentName ='Safari') as 'Safari' from PageView SINCE 600 minutes ago