Skip to content

Instantly share code, notes, and snippets.

@zero5100
zero5100 / apportion_lrm.sql
Last active April 22, 2020 20:15
This is an apportionment function using the Largest Remainder Method (LRM) used to divide a given total amount between any number of buckets proportionally.
DROP FUNCTION IF EXISTS apportion_lrm(NUMERIC, JSONB, INTEGER, NUMERIC, BOOLEAN);
CREATE FUNCTION apportion_lrm
(
IN apportion_amt NUMERIC,
IN proportions JSONB,
IN data_scale INTEGER DEFAULT 0,
IN proportion_total NUMERIC DEFAULT NULL,
IN allow_truncate_apportion BOOLEAN DEFAULT FALSE
)
RETURNS JSONB AS $BODY$
@wycleffsean
wycleffsean / dump_seeds.rake
Created September 1, 2016 17:25
Dump entire database into seeds
namespace :db do
task dump_seeds: :environment do
Rails.application.eager_load!
path = 'db/fixtures/gen/%s.rb'
ObjectSpace.each_object(Class)
.select{|c| c < ActiveRecord::Base && !c.abstract_class? }
.each do |c|
# skip if it's a view
next if c.new.readonly?
next unless c.attribute_names.include?('id')
@johnallen3d
johnallen3d / -introduction.md
Last active January 4, 2016 22:12
Technekes Rubocop Introduction and Instructions

A goal of the engineering team is to improve code quality and consistancy. One of the simplest ways to head in that direction is to start (or further) the use of RuboCop. If you're not farmiliar, RuboCop is a static Ruby code analyzer that use a common Ruby Style Guide as it's basis for enforcing standards. Once installed (it's just a gem) the RuboCop binary can be used as part of our development workflow to help enforce standards and consistancy on a change by change basis (with the help of Guard for example).

Realizing that some projects currently have a version of RuboCop setup and some do not at all we would like to take a gradual approach to introducing RuboCop. The idea would be to get RuboCop installed on an existing code base and then disable all of the cops that are not passing at the outset. From there we would spend a little time each week (or as you're naturally editing an existing piece of code) bringing things

@invalidusrname
invalidusrname / killing_pids_in_pg.sql
Last active April 3, 2019 20:59
Kills active connections to a postgres database
-- 9.1
-- Terminate connections to a database
SELECT
pg_terminate_backend(procpid)
FROM
pg_stat_activity
WHERE
-- don't kill my own connection!
procpid <> pg_backend_pid()
-- don't kill the connections to other databases
@croaker
croaker / postgresql.rb
Created May 15, 2012 12:50
Homebrew - PostgreSQL 9.2 Beta Formula
require 'formula'
class Postgresql < Formula
homepage 'http://www.postgresql.org/'
url 'http://ftp.postgresql.org/pub/source/v9.2.0beta1/postgresql-9.2beta1.tar.bz2'
md5 '7bb0b7a3a6c32a9ae153d4132fe47d01'
depends_on 'readline'
depends_on 'libxml2' if MacOS.leopard? # Leopard libxml is too old
depends_on 'ossp-uuid'