Skip to content

Instantly share code, notes, and snippets.

View damncabbage's full-sized avatar
🙅‍♀️
permanent omnishambles

Robin Howard damncabbage

🙅‍♀️
permanent omnishambles
View GitHub Profile
@damncabbage
damncabbage / bower.json
Created August 28, 2015 05:14
Bower and Version Conflicts
{
"name": "b",
"version": "0.0.0",
"authors": [
"Rob Howard <rob@robhoward.id.au>"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
$ pip install which -v -v
Downloading/unpacking which
Getting page https://pypi.python.org/simple/which/
URLs to search for versions for which:
* https://pypi.python.org/simple/which/
Getting page http://code.google.com/p/which/b
Analyzing links from page https://pypi.python.org/simple/which/
Skipping link http://code.google.com/p/which/ (from https://pypi.python.org/simple/which/); not a file
Analyzing links from page http://code.google.com/p/which/
Skipping link https://www.google.com/accounts/ServiceLogin?service=code&ltmpl=phosting&continue=http%3A%2F%2Fcode.google.com%2Fp%2Fwhich%2F&followup=http%3A%2F%2Fcode.google.com%2Fp%2Fwhich%2F (from http://code.google.com/p/which/); not a file
@damncabbage
damncabbage / same_instance_var.rb
Last active August 29, 2015 13:56
Mixins: Not Very Encapsulatey.

(In reply to https://twitter.com/gregmcintyre/status/432012568966619137)

Mixins (included Modules) all share one object's state and method set; you need to know everything about every module a class includes or extends before touching it, or risk breaking your code unintentionally. This is practically antithetical to Encapsulation, which hides state behind defined interfaces.

A good quote from a good article:

Using mixins like this is akin to “cleaning” a messy room by dumping the clutter into six separate junk drawers and slamming them shut. Sure, it looks cleaner at the surface, but the junk drawers actually make it harder to identify and implement the decompositions and extractions necessary to clarify the domain model.

@damncabbage
damncabbage / sane_timeout.rb
Last active August 29, 2015 13:56
Ruby Timeout
require 'open3'
require 'sane_timeout'
puts "Time out after 2 seconds. Count them..."
result = Timeout.timeout(2) do
stdin, stdout, stderr = Open3.capture3("sleep 30")
output = stdout.read + "\n" + stderr.read
end
@damncabbage
damncabbage / Dockerfile
Created April 8, 2014 05:11
Dockerfile + docker_build.sh script, for eventual use with Jenkins CI.
FROM ubuntu:precise
### Lean on our existing Babushka definitions to pull in Ruby and other dependencies ###
# Babushka bootstrap
RUN apt-get update
RUN apt-get -y install curl
RUN sh -c "`curl https://babushka.me/up`"
# Babushka deps setup
@damncabbage
damncabbage / multiple_objects.rb
Created June 8, 2014 09:12
Writing Object to CSV
require 'csv'
# A class and object of some sort.
# (Ignore the OpenStruct thing; I'm being lazy when I'm making my example objects.)
require 'ostruct'
class Car < OpenStruct(:name, :made_in)
end
cars = [
Car.new(name: "Shitbox Mazda", made_in: 1992),
@damncabbage
damncabbage / dig.hs
Last active August 29, 2015 14:02
GHC compiler warnings
sumDigits :: [Int] -> Int
sumDigits (x:xs) = x + sumDigits xs
-- Missing the "sumDigits [] = 0" base case.
main = do
putStr $ show $ sumDigits [1,2,3]
module Golf where
-- | Foo
--
-- >>> skips "ABCD"
-- ["ABCD","BD","C","D"]
--
-- >>> skips "hello!"
-- ["hello!","el!","l!","l","o","!"]
--
@damncabbage
damncabbage / List.hs
Created June 17, 2014 08:56
NICTA course exercises.
headOr :: a -> List a -> a
headOr d l = foldRight (\x y -> x) d l -- This anonymous function here is dumb.
product :: List Int -> Int
product l = foldRight (\x y -> x * y) 1 l
-- Alternative:
-- product l = foldRight (*) 1
@damncabbage
damncabbage / Main.hs
Last active August 29, 2015 14:03 — forked from christian-marie/gist:475858353961828655f8
Prisoner's Dilemma: Game Server
--
-- Copyright © 2013-2014 Anchor Systems, Pty Ltd and Others
--
-- The code in this file, and the program it is a part of, is
-- made available to you by its authors as open source software:
-- you can redistribute it and/or modify it under the terms of
-- the 3-clause BSD licence.
--
module Main where