Skip to content

Instantly share code, notes, and snippets.

package main
import (
"bufio"
"fmt"
"math/rand"
"os"
"sort"
"strconv"
"strings"
┌───────────────────┐ ┌────────────────────────┐
┌────────────────────│ Clearing │──────┘ ┌───────────────┐ │
│ └───────────────────┘ │ Up a Tree │ │
│ ║ │ └───────────────┘ │
│ Down │ │ │ ┌────────────────────────┐
│ ║ │ ┌──────────────────┘ ┌────────┘ │ │
│ │ │ Up/Down │ │ │
│ │ │ ▼ ▼ ┌─────────────────────┐
┌──────────────┐ ┌──────────────────────┐ ┌─────────────────────────┐ │ Forest 3 │
│ │───────────│ Forest Path │────────│ Forest 2 │───────────│impassible mountains │
@leklund
leklund / tweetgen.html
Created June 4, 2015 19:19
Generate Tweet Intent URL
<!DOCTYPE html>
<html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<title>twitter link gen</title>
<script>
$(function() {
$("#twtgen").submit(function() {
@leklund
leklund / gist:f7171eede07a1ed41a59
Last active August 29, 2015 14:21
Recursive query for member network
-- Get a network of members for a given member with a seperation distance.
-- In this example I've named the degree of seperation depth.
-- pid: petition_id
-- mid: member_id
-- in the real world there there woudl be a unique constraint on (pid,mid)
CREATE TABLE signatures (pid integer, mid integer);
-- populate some signatures
@leklund
leklund / node.rb
Created April 29, 2015 15:03
adjacency list modeling
class Node
attr_accessor :id, :name, :parent, :children
def initialize(opts = {})
@id = opts[:id]
@name = opts[:name]
@parent = opts[:parent]
# add children if passed an array or initialize as an empty array
@children = opts[:children].is_a?(Array) ? opts[:children] : []
@leklund
leklund / tagged_with_1.md
Last active August 29, 2015 13:57
tagged_with bug

The model:

class Content < ActiveRecord::Base
  acts_as_taggable
end

created with:

@leklund
leklund / verification_functions.sql
Created August 6, 2013 14:41
some verification functions for sqitch verify scripts.
-- select public.verify_index_exists('index','schema',true);
CREATE OR REPLACE FUNCTION public.verify_index_exists(IN _index VARCHAR, IN _schema VARCHAR, IN _throws_error BOOLEAN DEFAULT TRUE)
RETURNS BOOLEAN AS
$$
BEGIN
IF NOT EXISTS (SELECT relname FROM pg_class c, pg_namespace n WHERE c.relnamespace = n.oid AND relname = $1 AND nspname = $2 AND relkind = 'i') THEN
IF $3 THEN
RAISE 'no such index % on schema %', $1, $2;
ELSE
RETURN FALSE;
@leklund
leklund / 1 - nginx.conf.erb
Created June 27, 2013 15:27
simple conf for a static site on heroku using nginx with this buildpack: https://github.com/neilmiddleton/heroku-buildpack-nginx. File structure: app/conf/nginx.conf.erb app/conf/mime.types app/html/index.html
worker_processes 4;
daemon off;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
@leklund
leklund / db_create_schema.rake
Created December 13, 2012 21:34
How to create a schema other than public when running rake db:setup. This will allow you to include a schema_searth_path in database.yml without causing rake db:setup to fail.
SCHEMA_NAMES = %w(foo bar)
namespace :db do
task :create do
config = Rails.configuration.database_configuration[Rails.env].merge!({'schema_search_path' => 'public'})
ActiveRecord::Base.establish_connection(config)
SCHEMA_NAMES.each do |schema|
ActiveRecord::Base.connection.execute("CREATE SCHEMA #{schema}")
end
end
end
@leklund
leklund / game.pl
Created October 30, 2011 23:51
Rock, paper, scissors, spock, lizard in Perl Dancer
#!/usr/bin/env perl
use Dancer;
hook 'before'=> sub {
header('Content-Type' => 'text/plain');
my $throwmap= {
rock => { scissors => 'rock smashes scissors',
lizard => 'rock crushes lizard'},
paper => { rock => 'paper covers rock',
spock => 'paper disproves spock'},