Skip to content

Instantly share code, notes, and snippets.

View EvilScott's full-sized avatar

Molly Reis EvilScott

View GitHub Profile
@EvilScott
EvilScott / words.rb
Created January 12, 2015 20:39
Word generation using markov chains
prefix = (ARGV[0] || 2).to_i
words = (ARGV[1] || 5).to_i
corpus = `cat /usr/share/dict/words`.downcase
dict = Hash.new { |h,k| h[k] = [] }
corpus.split("\n").each do |word|
chars = "#{word} ".chars.to_a
until chars.length < (prefix + 1) do
dict[chars.first(prefix).join] << chars[prefix]
chars.shift
@EvilScott
EvilScott / edit-inline.html
Last active August 29, 2015 14:13
Angular Inline Editing Directive
<div class="edit-inline">
<span ng-show="editing">
<input type="text" ng-model="text" />
<button ng-click="editing = false">Save</button>
</span>
<span ng-hide="editing">
<span ng-bind="text"></span>
<button ng-click="editing = true">Edit</button>
</span>
</div>
@EvilScott
EvilScott / prim_graph.rb
Created February 4, 2015 02:11
Animated Implementation of Prim's Algorithm in Ruby + JS/Canvas
# R. Scott Reis - Implementation of Prim's Algorithm
# http://en.wikipedia.org/wiki/Prim%27s_algorithm
require 'sinatra'
require 'haml'
require 'json'
module Prim
class << self
def get_graph
@EvilScott
EvilScott / words.py
Last active December 14, 2015 18:52
Word generation using markov chains
from sys import argv
from collections import defaultdict
from random import choice
class DefaultList(list):
def __getitem__(self, idx):
try:
return super().__getitem__(idx)
except IndexError:
@EvilScott
EvilScott / 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('__')
@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
@EvilScott
EvilScott / 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] = [] }
@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 / 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 / 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