Skip to content

Instantly share code, notes, and snippets.

View EvilScott's full-sized avatar

Molly Reis EvilScott

View GitHub Profile
@EvilScott
EvilScott / my_parser.rb
Created April 22, 2014 07:37
An example grammar/parser using the Ruby gem Treetop
require 'treetop'
module Mine
class IntegerLiteral < Treetop::Runtime::SyntaxNode
def to_i
text_value.to_i
end
end
@EvilScott
EvilScott / start.sh
Created November 14, 2014 19:31
Express + Forever start script
#!/bin/sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
"$DIR/node_modules/.bin/forever" start \
--watch --watchDirectory ${DIR} \
--watchIgnore "$DIR/.*/*" \
--watchIgnore "$DIR/public/*" \
--watchIgnore "$DIR/logs/*" \
--append -l "$DIR/logs/app.log" \
--minUptime 1000 \
--spinSleepTime 1000 \
@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 / 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 / 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 / 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 / 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 / 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: