Skip to content

Instantly share code, notes, and snippets.

View brendte's full-sized avatar

Brendten Eickstaedt brendte

View GitHub Profile
@brendte
brendte / index-and-query.rb
Created February 5, 2013 16:15
Complete index and query solution. Naively implemented with nested loops.
#!/usr/bin/ruby
require 'rubygems'
require 'fast_stemmer'
def doc_prep(docs)
prepped_docs = {}
doc_id = 0
stop_words = "a,able,about,across,after,all,almost,also,am,among,an,and,any,are,as,at,be,because,been,but,by,can,cannot,could,dear,did,do,does,either,else,ever,every,for,from,get,got,had,has,have,he,her,hers,him,his,how,however,i,if,in,into,is,it,its,just,least,let,like,likely,may,me,might,most,must,my,neither,no,nor,not,of,off,often,on,only,or,other,our,own,rather,said,say,says,she,should,since,so,some,than,that,the,their,them,then,there,these,they,this,tis,to,too,twas,us,wants,was,we,were,what,when,where,which,while,who,whom,why,will,with,would,yet,you,your,use,used".split(',')
@brendte
brendte / build_inverted_index.rb
Created February 5, 2013 02:42
This builds on and refactors sentence-prep.rb, yielding an inverted index for a list of documents passed in as string arguments on the command line.
#!/usr/bin/ruby
require 'rubygems'
require 'fast_stemmer'
def doc_prep(docs)
prepped_docs = {}
doc_id = 0
stop_words = "a,able,about,across,after,all,almost,also,am,among,an,and,any,are,as,at,be,because,been,but,by,can,cannot,could,dear,did,do,does,either,else,ever,every,for,from,get,got,had,has,have,he,her,hers,him,his,how,however,i,if,in,into,is,it,its,just,least,let,like,likely,may,me,might,most,must,my,neither,no,nor,not,of,off,often,on,only,or,other,our,own,rather,said,say,says,she,should,since,so,some,than,that,the,their,them,then,there,these,they,this,tis,to,too,twas,us,wants,was,we,were,what,when,where,which,while,who,whom,why,will,with,would,yet,you,your,use,used".split(',')
@brendte
brendte / sentence-prep.rb
Last active December 12, 2015 03:38
Prep docs for indexing: remove stop words and punctuation, downcase, and stem (with fast_stemmer gem, a Ruby implementation of Porter's stemming algorithm)
#!/usr/bin/ruby
require 'rubygems'
require 'fast_stemmer'
stop_words = "a,able,about,across,after,all,almost,also,am,among,an,and,any,are,as,at,be,because,been,but,by,can,cannot,could,dear,did,do,does,either,else,ever,every,for,from,get,got,had,has,have,he,her,hers,him,his,how,however,i,if,in,into,is,it,its,just,least,let,like,likely,may,me,might,most,must,my,neither,no,nor,not,of,off,often,on,only,or,other,our,own,rather,said,say,says,she,should,since,so,some,than,that,the,their,them,then,there,these,they,this,tis,to,too,twas,us,wants,was,we,were,what,when,where,which,while,who,whom,why,will,with,would,yet,you,your,use,used".split(',')
unstemmed_words = ARGV[0].gsub(/[[:punct:]]/, '').downcase.split.select { |x| !stop_words.include?(x) }
stemmed_words = []
unstemmed_words.each { |x| stemmed_words << x.stem }
puts stemmed_words.join(' ')
@brendte
brendte / customTabsIniOS.js
Created April 3, 2012 03:28 — forked from dawsontoth/app.js
Customize the look of the tab bar in iOS Appcelerator Titanium
/**
* Override a tab group's tab bar on iOS.
*
* NOTE: Call this function on a tabGroup AFTER you have added all of your tabs to it! We'll look at the tabs that exist
* to generate the overriding tab bar view. If your tabs change, call this function again and we'll update the display.
*
* @param tabGroup The tab group to override
* @param backgroundOptions The options for the background view; use properties like backgroundColor, or backgroundImage.
* @param selectedOptions The options for a selected tab button.
* @param deselectedOptions The options for a deselected tab button.
@brendte
brendte / layout.haml
Created December 21, 2011 17:33
Paul Irish conditional-stylesheets-vs-css-hacks-answer-neither in haml
!!! 5
/ paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
/[if lt IE 7]
<html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en">
/[if IE 7]
<html class="no-js lt-ie9 lt-ie8" lang="en">
/[if IE 8]
<html class="no-js lt-ie9" lang="en">
/[if gt IE 8]
<!--> <html lang="en"> <!--