Skip to content

Instantly share code, notes, and snippets.

Avatar

Robert Scott Reis EvilScott

View GitHub Profile
@EvilScott
EvilScott / rbo.sql
Last active Jan 17, 2019
Rank Biased Overlap (Base) implementation (plpgsql)
View rbo.sql
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;
@EvilScott
EvilScott / rbo.js
Last active Jan 17, 2019
Rank Biased Overlap (Base) implementation (javascript)
View rbo.js
// 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;
@EvilScott
EvilScott / .babelrc
Last active Jun 24, 2018
Preact docker-compose boilerplate
View .babelrc
{
"presets": ["env", "stage-2"],
"plugins": [
["transform-react-jsx", { "pragma": "h" }]
]
}
@EvilScott
EvilScott / clean_local.sh
Created May 25, 2017
Remove merged local branches
View clean_local.sh
git branch --merged | egrep -v "(^\*|master)" | xargs git branch -d
@EvilScott
EvilScott / crontab
Created Mar 8, 2017
PostgreSQL automated dumps (and cleanup)
View crontab
# 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
View counter.html
<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>
@EvilScott
EvilScott / every-x-frames.md
Last active Aug 19, 2016
Grab every X frames from a video with ffmpeg
View every-x-frames.md

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)
@EvilScott
EvilScott / names.rb
Last active Mar 24, 2016
Name generation using Markov chains
View names.rb
# 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] = [] }
@EvilScott
EvilScott / mac_install.sh
Last active Aug 1, 2016
Install OpenCV for MacOS with Python 3.4 + VirtulEnv
View mac_install.sh
#!/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
@EvilScott
EvilScott / mnb.rb
Created Jan 21, 2016
Multinomial Naive Bayes for a bag of words
View mnb.rb
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('__')
You can’t perform that action at this time.