Skip to content

Instantly share code, notes, and snippets.

@jdanbrown
jdanbrown / log-color
Created November 21, 2011 04:51
log4j logs in color!
#!/bin/bash -eu
#
# Color log4j-style logs for easier visual parsing.
#
# Usage:
# tail foo.log | log-color
# run-service | log-color
black="` tput setaf 0; tput bold`"
red="` tput setaf 1; tput bold`"
ubuntu@ip-10-72-38-138:~$ sudo -u xncore lsof -p 18990 | cut -c72- | sort|uniq -c | sort -n
1 /
1 *:17071 (LISTEN)
1 *:44059 (LISTEN)
1 *:50343 (LISTEN)
1 anon_inode
1 /dev/null
1 /dev/random
1 /dev/urandom
1 *:http-alt (LISTEN)
@jdanbrown
jdanbrown / boto-fab.py
Created September 25, 2012 20:40 — forked from marthakelly/boto-fab
Creating EC2 instance with Boto and Fabric
from fabric.api import *
from fabric.colors import green as _green, yellow as _yellow
import boto
import boto.ec2
from config import *
import time
def create_server():
"""
Creates EC2 Instance
@jdanbrown
jdanbrown / gist:4747205
Last active January 30, 2019 10:44
Object algebras example in scala
#!/bin/bash
exec ~/src/scala/bin/scala -savecompiled "$0" "$@"
!#
// Example of object algebras, based on the scala example at http://ropas.snu.ac.kr/~bruno/oa/
// type Term = ∀A,O. O[A] -> A
trait Term[O[_]] {
def apply[A](o: O[A]): A
}
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.Set;
import javax.management.MBeanServer;
import javax.management.ObjectName;
/**
* Print the Collector used in the program.
* @author khotyn
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_21).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import shapeless._
import shapeless._
scala> import syntax.tuple._
import syntax.tuple._
require 'rubygems'
require 'sinatra'
require 'json'
class GitHubUpdater
def self.update?(json)
(JSON.parse(json)["ref"] == "refs/heads/master")
end
import sys, types
def module(cls):
'''
Compose modules via class inheritance.
Construct a module from a singleton object from the given class `cls`, and
then replace cls's enclosing, top-level, file-based module with the newly
constructed class-based module. Retain a reference `_cls` to the original
class to allow extension via class inheritance.
implicit class AnyOps[X](x: X) {
def withEffect (f: X => Unit) : X = { f(x); x }
def into[Y] (f: X => Y) : Y = f(x)
}
// Example usage:
def lifeTheUniverseAndEverything = 42 withEffect { x =>
log.debug("Someone asked 'the question' again, I told them %s", x)
meter("req.lifeTheUniverseAndEverything") += 1
@jdanbrown
jdanbrown / ebs_set_names.py
Last active August 29, 2015 13:57
ebs_set_names.py
#!/usr/bin/env python
#
# Set names on unnamed EBS volumes from their attached EC2 instance.
#
# Requires:
# - aws: https://github.com/aws/aws-cli (tested with aws-1.0.0)
# - jq: http://stedolan.github.io/jq/ (tested with jq-1.3)
import os, sys, json, subprocess