Skip to content

Instantly share code, notes, and snippets.

@rmoorman
rmoorman / jekyll.hs
Created April 18, 2012 07:00 — forked from jaspervdj/jekyll.hs
Jekyll-like hakyll config. Haven't actually tested it, I need sleep.
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
import Hakyll
import Control.Arrow ((>>>))
main :: IO ()
main = hakyll $ do
-- Favicon
match "favicon.ico" copy
@rmoorman
rmoorman / guestbook.markdown
Created July 29, 2012 18:52 — forked from nikic/guestbook.markdown
Quick doesn't have to mean dirty: Also applies to PHP!

Quick doesn't have to mean dirty: Also applies to PHP!

This is just a quick response to http://me.veekun.com/blog/2012/07/28/quick-doesnt-mean-dirty/. I won't bother to write a proper blog post for this, so a Gist will have to do ;)

When I read that article, one thing really striked me: If you want to quickly create a web app in PHP, you do exactly the same. I mean, exactly.

I never used the Silex microframework before, so I took this as a chance to see how it works. I'll just do the same as eevee did, only with a bit less commentary (this is a Gist after all!)

I hope that this will show you that PHP and Python are really similar to work with. Also this should show that just because you're using PHP, doesn't mean that you write dirty code. The similarity in the process and code is really incredible :)

@rmoorman
rmoorman / install-ghc-cabal.md
Created November 22, 2012 10:28 — forked from ion1/install-ghc.md
Installing GHC and Cabal under the home directory

Installing GHC and Cabal under the home directory

  1. Install libgmp-dev libgmp3c2 or equivalent using the system package manager.
  2. Add export PATH="$HOME/.ghc/bin:$HOME/.cabal/bin:$PATH" to your .<shell>rc.
  3. Also run the command above now.
  4. Get the [GHC binary tarball][ghc] and extract it.
  5. ./configure --prefix="$HOME/.ghc" && make install
  6. Get the [cabal-install source tarball][cabal] and extract it.
  7. EXTRA_CONFIGURE_OPTS=-p sh bootstrap.sh
  8. cabal update
@rmoorman
rmoorman / steam_bootstrap.sh
Created December 9, 2012 18:22 — forked from grindars/steam_bootstrap.sh
Steam installer for Debian
#!/bin/bash
#
# Steam installer for Debian wheezy (32- and 64-bit)
#
# Place into empty directory and run.
#
download() {
local url="$1"
local filename="$(basename "$url")"
/*
* jQuery.ajaxQueue - A queue for ajax requests
*
* (c) 2011 Corey Frang
* Dual licensed under the MIT and GPL licenses.
*
* Requires jQuery 1.5+
*/
(function(a){var b=a({});a.ajaxQueue=function(c){function g(b){d=a.ajax(c).done(e.resolve).fail(e.reject).then(b,b)}var d,e=a.Deferred(),f=e.promise();b.queue(g),f.abort=function(h){if(d)return d.abort(h);var i=b.queue(),j=a.inArray(g,i);j>-1&&i.splice(j,1),e.rejectWith(c.context||c,[f,h,""]);return f};return f}})(jQuery)
@rmoorman
rmoorman / pr.md
Created March 26, 2013 20:35 — forked from piscisaureus/pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

#Deploy and rollback on Heroku in staging and production
task :deploy_staging => ['deploy:set_staging_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
task :deploy_production => ['deploy:set_production_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
namespace :deploy do
PRODUCTION_APP = 'YOUR_PRODUCTION_APP_NAME_ON_HEROKU'
STAGING_APP = 'YOUR_STAGING_APP_NAME_ON_HEROKU'
task :staging_migrations => [:set_staging_app, :push, :off, :migrate, :restart, :on, :tag]
task :staging_rollback => [:set_staging_app, :off, :push_previous, :restart, :on]

Virtualenv's bin/activate is Doing It Wrong

I'm a Python programmer and frequently work with the excellent [virtualenv][] tool by Ian Bicking.

Virtualenv is a great tool on the whole but there is one glaring problem: the activate script that virtualenv provides as a convenience to enable its functionality requires you to source it with your shell to invoke it. The activate script sets some environment variables in your current environment and defines for you a deactivate shell function which will (attempt to) help you to undo those changes later.

This pattern is abhorrently wrong and un-unix-y. activate should instead do what ssh-agent does, and launch a sub-shell or sub-command with a modified environment.

Problems

Build your own private, encrypted, open-source Dropbox-esque sync folder

Prerequisites:

  • One or more clients running a UNIX-like OS. Examples are given for Ubuntu 12.04 LTS, although all software components are available for other platforms as well (e.g. OS X). YMMV
  • A cheap Ubuntu 12.04 VPS with storage. I recommend Backupsy, they offer 250GB storage for $5/month. Ask Google for coupon codes.

Software components used:

  • Unison for file synchronization
  • EncFS for folder encryption
# -*- coding: utf-8 -*-
from sqlalchemy.exc import IntegrityError
from sqlalchemy.sql.expression import ClauseElement
def _get_or_create(session, model, defaults=None, **kwargs):
try:
query = session.query(model).filter_by(**kwargs)
instance = query.first()