Skip to content

Instantly share code, notes, and snippets.

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) }
@dolzenko
dolzenko / gist:ba9f14c104a105ee46a13ced19a18332
Created July 15, 2016 11:09 — forked from marcinbunsch/gist:1044437
Rails production prompt change as a Rails initializer
# Put this file in config/initializers/irb.rb
# Works in Rails 3.0+, should also work in 2.3
# Override the IRB, to provide the Rails environment in the prompt
module IRB
class << self
def setup_with_prompt_override(ap_path)
setup_without_prompt_override(ap_path)
env = (Rails.env.to_sym == :production ? "\033[00;31mPRODUCTION\033[00m" : Rails.env)
@dolzenko
dolzenko / gist:7c76d6b594ba6a2c68266b58bd83275b
Created July 15, 2016 11:09 — forked from kogakure/gist:3187467
Ruby: Colorized irb prompt for production: ~/.irbrc
# .irbrc
if defined?(Rails) && Rails.production?
conf = IRB.conf[:PROMPT][IRB.conf[:PROMPT_MODE]]
red = "\033[0;31m"
reset = "\033[0m"
[:PROMPT_S, :PROMPT_C].each do |p|
conf[p].gsub!(/^(.*)$/, "#{red}\\1#{reset}")
end
conf[:PROMPT_I] = "#{red}%N(%m):%03n:%i (PRODUCTION) > #{reset}"
end
@dolzenko
dolzenko / ack-gems
Created September 5, 2013 15:31 — forked from AndrewRadev/ack-gems
#! /usr/bin/env ruby
require 'bundler'
paths = Bundler.load.specs.map(&:full_gem_path)
system("ack '#{ARGV[0]}' #{paths.join(' ')}")
# Not needs as there is 'Copy as Curl' in Chrome now
sqlite3 -separator ' ' ~/.config/google-chrome/Default/Cookies 'select host_key, "TRUE", path, "FALSE", expires_utc, name, value from cookies'
extract :DWAPI do
get 'Siphon'
limit 2
resolve do |response|
rows = []
p response
response.each do |input|
p input
name = input[:name]
@dolzenko
dolzenko / hoptoad_api.rb
Created January 19, 2012 11:01 — forked from croaky/hoptoad_api.rb
Access the Hoptoad (http://hoptoadapp.com) API with Ruby's ActiveResource
class Hoptoad < ActiveResource::Base
self.site = "https://your_account.airbrake.io"
class << self
@@auth_token = 'your_auth_token'
def find(*arguments)
arguments = append_auth_token_to_params(*arguments)
super(*arguments)
end
@dolzenko
dolzenko / heroku-info.rb
Created April 15, 2011 08:00
Show stats for all of your Heroku apps
#!/usr/bin/env ruby
require 'rubygems'
require 'heroku'
require "heroku/command/base"
user, pass = File.read("#{ENV['HOME']}/.heroku/credentials").split(/\r?\n/)
HEROKU = Heroku::Client.new(user, pass)
class Heroku::Client
@dolzenko
dolzenko / deps.rb
Created July 8, 2010 14:32 — forked from lsegal/deps.rb
require 'json'
require 'open-uri'
class DependencyChecker
def initialize(*gems)
@gems = gems.flatten
@dep_cache = {}
end
def all_dependencies