Skip to content

Instantly share code, notes, and snippets.

View EvilScott's full-sized avatar

Molly Reis EvilScott

View GitHub Profile
@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 / 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 / .gitconfig
Created January 10, 2014 16:29
Git Config
[user]
email = <YOUR EMAIL>
name = <YOUR NAME>
[color]
diff = auto
status = auto
branch = auto
interactive = auto
ui = true
@EvilScott
EvilScott / .bash_profile
Last active December 20, 2015 16:18
git prompt
source ~/git-prompt.sh
source ~/git-completion.bash
PS1='\u:\w\[\033[32m\]$(__git_ps1)\[\033[0m\]$ '
@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 / longpoll.rb
Created November 27, 2012 17:23
example of long polling using sinatra and jquery
require 'json'
require 'haml'
require 'sinatra'
get '/' do
haml :view
end
get '/request' do
content_type :json
@EvilScott
EvilScott / session_fun.rb
Created April 25, 2012 20:28
Guessing game fun using sessions with Sinatra
require 'sinatra'
require 'haml'
require 'json'
enable :sessions
get '/' do
session[:answer] = %w[A B C D].sample
haml :index
end
@EvilScott
EvilScott / jimson-sinatra.rb
Created April 11, 2012 15:33
Jimson and Sinatra playing together
require 'sinatra'
require 'jimson'
class Api
extend Jimson::Handler
def get_data
{'foo' => 'bar'}
end
end
@EvilScott
EvilScott / apprunner.rb
Created February 13, 2012 22:44
Use Sinatra to open a browser window (and close Sinatra when the window closes)
%w[sinatra watir-webdriver].each { |gem| require gem }
class MyApp < Sinatra::Base
get('/') { "hello world" }
end
class AppRunner
def initialize
@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