Skip to content

Instantly share code, notes, and snippets.

View olliebun's full-sized avatar
⌨️
IC

Oliver Hassett olliebun

⌨️
IC
View GitHub Profile
@olliebun
olliebun / ruby-file-creation.rb
Created December 19, 2011 05:45
Odd Ruby file behaviour
fileName = 'test.txt'
folder = '/home/me/testDirectory'
fileName = folder + '/' + fileName
f = File.new(fileName, 'wb+')
f.write(attachment[:body])
f.close
@olliebun
olliebun / gist:3607360
Created September 3, 2012 06:41
Error when adding a submodule
git submodule add git@github.com:$mycompany/$myrepo.git
Cloning into 'go'...
Enter passphrase for key '/home/$me/.ssh/id_rsa':
remote: Counting objects: 21, done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 21 (delta 1), reused 21 (delta 1)
Receiving objects: 100% (21/21), 6.37 KiB, done.
Resolving deltas: 100% (1/1), done.
fatal: You are on a branch yet to be born
Unable to checkout submodule '$myrepo'
@olliebun
olliebun / gist:4507604
Created January 11, 2013 02:52
variable naming and keyword overlap in go
func find_paths_in_ranges(match_ranges []*matchRange) []Path {
var (
paths = make([]Path, len(ranges))
path Path
i, j int
row *csvm.Row
match_range *matchRange
)
for i, match_range = range ranges {
@olliebun
olliebun / gist:4727589
Created February 7, 2013 01:24
decorator with closure
def will_break(f):
broken = False
def on_call(self, *args, **kwargs):
if broken:
raise ValueError("Already broken!")
else:
broken = True
f(self, *args, **kwargs)
return on_call
@olliebun
olliebun / gist:5996606
Created July 14, 2013 23:47
Get exception line number
import sys
try:
raise ValueError("Damn")
except ValueError as e:
_, _, exc_tb = sys.exc_info()
# print the file that threw the exception
print(exc_tb.tb_frame.f_code.co_filename)
# print the line number of the expression that threw the exception
print(exc_tb.tb_lineno)
@olliebun
olliebun / gist:6489507
Last active December 22, 2015 14:59
love #dat settler state
for the next time a technocrat faffs on about how everything would be ok If People Just Respected Statistics And Data:
Through the state's statistical fetishism, a de-contextualised and dated
statistic derived from vague sources comes to represent reality. Zombie-like,
this statisic rises from the grave, consuming hunters, fishers and gatherers
and their bush foods along with entire outstations so that they can no longer
be seen by the state. Fetishised, it gains a magical power over other evidence
that either challenges or contextualises it. It also gains a power over
Indigenous communities, as this statistical abstraction becomes a means for
creting their reality rather than merely representing it. It is used as
@olliebun
olliebun / test.php
Last active December 23, 2015 12:09
Getting the path to a PHP file without resolving symlinks.
$ ln -s test.php foo.php
$ php test.php
/home/vagrant/test.php
$ php foo.php
/home/vagrant/foo.php
@olliebun
olliebun / gist:7295983
Created November 3, 2013 23:22
Coffeecript's list comprehension compilation.. crazy.
validate: (attrs, options) ->
missing = [attr for attr in required if attrs[attr] is null]
if missing.length > 0
return "Missing #{missing.join(', ')}"
@olliebun
olliebun / gist:7650947
Created November 25, 2013 23:46
Error when bootstrapping Go for Linux X86-64 cross-compilation on OSX Mavericks
$ hg summary
parent: 16840:414057ac1f1f go1.1.2 release
go1.1.2
branch: release-branch.go1.1
commit: (clean)
update: (current)
$ clang -v
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
@olliebun
olliebun / gist:7798493
Created December 5, 2013 01:04
C OID handling in Go
type OID []uint32
// Create a new OID
func NewOID(num ...uint32) OID {
return num
}
// Create an OID from the C representation
func NewOIDFromCArray(coid *C.oid, oid_length C.int) (OID, error) {
// See http://stackoverflow.com/questions/14826319/go-cgo-how-do-you-use-a-c-array-passed-as-a-pointer