Skip to content

Instantly share code, notes, and snippets.

@khoan
khoan / australian-postcodes.sql
Created November 13, 2020 06:17 — forked from randomecho/australian-postcodes.sql
Australian postcodes (with states and suburb names) geocoded with latitude and longitude.
/*
Taken and cribbed from blog.datalicious.com/free-download-all-australian-postcodes-geocod
May contain errors where latitude and longitude are off. Use at own non-validated risk.
*/
SET NAMES utf8;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
DROP TABLE IF EXISTS postcodes_geo;
@khoan
khoan / some_controller.rb
Created June 6, 2020 12:00 — forked from mlt/some_controller.rb
Stream PostgreSQL query with potentially huge result set as CSV using gzip compression in Rails and low memory overhead
headers['X-Accel-Buffering'] = 'no'
headers['Cache-Control'] = 'no-cache'
headers['Content-Type'] = 'text/csv; charset=utf-8'
headers['Content-Disposition'] = 'inline; filename="data.csv"'
headers['Content-Encoding'] = 'gzip'
sql = "select * from something;"
self.response_body = SqlToCsvStreamer.new(sql)
@khoan
khoan / user.rb
Created May 21, 2020 13:48 — forked from ziemekwolski/user.rb
Ruby model formatted
class User < ActiveRecord::Base
# == Constants ============================================================
GENDERS = [[‘Male’, ‘m’], [‘Female’, ’f’]].freeze
# == Attributes ===========================================================
# paperclip
attr_accessor :remove_logo
@khoan
khoan / ticket.rb
Created May 2, 2020 00:31 — forked from dhh/ticket.rb
class Ticket < ActiveRecord::Base
belongs_to :grouper
belongs_to :user
validate :user_cant_be_blacklisted, on: :confirmation
validate :user_cant_double_book, on: :confirmation
validate :grouper_cant_be_full, on: :confirmation
validate :grouper_cant_have_occurred, on: :confirmation