Skip to content

Instantly share code, notes, and snippets.

@tarnacious
tarnacious / parse.hs
Created September 30, 2013 13:49
While writing the same parser in JavaScript and Haskell I found these two snippets illustrated to me why monads and do syntax are awesome.
piece :: Parser Piece
piece = do
many space
t <- pieceType
c <- pieceColour
return $ Piece t c
@tarnacious
tarnacious / gist:6270193
Created August 19, 2013 15:07
Some initial setup to my macbook air. I need to do it twice, so wrote it down to make it quicker.
Download + Install Firefox in English (http://www.mozilla.org/en-US/firefox/all/)
Download + Install XCode and XCode command line tools. (https://developer.apple.com/downloads/)
Download + Install ITerm2
Download Solarized.
Install Solarized for ITerm2: http://michaelheap.com/solarized-with-iterm2/
Download + Install Chrome in English (https://www.google.com/intl/en/chrome/)
Install homebrew http://brew.sh/
brew install vim
brew install tmux
brew install wget
@tarnacious
tarnacious / tarnbarfordnet
Created February 18, 2013 11:54
Simple nginx config (/etc/nginx/sites-enabled/tarnbarfordnet) for a reverse proxy to a Flask app running on localhost:8000 and to serve the static files directly though nginx.
upstream tarnbarfordnet {
server localhost:8000;
}
server {
root /usr/share/nginx/www;
index index.html index.htm;
server_name localhost;
@tarnacious
tarnacious / gist:4608177
Created January 23, 2013 15:31
Notes on using Python bolts / spouts in Storm
We encountered some issues using python processes with storm.
1) Storm uses the stdin and stdout of the python processes to communicate with them. This makes them almost impossible to debug with pdb.set_trace().
2) The local topology (and the real storm to a lesser extent) has issues killing the Python processes it creates. Some of our rouge processes pin the CPU. I find myself running something like this on my local machine.
ps aux | grep python | awk '{ print $2 }' | xargs kill
3) We didn't want to install python packages in the system packages because it adds dependencies on the system storm is running on and we also have different topologies with different bolts that depend of different versions of packages. We install the dependencies (with buildout or virtualenv) in a relative path before creating the uberjar and deploying it, or you can also make the script storm calls a shell script that installs the dependencies locally then runs the python entry point. Either way, it is a little painful, espe
***
***
* *********
**************
***************
******************
***** ******************
***************************
**************************************
@tarnacious
tarnacious / myview.js.coffee
Created March 7, 2012 07:34
backbone example - serialize form + update on change
window.MyView = Backbone.View.extend({
initialize: ->
_.bindAll(this,'render')
this.template = window.JST["MyView"]
this.model.bind('change', this.render)
render: ->
$(this.el).html(this.template(this.model.toJSON()))
events: {
@tarnacious
tarnacious / helpers.cs
Created December 20, 2011 00:20
Quick hack to validate a facebook javascript api auth cookie on the server.
public bool Authenticate()
{
var FacebookAppId = ConfigurationManager.AppSettings["FACEBOOK_APPID"];
var FacebookAppSecret = ConfigurationManager.AppSettings["FACEBOOK_SECRET"];
var cookie = Request.Cookies["fbs_" + FacebookAppId];
if (cookie == null) return false;
@tarnacious
tarnacious / DashRss.ascx
Created November 29, 2011 04:45
More good times with Umbraco
// Good times with Umbraco. This time with the broken link checker plug-in (http://our.umbraco.org/projects/developer-tools/broken-link-checker)
// To be fair I think these problems are mainly due to changes in Umbraco > 4.0.
//
// I wouldn't recommend using the plugin, but I had to put in this hacky fix it for a client who wanted to use it.
//
// Firstly it tries to download some javascript from here:
// http://localhost:50812/umbraco/~/umbraco/plugins/FergusonMoriyama/DashRss/dashrss.js
//
// When the location of the file is:
// http://localhost:50812/umbraco/plugins/FergusonMoriyama/DashRss/dashrss.js
@tarnacious
tarnacious / search.cs
Created November 28, 2011 06:47
Searching for multiple terms using the Umbraco Examine API.
// This seems way too difficult for what you would expect to be a pretty common task;
// taking a search string from the user and finding documents which contain some or all of the terms
// in the search string.
// This function naively splits a search string into terms and finds documents
// which contain some or all of the terms. Does not handle quoted terms as or ignore case as it should.
public IEnumerable<SearchResult> Search(string searchString, string[] fields)
{
// Spit the search string and return an empty list if no search string was provided.
if (string.IsNullOrEmpty(searchString)) return new List<SearchResult>();
@tarnacious
tarnacious / tdb.hs
Created November 24, 2011 22:50
tdb
$ ghci
GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help
Prelude> let make = (\a b -> take b (repeat a))
Prelude> ("abc",123) `make` 3
[("abc",123),("abc",123),("abc",123)]