Skip to content

Instantly share code, notes, and snippets.

@endenis
endenis / postgresql_invalid_indexes.sql
Created August 6, 2019 10:16
postgresql display invalid indexes
SELECT * FROM pg_class, pg_index WHERE pg_index.indisvalid = false AND pg_index.indexrelid = pg_class.oid;
@endenis
endenis / logger.txt
Last active August 18, 2016 13:19
Add logging to sql in production rails console
ActiveRecord::Base.logger = Logger.new(STDOUT)
@endenis
endenis / polynomial_regression.rb
Last active August 29, 2015 14:23
Polynomial regression in ruby
require 'matrix'
def polynomial_regression x, y, degree
rows = x.map do |i|
(0..degree).map { |power| (i ** power).to_f }
end
mx, my = Matrix.rows(rows), Matrix.columns([y])
((mx.transpose * mx).inv * mx.transpose * my).transpose.row(0).to_a.reverse
end
@endenis
endenis / launch_puma
Last active August 29, 2015 14:19
Launch puma locally with workers
puma -w 4 --preload --port 3000
fn swap(arr: &mut Vec<int>, i: uint, j: uint) -> &Vec<int> {
let buf = arr[i];
arr[i] = arr[j];
arr[j] = buf;
arr
}
fn insertion_sort1(arr: &mut Vec<int>) -> &Vec<int> {
for i in range(1, arr.len()) {
let key = arr[i];
@endenis
endenis / postgresql_commands
Created September 20, 2014 22:01
Commands for using postgresql on mac os x (installed via brew).
# Commands for using postgresql on mac os x (installed via brew).
# Start postgresql
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
# Status
pg_ctl -D /usr/local/var/postgres status
# Stop postgresql
pg_ctl -D /usr/local/var/postgres stop