Skip to content

Instantly share code, notes, and snippets.

@CoralineAda
CoralineAda / open_remote_github.md
Last active April 12, 2016 13:29
Open current git repo on GitHub in a browser
# 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.
@Zolmeister
Zolmeister / app.yml
Created March 19, 2015 22:32
Ansible Skeleton
---
# 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
@chetan
chetan / raspberrypi_fix_wifi.sh
Created March 18, 2015 16:14
Script to fix WIFI issues on the Raspberry Pi B+
#!/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 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.

  1. 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) }
@mietek
mietek / set-up-l2tp-ipsec-vpn-on-debian.md
Last active October 22, 2023 12:25
Set up L2TP/IPsec VPN on Debian

Set up L2TP/IPsec VPN on Debian

Set up IPsec

Set up networking

@brianhempel
brianhempel / enumerator_to_json.rb
Created February 17, 2015 17:32
Lazily convert an Enumerator or Enumerator::Lazy to a JSON array. Save as config/initializers/enumerator_to_json.rb
# 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|
@joech4n
joech4n / Configure Postfix for Gmail SMTP in Mac OSX.md
Last active May 13, 2023 10:34 — forked from larrybotha/readme.markdown
Configure Postfix for Gmail SMTP in Mac OSX