Skip to content

Instantly share code, notes, and snippets.

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
source ~/perl5/perlbrew/etc/bashrc
export TERM="xterm-256color"
PS1='[\u@\h \W$(__docker_machine_ps1)]\$ '
[ -n "$PS1" ]
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/X11/bin:/Applications/Postgres.app/Contents/Versions/latest/bin:/usr/local/bin/mysql:${PATH}"
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
@dbkbali
dbkbali / AXH_Vector_Sum.sql
Created January 15, 2018 05:12 — forked from andrewxhill/AXH_Vector_Sum.sql
Sum PostgreSQL arrays in place [1,2,3] + [2,3,4] = [3,5,7]
CREATE AGGREGATE vector_sum (
sfunc = AXH_Vector_Sum,
basetype = int[],
stype = int[],
initcond = '{0}'
);
DROP FUNCTION IF EXISTS AXH_Vector_Sum(int[], int[]);
CREATE OR REPLACE FUNCTION AXH_Vector_Sum(int[], int[])
RETURNS int[] AS $$
@dbkbali
dbkbali / AXH_Vector_Sum.sql
Created January 15, 2018 05:12 — forked from andrewxhill/AXH_Vector_Sum.sql
Sum PostgreSQL arrays in place [1,2,3] + [2,3,4] = [3,5,7]
CREATE AGGREGATE vector_sum (
sfunc = AXH_Vector_Sum,
basetype = int[],
stype = int[],
initcond = '{0}'
);
DROP FUNCTION IF EXISTS AXH_Vector_Sum(int[], int[]);
CREATE OR REPLACE FUNCTION AXH_Vector_Sum(int[], int[])
RETURNS int[] AS $$
@dbkbali
dbkbali / db.rake
Created March 15, 2016 04:46 — forked from hopsoft/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
@dbkbali
dbkbali / dog.rb
Created February 17, 2016 04:21 — forked from shiroyasha/dog.rb
Method tracer for Ruby classes
class Dog
attr_writer :name
def initialize(name)
@name = name
end
def bark
puts "patrick"
end
@dbkbali
dbkbali / project_schema.txt
Created January 11, 2016 18:15
Project Schema
# == Schema Information
#
# Table name: projects
#
# id :integer not null, primary key
# site_url :string
# scrape_date :date
# scrape_page :integer
# project_url :string
# project_id :string
@dbkbali
dbkbali / repl.rb
Created January 10, 2016 00:43
Basic Psuedocode and Ruby for Creating a Repl
require "pry"
### REPL EXAMPLE
#
# ARGV array holds any additional parameters when the program is run
#
# STDIN.gets.chomp - waits for the user to input on the terminal
#
#
class SomeModel
include Mongoid::Document
field :date, :type => Date
validates_presence_of :date
def date=(value)
begin
date_parsed = value.to_date
write_attribute :date, date_parsed
require "bundler/capistrano"
set :port, XXXX
server "XX.XXX.XXX.XX", :web, :app, :db, primary: true
set :application, "XXXXXXX"
set :user, "XXXXXXX"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
@dbkbali
dbkbali / gist:5049781
Created February 27, 2013 17:28
Upgrade from Mongoid 3.0.23 to 3.1.2 causes test failure - need to reload other side of the relationship to get test to pass
[1] pry(#<Activity>)> activity
=> #<Activity _id: 512e3ef99a4b7cecef000005, created_at: 2013-02-27 17:14:33 UTC, updated_at: 2013-02-27 17:14:33 UTC, slug: {"en"=>"activity2", "id"=>"activity2"}, search_slug: {"en"=>""}, category_ids: ["512e3ef99a4b7cecef000006"], name: {"en"=>"activity2"}, position: nil, icon: nil>
[2] pry(#<Activity>)> activity.categories
=> [#<Category _id: 512e3ef99a4b7cecef000006, created_at: 2013-02-27 17:14:33 UTC, updated_at: 2013-02-27 17:14:33 UTC, slug: {"en"=>"category3", "id"=>"category3"}, search_slug: {"en"=>"category3", "id"=>"category3"}, parent_id: nil, activity_ids: ["512e3ef99a4b7cecef000005"], level: 0, name: {"en"=>"category3"}, description: nil, group: nil, classification: "Category", position: 1>]
[3] pry(#<Activity>)> category1
=> #<Category _id: 512e3ef99a4b7cecef000006, created_at: 2013-02-27 17:14:33 UTC, updated_at: 2013-02-27 17:14:33 UTC, slug: {"en"=>"category3", "id"=>"category3"}, search_slug: {"en"=>"category3", "id"=>"category3"}, parent_id: nil, activity_i