Skip to content

Instantly share code, notes, and snippets.

View keybase.md

Keybase proof

I hereby claim:

  • I am dolzenko on github.
  • I am dolzenko (https://keybase.io/dolzenko) on keybase.
  • I have a public key ASAipUSRr1nXIPSfQHVNeEFTKKf7snq4L8dxWbcm7uQrcAo

To claim this, I am signing this object:

View The Three Go Landmines.markdown

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 Jul 15, 2016 — forked from marcinbunsch/gist:1044437
Rails production prompt change as a Rails initializer
View gist:ba9f14c104a105ee46a13ced19a18332
# 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 Jul 15, 2016 — forked from kogakure/gist:3187467
Ruby: Colorized irb prompt for production: ~/.irbrc
View gist:7c76d6b594ba6a2c68266b58bd83275b
# .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
View gist:4fbb5f01831b972e2e4a
10.240.0.53 mm-1
10.240.0.55 mm-2
10.240.0.56 mm-3
10.240.0.21 ms-1
10.240.0.23 ms-2
10.240.0.29 ms-3
10.240.0.34 ms-4
10.240.0.36 ms-5
10.240.0.31 ms-6
10.240.0.32 ms-7
View single-bad-thing-about-go.go
package main
import "fmt"
func f() (int, error) {
return 42, nil
}
func main() {
x := 3
@dolzenko
dolzenko / mgmt-deps.rb
Last active Aug 29, 2015
Prints missing/unused Go deps for https://github.com/bsm/mgmt
View mgmt-deps.rb
require 'json'
require 'set'
myself = `go list`.strip
deps = Set.new
`go list ./...`.each_line do |dep|
pdeps = JSON.parse(`mgmt go list -json #{dep}`)
deps += pdeps['Deps']
deps += pdeps['TestImports'] if pdeps['TestImports']
@dolzenko
dolzenko / sidekiq_paper_trail_middleware.rb
Created Dec 18, 2014
Make originator of change tracked with paper_trail available in Sidekiq background workers
View sidekiq_paper_trail_middleware.rb
module Acme
module Sidekiq
module PaperTrailMiddleware
class Client
# @param [Object]
# @param [Hash] job
def call(_, job, *)
job['whodunnit'] = ::PaperTrail.whodunnit
yield
end
View run-webrick-in-current-dir.rb
ruby -rwebrick -e'WEBrick::HTTPServer.new(Port: 8000, DocumentRoot: Dir.pwd).start'
View net-http-debug-output.rb
module Net
class HTTP
alias_method '__initialize__', 'initialize'
def initialize(*args,&block)
__initialize__(*args, &block)
ensure
@debug_output = $stderr ### if ENV['HTTP_DEBUG']
end
end
You can’t perform that action at this time.