Skip to content

Instantly share code, notes, and snippets.

View gist:9e0fc8c9744c84ed924368dd5df4e400
┌───────────────────┐ ┌────────────────────────┐
┌────────────────────│ Clearing │──────┘ ┌───────────────┐ │
│ └───────────────────┘ │ Up a Tree │ │
│ ║ │ └───────────────┘ │
│ Down │ │ │ ┌────────────────────────┐
│ ║ │ ┌──────────────────┘ ┌────────┘ │ │
│ │ │ Up/Down │ │ │
│ │ │ ▼ ▼ ┌─────────────────────┐
┌──────────────┐ ┌──────────────────────┐ ┌─────────────────────────┐ │ Forest 3 │
│ │───────────│ Forest Path │────────│ Forest 2 │───────────│impassible mountains │
@leklund
leklund / tweetgen.html
Created Jun 4, 2015
Generate Tweet Intent URL
View tweetgen.html
<!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 Aug 29, 2015
Recursive query for member network
View gist:f7171eede07a1ed41a59
-- 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 Apr 29, 2015
adjacency list modeling
View node.rb
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 Aug 29, 2015
tagged_with bug
View tagged_with_1.md

The model:

class Content < ActiveRecord::Base
  acts_as_taggable
end

created with:

@leklund
leklund / verification_functions.sql
Created Aug 6, 2013
some verification functions for sqitch verify scripts.
View verification_functions.sql
-- 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 Jun 27, 2013
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
View 1 - nginx.conf.erb
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 Dec 13, 2012
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.
View db_create_schema.rake
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 Oct 30, 2011
Rock, paper, scissors, spock, lizard in Perl Dancer
View game.pl
#!/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'},
@leklund
leklund / game.rb
Created Oct 30, 2011
Rock, paper, scissors, lizard, spock in Sinatra
View game.rb
require 'sinatra'
# before we process a route, we'll set the response as
# plain text and set up an array of viable moves that
# a player (and the computer) can perform
before do
content_type :txt
@defeat = {
rock: [:scissors, :lizard],
paper: [:rock, :spock],
You can’t perform that action at this time.