Skip to content

Instantly share code, notes, and snippets.

View MollsReis's full-sized avatar

Molly Reis MollsReis

View GitHub Profile
@MollsReis
MollsReis / rbo.sql
Last active January 17, 2019 18:13
Rank Biased Overlap (Base) implementation (plpgsql)
DROP FUNCTION IF EXISTS f_intersect;
CREATE OR REPLACE FUNCTION f_intersect(a ANYARRAY, b ANYARRAY)
RETURNS ANYARRAY AS $$
BEGIN
-- TODO ensure a and b are the same length
RETURN ARRAY(SELECT UNNEST(a) INTERSECT SELECT UNNEST(b));
END;
$$ LANGUAGE plpgsql;
DROP FUNCTION IF EXISTS f_overlap;
@MollsReis
MollsReis / rbo.js
Last active January 17, 2019 18:13
Rank Biased Overlap (Base) implementation (javascript)
// http://blog.mobile.codalism.com/research/papers/wmz10_tois.pdf
// used for a list of 50 items
const P_VALUE = 0.8;
export const intersection = (a, b) => a.filter(x => b.indexOf(x) > -1);
export const overlap = (a, b) => intersection(a, b).length;
export const agreement = (a, b) => overlap(a, b) / a.length;
@MollsReis
MollsReis / .babelrc
Last active May 23, 2021 05:35
Preact docker-compose boilerplate
{
"presets": ["env", "stage-2"],
"plugins": [
["transform-react-jsx", { "pragma": "h" }]
]
}
@MollsReis
MollsReis / clean_local.sh
Created May 25, 2017 18:12
Remove merged local branches
git branch --merged | egrep -v "(^\*|master)" | xargs git branch -d
@MollsReis
MollsReis / crontab
Created March 8, 2017 22:17
PostgreSQL automated dumps (and cleanup)
# m h dom mon dow command
0 0 * * * pg_dump DATABASENAME > $(date "+%b_%d_%Y").bak
0 1 * * * find ~/*.bak -mtime +10 -type f -delete
@MollsReis
MollsReis / counter.html
Last active February 21, 2017 21:16
CSS counter
<span class="counter">1</span>
<span class="counter">2</span>
<span class="counter">3</span>
<span class="counter">4</span>
<span class="counter">5</span>
@MollsReis
MollsReis / every-x-frames.md
Last active August 19, 2016 20:36
Grab every X frames from a video with ffmpeg

Download ffmpeg from here (ffmpeg is also available via brew)

Use the following bash command:

$ ffmpeg -i <videofile> -vf fps=1/10 frame%04d.png

Notes on this command:

  • Replace <videofile> with the path to the video file you wish to process
  • fps=1/10 is the frames per second (grab one frame every ten seconds)
@MollsReis
MollsReis / names.rb
Last active March 24, 2016 00:16
Name generation using Markov chains
# example list of names generated from http://listofrandomnames.com/
# tweakable values
PREFIX = 3
MAX_LENGTH = 30
MIN_WORDS = 2
MAX_WORDS = 3
# create dictionary from corpus of names
dict = Hash.new { |h,k| h[k] = [] }
@MollsReis
MollsReis / mac_install.sh
Last active August 1, 2016 18:32
Install OpenCV for MacOS with Python 3.4 + VirtulEnv
#!/usr/bin/env bash
# this script will download, configure, compile, and install opencv for macos with python 3.4 using a virtualenv
# instructions are from http://www.pyimagesearch.com/2015/06/29/install-opencv-3-0-and-python-3-4-on-osx/
# you need git, homebrew, and a virtualenv with python 3.4
# grab prereqs
brew install cmake pkg-config jpeg libpng libtiff openexr eigen tbb ffmpeg
# grab opencv source
@MollsReis
MollsReis / mnb.rb
Created January 21, 2016 22:54
Multinomial Naive Bayes for a bag of words
class MNB
def initialize(examples)
@examples = examples.map { |ex| [ex.first.gsub(/[^a-zA-Z]/, ' ').downcase.split, ex.last] }
@buckets = @examples.map { |ex| ex.last }.uniq
@vocab_size = @examples.map { |ex| ex.first }.flatten.uniq.count
@prob_bucket = Hash.new do |hash, bucket|
hash[bucket] = @examples.count { |ex| ex.last == bucket } / @examples.count.to_f
end
@prob_word_given_bucket = Hash.new do |hash, word_bucket|
word, bucket = word_bucket.split('__')