Skip to content

Instantly share code, notes, and snippets.

View rcoh's full-sized avatar

Russell Cohen rcoh

View GitHub Profile
logs.view.map(_.takeWhile(_ != ' ')).grouped(8).count(_.contains("ERROR"))
@rcoh
rcoh / sshupdate.py
Created February 3, 2013 22:57
Automatically update your SSH config to allow ssh-ing into EC2 instances by their name. Works on Linux and Mac OS X.
import os
import subprocess
import boto.ec2
import itertools
AWS_KEY = os.getenv('AWS_ACCESS_KEY')
AWS_SECRET = os.getenv('AWS_SECRET_KEY')
# Tweak as necessary for your infrastructure
regions = ['us-east-1', 'us-west-1', 'eu-west-1']
@rcoh
rcoh / scala-patterns.scala
Last active September 13, 2018 12:59
Scala patterns for compiler construction
// Useful Scala Patterns for Compiler Design
// 1. Case Classes
// [For full details, see Programming in Scala 2ed, page 310]
// Case classes are syntactic sugar around normal Scala classes. They come prebaked with the following properties:
// * Factory constructor (don't need new) :
case class Foo(bar: String)
@rcoh
rcoh / main.py
Last active December 15, 2015 05:19
How to Hang Yourself With Exceptions
import other
def thrower():
raise other.Exp1
def catcher():
try:
thrower()
except other.Exp1, other.Exp2:
pass
.....
File "./filepicker/client/url_client.py", line 102, in get_file_info_response
url = urls_lib.sanitize_url(url, strict=True)
File "./filepicker/urls_lib.py", line 50, in sanitize_url
error()
File "./filepicker/urls_lib.py", line 38, in error
raise exceptions_lib.FilepickerException("Invalid Url", 400)
TypeError: 'AuthException' object is not callable
import exception_package
try:
thrower()
except exception_package.Exp1, exception_package.Exp2:
pass
try:
thrower()
except NastyException, e:
print "Uh oh. We threw an", e
try:
thrower()
except (Exception1, Exception2):
print DoStuff
for (loop_cond) {
int x = 2;
if (x > 1) {
x = -5;
}
print(x);
}
// If we hoist x = 2, then we'll only print once
// If we don't we'll print every time.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Ink setupWithAppKey:@"your-appkey-here"];
/*Your app's intialization code here*/
}