Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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
extract :DWAPI do
get 'Siphon'
limit 2
resolve do |response|
rows = []
p response
response.each do |input|
p input
name = input[:name]
# 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'
@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(' ')}")
@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 / 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)

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 / site.conf
Created March 28, 2023 06:19 — forked from paskal/site.conf
Nginx configuration for best security and modest performance. Full info on https://terrty.net/2014/ssl-tls-in-nginx/
# read more at https://terrty.net/2014/ssl-tls-in-nginx/
# latest version on https://gist.github.com/paskal/628882bee1948ef126dd/126e4d1daeb5244aacbbd847c5247c2e293f6adf
# security test score: https://www.ssllabs.com/ssltest/analyze.html?d=terrty.net
# your nginx version might not have all directives included, test this configuration before using in production against your nginx:
# $ nginx -c /etc/nginx/nginx.conf -t
server {
# public key, contains your public key and class 1 certificate, to create:
# (example for startssl)
# $ (cat example.com.pem & wget -O - https://www.startssl.com/certs/class1/sha2/pem/sub.class1.server.sha2.ca.pem) | tee -a /etc/nginx/ssl/domain.pem > /dev/null