Skip to content

Instantly share code, notes, and snippets.

View grosser's full-sized avatar
🎯
Focusing

Michael Grosser grosser

🎯
Focusing
View GitHub Profile
@grosser
grosser / push_and_merge_all.rb
Created August 5, 2011 12:40
Script to push and merge all branches
#!/usr/bin/env ruby
require 'rubygems'
require 'rake'
sh "git status | grep 'nothing to commit'" # ensure we are not dirty
sh "git fetch origin" # get current branch info
current_branch = `git branch | grep '*'`.split.last
def sync(branch)
sh "git checkout #{branch}"
# frozen_string_literal: true
source 'https://rubygems.org'
ruby "~> #{File.read('.ruby-version').strip}"
# bot
gem 'slack-ruby-bot'
gem 'slack-ruby-client'
gem 'async-websocket', '~> 0.8.0'
#!/bin/bash -e
# Kubernetes api server is supposed to run compaction on etcd
# when that does not happen we need to do an emergency compaction to make etcd not lock up
# this should only be done once, so we pick the leader to do it, which we assume is healthy
# (compacting manually outside of api server can lead to watches failing / requests for specific revisions failing etc)
#
# After compacting the keyspace, the backend database may exhibit internal fragmentation.
# Any internal fragmentation is space that is free to use by the backend but still consumes storage space.
# The process of defragmentation releases this storage space back to the file system.
@grosser
grosser / slow.rego
Created January 1, 2020 01:34
opa test is slow
package k8srequiredlabels
violation[{"msg": msg, "details": {"missing_labels": missing}}] {
provided := {label | input.review.object.metadata.labels[label]}
required := {label | label := input.parameters.labels[_]}
missing := required - provided
count(missing) > 0
msg := sprintf("opa-gatekeeper: you must provide labels %v for %v %v/%v", [missing, input.review.object.kind, input.review.object.metadata.namespace, input.review.object.metadata.name])
}
ruby test.rb internaltools.k8s.local
Warming up --------------------------------------
kubeclient os 1.000 i/100ms
kubeclient json 1.000 i/100ms
faraday json 1.000 i/100ms
faraday persistent 1.000 i/100ms
Calculating -------------------------------------
kubeclient os 1.896 (± 0.0%) i/s - 10.000 in 5.275373s
kubeclient json 1.907 (± 0.0%) i/s - 10.000 in 5.248037s
faraday json 1.933 (± 0.0%) i/s - 10.000 in 5.175768s
@grosser
grosser / build.rb
Last active April 16, 2018 22:35
Building single/partial steps from cloudbuild.yaml
remote = ARGV.delete("--remote")
id = ARGV.pop
abort "Usage: ruby build.rb <id|all> [--remote]" unless ARGV.empty?
unless system('which container-builder-local')
abort "Run: gcloud components install container-builder-local"
end
def dependencies(steps, id)
@grosser
grosser / mil_with_mail.rb
Created January 14, 2014 19:29
Making rails 2 use mail instead of tmail
module MailWithMail
# stolen + made static from Rails 3.0 action_mailer/old_api.rb
def self.set_content_type(m, user_content_type, class_default, params)
case
when user_content_type.present?
user_content_type
when m.has_attachments?
if m.attachments.detect { |a| a.inline? }
["multipart", "related", params]
else
@grosser
grosser / resque_web.rb
Created September 13, 2011 15:08 — forked from skippy/resque_web.rb
Mountable resque-web for rails 3+ apps
# https://gist.github.com/1214052
require 'sinatra/base'
class ResqueWeb < Sinatra::Base
require 'resque/server'
use Rack::ShowExceptions
if CFG[:user].present? and CFG[:password].present?
Resque::Server.use Rack::Auth::Basic do |user, password|
user == CFG[:user] && password == CFG[:password]
@grosser
grosser / gist:1609781
Created January 14, 2012 01:35
Transactional fixtures with capybara javascript tests
ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do
def current_connection_id
# Thread.current.object_id
Thread.main.object_id
end
end
@grosser
grosser / gist:2166521
Created March 23, 2012 03:39
Interact with commandline processess via stdin
# capture commandline output and send responses if nothing was read
def interact(command, answers)
puts command
line = ""
write = false
PTY.spawn(command) do |output, input, pid|
loop do
rs, ws, = IO.select([output], [input])