Skip to content

Instantly share code, notes, and snippets.

@squarism
squarism / bot.rb
Created November 21, 2011 15:41
bot reply test
$LOAD_PATH.unshift File.dirname(__FILE__) + "/lib"
require 'chatterbot/dsl'
require 'pokerthing'
exclude "http://" # block spam tweet
blacklist "jerkface, assbutt" # block jerks or self
#debug_mode true
@squarism
squarism / wikipedia.rb
Created November 21, 2011 16:35
Wikipedia mirroring in 10 lines
# we are going to intentionally use the vanilla mongo driver
require 'mongo'
require 'nokogiri'
require 'open-uri'
require 'active_support/core_ext' # from rails
include Mongo
pages = Connection.new('localhost', 27017).db('loadtest').collection('pages')
wikipedia_page = "http://en.wikipedia.org/wiki/Special:Export/Ford_Motor"
@squarism
squarism / bot.rb
Created November 26, 2011 06:00 — forked from muffinista/bot.rb
bot reply test
$LOAD_PATH.unshift File.dirname(__FILE__) + "/lib"
require 'chatterbot/dsl'
require 'pokerthing'
exclude "http://" # block spam tweet
blacklist "jerkface, assbutt" # block jerks or self
#debug_mode true
@squarism
squarism / cache.rb
Created November 30, 2011 15:32
ruby cache
# not exactly a pure cache, implements the lookup or expensive operation too
# probably needs to be decoupled
class Cache
def initialize
@cache = {}
end
def cache(name, values = {})
if values = {}
@squarism
squarism / rbenv_profile.sh
Created December 2, 2011 15:00
sstephenson's prompt from rbenv README
# sstephenson's prompt from rbenv
# - Set your Terminal.app theme to Basic
# - Set your Terminal.app font to 13pt Inconsolata
# - Set your ANSI Color for Normal White(7) to Tin (Crayons tab in color picker)
# - Put this at the end of your .profile
# - Help me figure out what his exact font is because it's not Inconsolata.
function parse_git_dirty {
[[ $(git status 2> /dev/null \
@squarism
squarism / obfuscation.ruby
Created December 6, 2011 15:27
Anyone can bang on the keyboard
!!!!!!!!0[0].+(2)[0][2e2].^(6).%(4)#| <('-'<) Kirby loves trolling?
# => true
@squarism
squarism / url_tmp_open.rb
Created December 12, 2011 15:44
Tempfile URL block open
require 'tempfile'
require 'open-uri'
url = "http://www.kernel.org/pub/linux/kernel/v3.x/ChangeLog-3.1"
tmp = Tempfile.new('foo')
# while this is running in irb, check out /tmp/foo*
open(url) do |f|
f.each_line {|line| tmp.write line}
end
@squarism
squarism / rejectless.rb
Created December 12, 2011 19:23
Reject without reject
a = [10, 20, 30, 40, 50]
# each stage along the way:
# >> a.each_with_index.collect {|value,index| {index => value <= 30} }
# => [{0=>true}, {1=>true}, {2=>true}, {3=>false}, {4=>false}]
#
# .select {|h| h.invert.has_key?(false) }
# => [{3=>false}, {4=>false}]
#
# .collect {|h| h.keys}.flatten
@squarism
squarism / nlp_playtime.rb
Created December 19, 2011 19:29
nlp_playtime_1
# need jruby
# need stanford-corenlp in a directory somewhere
# untar it, cd into it
# irb innvocation for more memory happy:
# jruby -J-Xmn512m -J-Xms2048m -J-Xmx2048m -J-server -S irb
require 'java'
require 'stanford-corenlp-2011-09-16.jar'
require 'stanford-corenlp-2011-09-14-models.jar'
@squarism
squarism / nlp_playtime_2.rb
Created December 19, 2011 21:35
nlp_playtime_2
# Instructions for OSX likely to be brew install based, have not tried
# $ sudo apt-get install libtool
# $ sudo aptitude install liblink-grammar4-dev
# runs on regular ruby not jruby-1.6.5 (tested)
# $ gem install linkparser
# set putty or whatever to width of 128
dict = LinkParser::Dictionary.new( :screen_width => 128 )
sent = dict.parse( "People use your mom for all kinds of nifty things." )