Skip to content

Instantly share code, notes, and snippets.

@bcackerman
bcackerman / File download on Heroku
Created August 17, 2016 20:51
Code to download a CSV file on Heroku (using Rails) and run a script on it
# 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
class Human
def talk
puts "I’m talking"
end
private
def whisper
puts "I’m whispering"
end
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 / Margin and padding elements
Last active December 29, 2015 11:59
Create a list of CSS elements that can be used in the view for margin/padding.
@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 November 23, 2013 17:47
Background image that covers the background
.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 August 21, 2013 18:58
Loop through large amounts of data in Rails without creating a huge object from ActiveRecord
ActiveRecord::Base.uncached do
# loop here
end
@bcackerman
bcackerman / gist:ea5df23b5bd59ca0d2a0
Created March 10, 2015 13:58
Rails' Locales with Country Names
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 August 29, 2015 14:09 — forked from siong1987/mrr.rb
Stripe Monthly Recurring Revenue (MRR) Calculator
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 June 8, 2014 19:15
JavaScript Promise example
function doSomething() {
return {
then: function(callback) {
return "3";
},
error: function(callback) {
return "4";
}
};