Skip to content

Instantly share code, notes, and snippets.

View thegedge's full-sized avatar

Jason Gedge thegedge

View GitHub Profile
@thegedge
thegedge / thunderstorm_timelapse.py
Created August 7, 2016 21:26
Produces a timelapse video of a thunderstorm with an emphasis on lightning
#!/usr/bin/env python
import cv2
import os.path
import sys
import tqdm
def frames(reader, indices=None, desc=None):
frame_count = int(reader.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))
if indices is None:
indices = xrange(0, frame_count)
@thegedge
thegedge / native_libs.rb
Last active June 16, 2016 19:17
Read -l flags from Makefiles for gems with native extensions
require 'set'
libs = Set.new
Gem::Specification.reject { |spec| spec.extensions.empty? }.each do |spec|
spec.extensions.each do |ext_path|
extconf_rb_path = Pathname.new(spec.gem_dir).join(ext_path)
makefile_path = extconf_rb_path.dirname.join('Makefile')
if makefile_path.readable?
last_was_lib_flag = false
makefile_path.readlines.map(&:strip).each do |line|
@thegedge
thegedge / find_unused_functions.rb
Last active May 25, 2016 00:25
Find (maybe) unused functions in Ruby
#!/usr/bin/env ruby
require 'optparse'
module CLI
extend self
PATHS_TO_CHECK = %w(app bin config engines lib script)
EXTENSIONS_TO_CHECK_FOR_DEFINITIONS = %w(.rb .rake)
EXTENSIONS_TO_CHECK_FOR_USAGE = EXTENSIONS_TO_CHECK_FOR_DEFINITIONS + %w(.yml .yaml .erb)
@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
@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 / 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 / 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 / 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 / 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 / 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;