Skip to content

Instantly share code, notes, and snippets.

alias duf='du -sk * | sort -n | perl -ne '\''($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}'\'
@cupakromer
cupakromer / gist:4512023
Last active December 10, 2015 23:55
Find manufacturer
require 'ap'
require 'csv'
class WifiManufacturer
include Enumerable
attr_reader :name, :oui_list
def initialize(name, ouis)
@name = name
@cupakromer
cupakromer / gist:4710950
Last active December 12, 2015 03:58
Scrappy Post

Something we started doing just this week, and plan on continuing moving forward, is tackling "warm-up" problems. This reminds me of middle school math class. These are relatively simple programming problems that are solved via group-pairing.

Group-pairing is where the entire group participates in solving the problem. One person is designated as the coder. S/he displays her/his laptop on the conference room TV (via an Apple TV). The group then discusses the problem, and codes up a solution together.

@cupakromer
cupakromer / gist:4719800
Created February 6, 2013 02:47
How to require all .rb in sub-dirs
Dir[File.expand_path('../formulas/**/*.rb', __FILE__)].each{|f| require f}
class Test
attr_accessor :my_var
def set_name(name)
self.my_var = name # You must do this using just my_var = name would
# create a local variable with the name my_var
end
def say_hello
puts "Hi #{my_var}" # No need to say `self`. It is the implicit receiver
@cupakromer
cupakromer / gist:4750412
Created February 10, 2013 17:54
Remove urls from file
def remove_urls(filename)
File.write filename, File.read(filename).gsub(/https?:\/\/[^\s'"]+/,'')
end
@cupakromer
cupakromer / gist:4759041
Created February 12, 2013 00:44
Project Euler Problem 3
# The prime factors of 13195 are 5, 7, 13 and 29.
#
# What is the largest prime factor of the number 600851475143?
require 'prime'
def largest_prime(number)
number.prime_division.map(&:first).max
end
describe "Problem 3: Largest prime factor" do
@cupakromer
cupakromer / README.md
Last active December 13, 2015 23:29
For some reason tshark is buffering

The idea is that the joiner will run as a master daemon, watching tshark and the processor which here is represented by std-reader. If either process is to die, the daemon will restart and re-join the FDs; this isn't implemented yet, but would be the end goal.

@cupakromer
cupakromer / my-daemon.conf
Last active December 14, 2015 01:59
Upstart Y u no work :trollface: clearly no :neckbeard:
# /etc/init/my-daemon.conf
description "The Daemon"
start on runlevel [2345]
stop on runlevel [!2345]
expect daemon
respawn
@cupakromer
cupakromer / gist:5068434
Created March 1, 2013 22:28
Custom with matcher
class SubstringMatcher
def initialize(regexp)
@regexp = regexp
end
def ==(actual)
actual.to_s =~ @regexp
end
end