alias gh='git config --get remote.origin.url | ruby -ne "puts %{https://github.com/#{\$_.split(/.com[\:\/]/)[-1].gsub(%{.git},%{})}}"| xargs open'
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
# Multiple inheritance with Modules as an alternative to injected composition | |
# from Sandi Metz's talk [Nothing is Something](http://confreaks.tv/videos/bathruby2015-nothing-is-something) | |
# Like Sandi's 'direct' DI method this has behavior outside of the base class | |
# that gets composed together. However in this gist I compose modules in class | |
# definitions instead of injecting collaborators. | |
# Tradeoffs between this and Sandi's version are that in this case the API consumer doesn't | |
# have to know how to make a RandomEchoHouse (no `house = House.new(formatter: Whatever.new)`), | |
# but also the API consumer can't make anything not already accounted for either. |
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
--- | |
# file: roles/app/tasks/main.yml | |
- name: ensure logging directory exists | |
file: path=/var/log/acme state=directory | |
tags: | |
- install | |
- name: ensure config directory exists | |
file: path=/etc/acme/app state=directory |
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/bash | |
# The raspberrypi would occasionally lose WIFI. | |
# The fix is to reset the interface manually or reboot the device. | |
# | |
# Script should be run as root and run every 5 min: | |
# crontab: | |
# */5 * * * * /root/bin/fix_wifi.sh | |
PATH="/sbin:$PATH" |
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
# This is a stripped-down example based on Selecta's TTY handling. We store the | |
# TTY state in `tty_state`, then go into an infinite loop. When the loop is | |
# terminated by a ^C, we try to restore the TTY state. It's important that this | |
# work, but it doesn't in some subtle situations, and I don't know why. | |
# | |
# Save this file as test.rb and run it via this command, where `stty` should | |
# successfully restore the TTY state: | |
# bash -c 'echo | ruby test.rb' | |
# | |
# Next, run it via this command, where `stty` should fail to restore the TTY |
There are three easy to make mistakes in go. I present them here in the way they are often found in the wild, not in the way that is easiest to understand.
All three of these mistakes have been made in Kubernetes code, getting past code review at least once each that I know of.
- Loop variables are scoped outside the loop.
What do these lines do? Make predictions and then scroll down.
func print(pi *int) { fmt.Println(*pi) }
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
# Natively, Enumerators get JSONized like "#<Enumerator::Lazy:0x007f8714807080>", or they explode, either of which is a problem. | |
# We want them to make an array, and do it lazily so we don't have to keep the items in memory! | |
class Enumerator | |
def to_json(state) | |
state.depth += 1 | |
string = "[\n" | |
first_item = true | |
self.each do |item| |
This should work on at least:
- 10.9 Mavericks
- 10.10 Yosemite
Taken from Using MacOSX Lion command line mail with Gmail as SMTP
Edit file /etc/postfix/main.cf
and add this to the bottom: