Skip to content

Instantly share code, notes, and snippets.

View thegedge's full-sized avatar

Jason Gedge thegedge

View GitHub Profile
@thegedge
thegedge / MergeSort.hs
Last active August 29, 2015 14:04
My amateur attempt at writing merge sort in Haskell.
merge :: Ord a => [a] -> [a] -> [a]
merge [] l = l
merge (a:l1) (b:l2)
| a <= b = a : merge l1 (b:l2)
| otherwise = b : merge l2 (a:l1)
mergeSort :: Ord a => [a] -> [a]
mergeSort [] = []
mergeSort [a] = [a]
mergeSort l =
@thegedge
thegedge / fix_broken_links.py
Created November 8, 2014 23:12
Fix broken shared library links in binaries/dylibs
@thegedge
thegedge / main.cpp
Last active August 29, 2015 14:09
Cache prefetch example
#include <array>
#include <chrono>
#include <iostream>
// Width of each dimension
constexpr size_t N = 200;
// Number of iterations for the test
constexpr size_t NUM_ITERATIONS = 100;
@thegedge
thegedge / main.tf
Last active August 29, 2015 14:24
Terraform count on aws_instance resource
variable "instances" {}
variable "flavor" {}
variable "ami" {}
variable "ami_list" {}
resource "aws_instance" "default" {
count = "${var.instances}"
ami = "${var.ami}"
instance_type = "${var.flavor}"
}
@thegedge
thegedge / example-use.tf
Last active August 29, 2015 14:27
Terraform zone module
resource "terraform_remote_state" "region" {
backend = "s3"
config {
bucket = "foo"
key = "bar"
region = "us-east-1"
}
}
module "sub1_zone" {
@thegedge
thegedge / gist:dcacba817bfb405afc59
Last active September 16, 2015 18:42
Terraform stack layout
// Directory layout
stacks/
|__ us-east-1
|__ test
|__ vpc
|__ services
|__ apps
|__ foo
|__ bar
@thegedge
thegedge / multi_sg_rule.tf
Created September 30, 2015 15:44
Security group rule for multiple SGs
resource "aws_security_group_rule" "allow_all" {
count = "${length(split(",", var.security_group_ids))}"
type = "ingress"
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = "${element(split(",", var.security_group_ids), count.index)}"
@thegedge
thegedge / example.tf
Created October 5, 2015 20:44
Forwarding module outputs for remote state or `terraform output`
// Foo has outputs "bar" and "baz"
module "foo" {
source = "..."
arg1 = "spam"
arg2 = "eggs"
}
// If you want `terraform output` or your remote state to show the outputs of
// `module.foo` you need to "forward" them along here:
output "bar" { value = "${module.foo.bar}" }
@thegedge
thegedge / rs_intersect.py
Last active December 12, 2015 12:09
Ray/sphere intersection in Python
#!/usr/bin/env python
import timeit
def dot(a, b):
"""Dot product"""
return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]
def rs_intersect(R0, d, C, r):
"""Ray/sphere intersection"""
R0 = (R0[0] - C[0], R0[1] - C[1], R0[2] - C[2])
@thegedge
thegedge / app--controllers--v1-welcome_controller.rb
Created April 29, 2016 16:55
Rails versioned controllers via Accept header
class V1::WelcomeController < V1::ApplicationController
def index
respond_to do |format|
format.welcome { render plain: "testing v1" }
end
end
end