Skip to content

Instantly share code, notes, and snippets.

View EvilScott's full-sized avatar

Molly Reis EvilScott

View GitHub Profile
@EvilScott
EvilScott / image_resizer.rb
Created April 20, 2012 19:54
Image processing server using Sinatra and MiniMagick
require 'mini_magick'
class ImageResizer
attr_accessor :height, :width, :padding, :stretch, :grayscale
def initialize(path)
@image = MiniMagick::Image.open(path)
end
@EvilScott
EvilScott / .babelrc
Last active May 23, 2021 05:35
Preact docker-compose boilerplate
{
"presets": ["env", "stage-2"],
"plugins": [
["transform-react-jsx", { "pragma": "h" }]
]
}
@EvilScott
EvilScott / diagonals.rb
Created February 6, 2012 23:04
Retrieve diagonals from array of arrays in Ruby
class Array
def diagonals
[self, self.map(&:reverse)].inject([]) do |all_diags, matrix|
((-matrix.count + 1)..matrix.first.count).each do |offet_index|
diagonal = []
(matrix.count).times do |row_index|
col_index = offet_index + row_index
diagonal << matrix[row_index][col_index] if col_index >= 0
end
all_diags << diagonal.compact if diagonal.compact.count > 1
@EvilScott
EvilScott / 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;
@EvilScott
EvilScott / 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;
@EvilScott
EvilScott / clean_local.sh
Created May 25, 2017 18:12
Remove merged local branches
git branch --merged | egrep -v "(^\*|master)" | xargs git branch -d
@EvilScott
EvilScott / 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
@EvilScott
EvilScott / 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>
@EvilScott
EvilScott / 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)
@EvilScott
EvilScott / 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