Skip to content

Instantly share code, notes, and snippets.

View Integralist's full-sized avatar
🎯
Making an impact

Mark McDonnell Integralist

🎯
Making an impact
View GitHub Profile
@Integralist
Integralist / building-a-go-program-via-docker.sh
Last active August 28, 2015 08:28
Building a Go program via Docker
docker run -\
-rm=true \
-v $WORKSPACE/src:/gopath/src/github.com/foo/bar/src \
-v $WORKSPACE/src:/app \
-e "GOPATH=/gopath" \
-w /app golang:1.5 sh \
-c 'CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags=\"-s\" -o bar'
# Refactor:
# Set the working directory to `/gopath/src/github.com/foo/bar/src
@Integralist
Integralist / heredoc.rb
Created February 12, 2014 12:04
Ruby HEREDOC but not worrying about the crappy spacing
<<-FOO.gsub /^\s+/, ""
abc
def
ghi
jkl
FOO
@Integralist
Integralist / dynamo_db_query_example.md
Last active August 29, 2015 13:56 — forked from kenoir/dynamo_db_query_example.md
Playing around with DynamoDB (old)

AWS query-instance_method docs

export AWS_ACCESS_KEY_ID=‘XXXX’
export AWS_SECRET_ACCESS_KEY=‘XXXX’
# ENV['AWS_ACCESS_KEY_ID']
# ENV['AWS_SECRET_ACCESS_KEY']
{
"name": "WebScraping",
"main": "scrap.js",
"dependencies": {
"cheerio": "~0.13.1"
}
}
@Integralist
Integralist / bubbling errors.js
Last active August 29, 2015 13:56
Demonstrate how to handle bubbling errors by consolidating them (modified from: http://blog.ponyfoo.com/2013/07/12/teach-yourself-nodejs-in-10-steps)
function sum(a, b, done) {
// we convert this otherwise sync function into an async function
// note: this forces itself into the next event loop
// we should use setImmediate instead which places it at
// the bottom of the current event loop stack
process.nextTick(function() {
// `done` is the callback function passed into `sum`
done(null, a + b)
});
}
@Integralist
Integralist / << method.rb
Last active August 29, 2015 13:56
In Ruby using the `<<` operator as a method identifier has special meaning. It allows us to call the method without using a period (so we can do `foo << "abc"` and not have to do `foo.<< "abc"`)
class Foo
def <<(something)
puts something
end
def say(something)
puts something
end
end
@Integralist
Integralist / reduce with key and value.rb
Last active August 29, 2015 13:56
Passing through key and value to a reduce method block rather than just the item
# As expected the output is the key, then the value...
({ :key => :value, :foo => :bar }).reduce([]) { |pass_through, item|
puts item
}
# key
# value
# foo
# bar
@Integralist
Integralist / mocking-and-faking.md
Last active August 29, 2015 13:57
Examples of mocking and faking data using PHPUnit

The problem with Faking it

The Problem

Developer (A) creates 2 classes, MyClass and Dependency:

class MyClass
{
    private $dependency;
@Integralist
Integralist / 1. too much context.rb
Last active August 29, 2015 13:57
Ruby: reducing context
class Dependency
def initialize(foo, bar, baz)
@foo = foo
@bar = bar
@baz = baz
end
def data
{ :foo => @foo, :bar => @bar, :baz => @baz }
end
@Integralist
Integralist / AOP.md
Last active August 29, 2015 13:57
AOP (Aspect-Oriented Programming)

What is AOP?

Aspect Oriented Programming is a means to change the behaviour of – or add behaviour to – methods and functions (including constructors) non-invasively. The added behaviour is called “advice” and can be added before, after, or around the function it advises.

This description is similar to the Extract Surrounding refactoring method. The difference is in the direction of the change. It seems AOP is more focused at modifying existing behaviour non-invasively; where as the Extract Surrounding Method actually changes the source code to allow this type of behavioural modification.

Libraries