Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash -u
k8s_context=$1
# https://kubernetes.io/docs/tasks/access-application-cluster/list-all-running-container-images/
images=$(kubectl --context $1 get pods --all-namespaces -o jsonpath="{.items[*].spec['initContainers', 'containers'][*].image}" \
| tr -s '[[:space:]]' '\n' \
| sort \
| uniq)
@chulkilee
chulkilee / diff-gemfile.rb
Last active June 26, 2024 14:20
generate changes from git diff Gemfile.lock
#!/usr/bin/env ruby
# frozen_string_literal: true
def read_changes
gem_changes = {}
ARGF.each_line do |line|
next unless /(?<op>[-+]) (?<name>\S+) \((?<ver>\S+)\)/ =~ line.strip
gem_changes[name] ||= {}
@chulkilee
chulkilee / link_parser.ex
Last active June 23, 2019 00:52
Parsing HTTP Link header with NimbleParsec
@chulkilee
chulkilee / gitlab-backfill-service-from-template.rb
Created April 25, 2018 19:34
GitLab: backfill service from template
service_klass_to_property_keys = {
JiraService => %w[api_url url username password]
}
service_klass_to_property_keys.each do |klass, property_keys|
template_properties = klass.find_by!(template: true).properties.slice(*property_keys)
klass.find_each do |service|
service.properties = service.properties.merge(template_properties)
service.save! if service.changed?
@chulkilee
chulkilee / new-phx.sh
Created March 2, 2018 23:21
new-phx.sh
#!/bin/bash -eux
# tested with phoenix 1.3.0
shopt -s nullglob
app_path=$1
elixir_version=${ELIXIR_VERSION:-1.6.1}
echo n | mix phx.new "$app_path" --no-brunch --no-html
cd "$app_path"
@chulkilee
chulkilee / get-cert-chain.sh
Created December 13, 2017 23:09
Get cert chain
servername=
port=
echo \
| openssl s_client -showcerts -servername $servername -connect $servername:$port 2>&1 \
| sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' \
> $servername.crt
@chulkilee
chulkilee / generate-oj-changelog.rb
Created December 14, 2016 22:07
Generate changelog for oj gem
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
entries = []
current_entry = nil
doc = Nokogiri::HTML(open('http://www.ohler.com/dev/oj_misc/release_notes.html'))
body = doc.at_css('.content_box')
body.children.each do |cur|
@chulkilee
chulkilee / Ipify.java
Created March 31, 2015 17:36
Print public ip address from Ipify
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
public class Ipify {
public static void main(String[] args) throws Exception {
URL url = new URL("http://api.ipify.org");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
for (String line; (line = reader.readLine()) != null;) {
System.out.println(line);
@chulkilee
chulkilee / update-ldap-provider.rb
Created February 26, 2015 20:51
Update old LDAP provider name on gitlab
puts Identity.unscoped.group(:provider).count
users = User.includes(:identities).all
duplicated_providers = %w(ldap ldapmain).sort
old_provider = 'ldap'
new_provider = 'ldapmain'
users.each do |u|
next if u.identities.blank?
@chulkilee
chulkilee / deploy.rake
Created January 23, 2015 01:53
capistrano deploy:check for local git repo
namespace :deploy do
namespace :git do
before :check, :local_repo do
on release_roles :all do
unless test "[ -d #{fetch(:local_repo_path)} ]"
execute :mkdir, '-p', fetch(:local_repo_path)
execute :git, "init --bare #{fetch(:local_repo_path)}"
end
end
end