A Couple of Usefule Snippets When Working with Textmate
Here is the snippet
f path/to/directory 'search string' | open_in_mate
This snippet (technically 2 snippets) will recursively scan the contents of files in a directory and then open all the files it finds in Textmate.
It's useful on large projec...
Written by Sean Behan on 10/18/2013
Roll Your Own Full Page Caching in Sinatra
It's as simple as this.
# app.rb
get '/:slug' do
@slug = File.basename("#{params[:slug]}")
@cache = "public/cache/#{@slug}.html"
if File.exists?(@cache)
File.read(@cache)
else
@post = Post.find_by(page: params[:slug])
...
Written by Sean Behan on 08/23/2013
Trigrams, Bigrams and Ngrams in Python for Text Analysis
Creating trigrams in Python is very simple
trigrams = lambda a: zip(a, a[1:], a[2:])
trigrams(('a', 'b', 'c', 'd', 'e', 'f'))
# => [('a', 'b', 'c'), ('b', 'c', 'd'), ('c', 'd', 'e'), ('d', 'e', 'f')]
You can generalize this a little bit more
...
Written by Sean Behan on 03/06/2017
How to import CSV into SQLite3
To import a CSV file into SQLite is easy.
sqlite3 my.db
.mode csv
.import path/to/file.csv name_of_table
And done.
Written by Sean Behan on 12/03/2017
salmon salad at home
Written by Sean Behan on 06/17/2012