This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def last(first=nil, *rest) | |
if rest.empty? | |
first | |
else | |
last(*rest) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Proc | |
def unfuck! | |
class << self | |
def call(*params) | |
if arity == 1 && params.first.is_a?(Array) | |
super(params.first.first) | |
else | |
super | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Symbol | |
# Makes :symbol.(a,b,c) equal to symbol(a,b,c). | |
def call(*params, &block) | |
send(self, *params, &block) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ListTransformation { | |
private ListTransformation() { /* empty */ } | |
public static <T> List<T> collect(List<T> inputList, Predicate<T> predicate) { | |
List<T> newList = new ArrayList(inputList); | |
Iterator<T> iterator = newList.iterator(); | |
while (iterator.hasNext()) { | |
try { | |
if (!predicate.check(iterator.next())) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class.metaClass.getDimensions = { -> isArray() ? 1 + componentType.dimensions : 0 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
package=ruby22 | |
suffix=2.2 | |
for source in $(port contents $package | grep /opt/local/bin/); do | |
target=$(dirname $source)/$(basename $source $suffix) | |
ln -s $source $target | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
echo 'Press any key to continue...'; read -k1 -s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
def to_bool | |
!!self | |
end | |
alias true? to_bool | |
def false? | |
!true? | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curldocker() { | |
local args | |
local endpoint | |
args=(${@:1:$(( $# - 1 ))}) | |
endpoint=${@[$#]} | |
curl --silent \ | |
--key $DOCKER_CERT_PATH/key.pem \ | |
--cert $DOCKER_CERT_PATH/cert.pem \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ENV['DOCKER_HOST'].sub(%r{(?<=tcp://)[^:]+}) { |ip| Resolv.getname(ip) } |
OlderNewer