Skip to content

Instantly share code, notes, and snippets.

View caius's full-sized avatar
👻

Caius Durling caius

👻
View GitHub Profile
module ExtendNumericRounding
def roundup(nearest=10)
self % nearest == 0 ? self : self + nearest - (self % nearest)
end
def rounddown(nearest=10)
self % nearest == 0 ? self : self - (self % nearest)
end
for i in `git branch -r`; do j=`echo $i|sed 's/\//_/'`; git checkout -b $j --track $i; done
# git checkout -b origin_master --track origin/master
# git checkout -b origin_topic_branch --track origin/topic_branch
@implementation InstaMenuAppDelegate
@synthesize menuController;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
if (!menuController)
menuController = [SCMenuController new];
}
@end
# Open xcode projects named after the folder you're in
alias xcode='open `pwd | sed -e "s/^\/.*\///g"`.xcodeproj'
require "benchmark"
TESTS = 1_000_000
Benchmark.bm do |results|
results.report do
TESTS.times do
"Br1ghtBox"[/[A-Za-z0-9]+/]
end
end
# What I usually do
a = []
5.times { a << "thing" }
a # => ["thing", "thing", "thing", "thing", "thing"]
# The "ruby" way to do it
Array.new(5) { "thing" } # => ["thing", "thing", "thing", "thing", "thing"]
require "module_include"
require "time_extend"
Time.now.foobar # => "foobar"
# >> "Include called at ./time_extend.rb:7"
#
# This gives you the following prompt:
# Julius:my-project(910-form)[1] caius$
# Julius == hostname
# my-project == current folder
# (910-form) == git branchname (shows nothing when not in git repo)
# [1] == git stash count (shows nothing when not in git repo or there aren't any stashes)
# caius == current user
# $ == non-root shell
#
# I'd expect every line here to raise a NameError, but the 2nd expression doesn't.
a # ~> -:1: undefined local variable or method `a' for main:Object (NameError)
b = b # => nil
c = d # ~> -:1: undefined local variable or method `d' for main:Object (NameError)
Julius:local(masterbrew) caius$ brew install glib
==> Downloading http://ftp.acc.umu.se/pub/gnome/sources/glib/2.20/glib-2.20.5.tar.bz2
File already downloaded and cached
==> ./configure --disable-debug --prefix=/usr/local/Cellar/glib/2.20.5 --disable-dependency-tracking --disable-rebuilds
==> make
Exit code: 512
cd . && /bin/sh ./config.status glibconfig.h
config.status: executing glibconfig.h commands
config.status: glibconfig.h is unchanged
echo timestamp > stamp-gc-h