Skip to content

Instantly share code, notes, and snippets.

@christianhatch
christianhatch / storyboard-viewcontroller-init.swift
Last active January 27, 2022 22:27
A simple UIStoryboard extension to easily instantiate viewcontrollers using Swift type casting. Raw
// Do you often find yourself writing lines of code that look like this?
// let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ViewController") as! ViewController
// Here's a simpler way, using generics and Swift type-casting (as long as the viewcontroller's storyboard identifier is its class name).
// Now you can write: let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController() as ViewController
extension UIStoryboard {
func instantiateViewController<T: UIViewController>() -> T {
guard let vc = instantiateViewControllerWithIdentifier(String(T)) as? T else {
fatalError("Could not locate viewcontroller with with identifier \(String(T)) in storyboard.")
}
@mjgp2
mjgp2 / create-queue.sh
Last active April 22, 2022 10:58
Instantly mirror an S3 bucket to a local directory, e.g. for ELB logs to be consumed by logstash
region=us-east-1
s3_bucket_name=$1
sns_topic_name=$2
sqs_queue_name=$sns_topic_name
# create the SNS topic
sns_topic_arn=$(aws sns create-topic \
--region "$region" \
--name "$sns_topic_name" \
--output text \
@ttscoff
ttscoff / barchart.rb
Last active January 2, 2022 10:40
Command line bar chart from JSON data (for GeekTool, et al)
#!/usr/bin/env ruby
# encoding: utf-8
# Brett Terpstra 2013, WTF license <http://www.wtfpl.net/txt/copying/>
# Outputs a vertical bar chart from date-based JSON data
# Requires the JSON rubygem: `[sudo] gem install json`
require 'date'
require 'open-uri'
require 'rubygems'
require 'json'
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@mike-burns
mike-burns / gist:987910
Created May 24, 2011 00:05
Implicts in Ruby, via Scala
# Implicits in Ruby, based on Scala. Works like:
#
# implicitly.from(BaseClass).to(WrapperClass).via do |base_object|
# WrapperClass.new(base_object)
# end
#
def implicitly
Implicit.new
end