Skip to content

Instantly share code, notes, and snippets.

@kamiller
kamiller / validate_json.sh
Created July 25, 2012 19:09
validate json with python via bash script
echo '{"foo":"bar"}' | python -m json.tool >> /dev/null && exit 0 || echo "NOT valid JSON"; exit 1
@kamiller
kamiller / pandoc.sh
Created July 20, 2012 15:57
pandoc dependencies and usage
sudo apt-get install texlive-latex-base
sudo apt-get install texlive-latex-base
pandoc input.md --toc -o output.pdf
@kamiller
kamiller / rsync.py
Created November 1, 2012 21:40
python rsync impl
## {{{ http://code.activestate.com/recipes/577518/ (r4)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This is a pure Python implementation of the [rsync algorithm](TM96).
[TM96] Andrew Tridgell and Paul Mackerras. The rsync algorithm.
Technical Report TR-CS-96-05, Canberra 0200 ACT, Australia, 1996.
http://samba.anu.edu.au/rsync/.
@kamiller
kamiller / draw_rounded.py
Created June 28, 2012 20:07
python rounded rectangle using cairo and arc
def draw_rounded(cr, area, radius):
""" draws rectangles with rounded (circular arc) corners """
from math import pi
a,b,c,d=area
cr.arc(a + radius, c + radius, radius, 2*(pi/2), 3*(pi/2))
cr.arc(b - radius, c + radius, radius, 3*(pi/2), 4*(pi/2))
cr.arc(b - radius, d - radius, radius, 0*(pi/2), 1*(pi/2)) # ;o)
cr.arc(a + radius, d - radius, radius, 1*(pi/2), 2*(pi/2))
cr.close_path()
cr.stroke()
@kamiller
kamiller / belkin_n300_router_tomato_setup.md
Created February 21, 2013 23:44
Belkin n300 share router tomato USB flash instructions

TomatoUSB Setup Guide

So, about those instructions. An important thing to know is that the model number of this router is F7D7302, which is just a newer version of the F7D3302. So when you're searching for firmware that's the model you want to use. Now, I've spent some time doing research to get this working with TomatoUSB and finally came with a pretty simple solution. I've noticed a lot of guides want you to install DD-WRT first, which is completely unnecessary.

The best version for this unit right now is the TomatoUSB builds from Toastman. While this may appear to be a lot of steps, it's really not all that complicated.

You're going to want two files for this procedure. Google "tomato toastman 4shared" to find the repository (it's hosted on a download site called 4shared). You'll be looking for the latest version in the RT (MIPSR2) folder (each version will be split into VLAN and STD versions, you'll want the STD one). Inside of that folder will be a bunch of .bin and .trx files. You'll want the .

Error: ssh-cleanup

(Usually occurs when running Vagrant Up (Evolution ​v1.3.16​) = Vagrant 1.6.5 Virtual Box 4.3)

There are errors in the configuration of this machine. Please fix
the following errors and try again:

vm:
* The 'ssh-cleanup' provisioner could not be found.
  • Upgrade to Vagrant 1.8.5+ & Virtual Box 5.1.2+
@kamiller
kamiller / rails_reporting_example.md
Last active December 27, 2015 06:39
Rails simple AR / Reporting example

For custom queries that require basically a whole custom SQL statement (your find above doesn't exactly abstract much from you) I like to set up a quick little new model that represents the new information. i.e.

class OperatingExpenseReportDatum
  attr_accessor :type, :heading, :total

  def initialize(row)
    # set values from row, like
    @total = row["total"].to_f
 end
@kamiller
kamiller / unicorn.sh
Created September 22, 2013 15:41
init.d script for rvm / unicorn
#!/bin/bash
### BEGIN INIT INFO
# Provides: APPLICATION
# Required-Start: $all
# Required-Stop: $network $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start the APPLICATION unicorns at boot
# Description: Enable APPLICATION at boot time.
### END INIT INFO
@kamiller
kamiller / escape_erb.md
Last active December 20, 2015 13:09
rails erb escape html

Use raw(string), as described in the release notes.

7.4.3 Other Changes

You no longer need to call h(string) to escape HTML output, it is on by default in all view templates. If you want the unescaped string, call raw(string).

Basically, where you did

<%=h @model.attr %>
#!/usr/lib/env ruby
# Acquires a shared lock on a SQLite database file and copies it to a backup
# usage: backup-db.rb DBFILE.db BACKUPFILE.db
# author: William Benton (willb@redhat.com)
# Public domain.
require 'sqlite3'
require 'fileutils'