Skip to content

Instantly share code, notes, and snippets.

Bruce Ackerman bcackerman

Block or report user

Report or block bcackerman

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Human class
class Human
def talk
puts "I’m talking"
end
private
def whisper
puts "I’m whispering"
end
View Store information from JSON in a temp file
uri = URI('https://api.catalog.com/v2/products')
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
request = Net::HTTP::Get.new uri
request.basic_auth 'user', 'pass'
http.request request do |response|
open 'temp_file_name', 'wb' do |io|
response.read_body do |chunk|
io.write chunk
@bcackerman
bcackerman / File download on Heroku
Created Aug 17, 2016
Code to download a CSV file on Heroku (using Rails) and run a script on it
View File download on Heroku
# I'm using smarter-csv gem to help parse the CSV
require 'net/ftp'
filename = 'filename-here.csv'
temp_file = Tempfile.new("download-#{filename}")
temp_file.binmode
import_options = {chunk_size: 10000, downcase_header: true, :row_sep => :auto, encoding: "UTF-8"}
size = 0
progress = 0
@bcackerman
bcackerman / gist:ea5df23b5bd59ca0d2a0
Created Mar 10, 2015
Rails' Locales with Country Names
View gist:ea5df23b5bd59ca0d2a0
Country.create(:name => 'Afghanistan', :iso3 => 'AFG', :iso2 => 'AF', :numcode => 4)
Country.create(:name => 'Åland Islands', :iso3 => 'ALA', :iso2 => 'AX', :numcode => 248)
Country.create(:name => 'Albania', :iso3 => 'ALB', :iso2 => 'AL', :numcode => 8)
Country.create(:name => 'Algeria', :iso3 => 'DZA', :iso2 => 'DZ', :numcode => 12)
Country.create(:name => 'American Samoa', :iso3 => 'ASM', :iso2 => 'AS', :numcode => 16)
Country.create(:name => 'Andorra', :iso3 => 'AND', :iso2 => 'AD', :numcode => 20)
Country.create(:name => 'Angola', :iso3 => 'AGO', :iso2 => 'AO', :numcode => 24)
Country.create(:name => 'Anguilla', :iso3 => 'AIA', :iso2 => 'AI', :numcode => 660)
Country.create(:name => 'Antarctica', :iso3 => 'ATA', :iso2 => 'AQ', :numcode => 10)
Country.create(:name => 'Antigua and Barbuda', :iso3 => 'ATG', :iso2 => 'AG', :numcode => 28)
@bcackerman
bcackerman / stripe_mrr.rb
Last active Aug 29, 2015 — forked from siong1987/mrr.rb
Stripe Monthly Recurring Revenue (MRR) Calculator
View stripe_mrr.rb
require 'stripe'
require 'ostruct'
# modified & fixed for more subscription based Stripe account from: https://gist.github.com/jacobpatton/a68d228bf2414852d862
#
# puts Stripe::Mrr.new(api_key: 'api_key').report
#
module Stripe
class Mrr
attr_reader :api_key
@bcackerman
bcackerman / promise.js
Created Jun 8, 2014
JavaScript Promise example
View promise.js
function doSomething() {
return {
then: function(callback) {
return "3";
},
error: function(callback) {
return "4";
}
};
@bcackerman
bcackerman / Margin and padding elements
Last active Dec 29, 2015
Create a list of CSS elements that can be used in the view for margin/padding.
View Margin and padding elements
@each $property in margin, padding {
@each $location in top, right, bottom, left {
@for $i from 0 through 15 {
.#{$property}-#{$location}-#{$i * 10} { #{$property}-#{$location}: 10px * $i; }
}
}
}
@bcackerman
bcackerman / gist:7617698
Created Nov 23, 2013
Background image that covers the background
View gist:7617698
.wrapper {
background-image: url('images/bg.jpg');
background-repeat: no-repeat;
background-position: 0 0;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
@bcackerman
bcackerman / gist:6298673
Created Aug 21, 2013
Loop through large amounts of data in Rails without creating a huge object from ActiveRecord
View gist:6298673
ActiveRecord::Base.uncached do
# loop here
end
You can’t perform that action at this time.