Skip to content

Instantly share code, notes, and snippets.

View kreeger's full-sized avatar

Ben Kreeger kreeger

View GitHub Profile
kreeger / benlight.vim
Created December 15, 2011 16:58
Benlight: My Twilight-based vim color scheme
" Vim color file
" Converted from Textmate theme Twilight using Coloration v0.3.2 (
set background=dark
highlight clear
if exists("syntax_on")
syntax reset
kreeger / mc_server.rb
Created January 7, 2012 18:44
Ruby: Minecraft process launcher
#!/usr/bin/env ruby
# Minecraft server launcher, by Benjamin Kreeger <>.
# Feel free to shamelessly steal this script. I don't care.
# I renamed mine to `mc_server` and did a `chmod +x` on it so I
# wouldn't have to type `ruby mc_server.rb` on it every time I
# wanted to launch my server in the background.
# Make sure this is in the same directory as your
# `minecraft_server.jar` file. I haven't tested it otherwise, and
kreeger / convert.rb
Created February 18, 2012 18:50
Ruby: Recursively convert to 128k MP3
#!/usr/bin/env ruby
# convert.rb
# Convert a directory (recursively!) full of audio files into 128k MP3.
# Good for burning folder-delimited MP3 CDs.
# Released under the license below (also at
kreeger / mw2md.rb
Created March 5, 2012 22:43
Ruby: Convert MediaWiki to Markdown
#!/usr/bin/env ruby
require 'rubygems'
require 'optparse'
require 'maruku'
require 'wikicloth'
require 'tidy_ffi'
require 'pandoc-ruby'
opts = {} do |o|
kreeger / 40hr.rb
Created May 11, 2012 18:28
Calculates the amount of time remaining in a 40 hour work-week
#!/usr/bin/env ruby
require 'time'
week_time = ARGV[0].to_f
clock_in = Time.parse(ARGV[1])
rescue Exception => e
kreeger / sonofabatch.rb
Created August 7, 2012 19:41
Handy batch renaming for stuff I do, in Ruby.
#!/usr/bin/env ruby
# Batch processing utilities I've found handy.
# Can also be found at
# Released under the WTFBPPL license, at
require 'thor'
require 'logger'
require 'fileutils'
require 'chronic'
kreeger / airbrake.rb
Created August 15, 2012 18:02
Hits up the Airbrake API for some commonly used tasks of ours.
#!/usr/bin/env ruby
# Hits up Airbrake to see what's happening.
require 'thor'
require 'httparty'
require 'logger'
require 'pp'
class AirbrakeAPI
kreeger / SomeTableViewDataSource.m
Created October 11, 2012 16:00
Removing "empty" cells from a section.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger count = [[[self.tableSettings objectAtIndex:section] objectForKey:@"rows"] count];
NSInteger emptyCount = 0;
for (int i = 0; i < count; i++) {
NSIndexPath *iPath = [NSIndexPath indexPathForRow:i inSection:section];
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:iPath];
if (cell.textLabel.text == nil || [cell.textLabel.text isEqualToString:@""]) emptyCount++;
kreeger /
Created October 25, 2012 16:32
Displaying Markdown on Cocoa Touch.

In writing my first iOS app, I found myself reaching out in a few areas of self-discovery regarding the Cocoa Touch framework and what it's capable of, especially in how it compares to Ruby and it's standard library (which is what I've been used to for the past few years of my life). I've grown to love Ruby mixins and monkey-patching, and was delighted to learn that Objective-C has something quite similar: categories. ClassName+CategoryName.{h,m} is all you need, and you can define new class/static and instance methods on an Objective-C class.

One of my other strong preferences is for the Markdown format, and thus I snagged one of the more popular C-based implementations of Markdown (named [Sundown][sun]) and wrote a category around UIWebView for effortlessly displaying a parsed file. This was all made possible in the first place by [an awesome post on Stack Overflow][sta] on using Sundown with Objective-C.

//  UIWebView+Markdown.h

#import <UIKit/UIKit.h>
kreeger / UITableView+IndexPathHelpers.m
Created November 13, 2012 03:09
A UITableView category for traversing index paths.
#import <UIKit/UIKit.h>
@interface UITableView (IndexPathHelpers)
- (NSIndexPath *)minimumIndexPath;
- (NSIndexPath *)maximumIndexPath;
- (NSIndexPath *)incrementIndexPath:(NSIndexPath *)indexPath;
- (NSIndexPath *)decrementIndexPath:(NSIndexPath *)indexPath;