Skip to content

Instantly share code, notes, and snippets.

View miry's full-sized avatar

Michael Nikitochkin miry

View GitHub Profile
@miry
miry / bench.rb
Created August 29, 2017 17:11
Compare map vs array search for Ruby 2.4.1
require 'benchmark'
module FastAttributes
TRUE_VALUES_ARRAY = [true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON'].freeze
FALSE_VALUES_ARRAY = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF'].freeze
TRUE_VALUES = {true => nil, 1 => nil, '1' => nil, 't' => nil, 'T' => nil, 'true' => nil, 'TRUE' => nil, 'on' => nil, 'ON' => nil}.freeze
FALSE_VALUES = {false => nil, 0 => nil, '0' => nil, 'f' => nil, 'F' => nil, 'false' => nil, 'FALSE' => nil, 'off' => nil, 'OFF' => nil}.freeze
end
@miry
miry / wifi.tf
Last active April 28, 2019 20:14
Set up Wifi on Raspberry Pi 3 with Ubuntu server
variable "server_ip" {
default = "10.0.0.2"
}
variable "wlan_ssid" {
default = "free wifi hotspot"
}
variable "wlan_psk" {
default = "changeme"
@miry
miry / set-hostname.tf
Last active June 21, 2019 14:00
Change ubuntu hostname with Terraform. `terraform apply -target=null_resource.set-hostname`
variable "server_ip" {
default = "10.0.0.2"
}
variable "server_hostname" {
default = "node01"
}
# Ubuntu reference for hostnamectl: http://manpages.ubuntu.com/manpages/trusty/man1/hostnamectl.1.html
resource "null_resource" "set-hostname" {
@miry
miry / raspi3-ubuntu-upgrade.tf
Last active July 11, 2022 15:45
Upgrade ubuntu on Raspberry Pi 3. `terraform apply -target=null_resource.upgrade-packages`
variable "server_ip" {
default = "10.0.0.2"
}
# Terraform documentation
# * Provisioner null_resource: https://www.terraform.io/docs/provisioners/null_resource.html
# * Provisioner Connections: https://www.terraform.io/docs/provisioners/null_resource.html
# Ubuntu issues:
# https://bugs.launchpad.net/ubuntu/+source/linux-raspi2/+bug/1652270
@miry
miry / ssh-github-authorized-keys.sh
Last active June 1, 2018 14:27
Import Github public keys.
# Updated 2017.07.05 Thanks to https://www.reddit.com/user/xeoomd for the url
# from comment https://www.reddit.com/r/devops/comments/6l6uhm/ubuntu_server_1606_on_raspberry_pi_3_via_terraform/djsf1ai/
# Replace GTIHUB_USER with your username in Github
curl -s https://github.com/GTIHUB_USER.keys >> ~/.ssh/authorized_keys
# First version
# curl -s https://api.github.com/users/GTIHUB_USER/keys | grep key | sed 's/.*"key":\s*"\([^\"]*\)"/\1/g' >> ~/.ssh/authorized_keys
@miry
miry / admins.yaml
Last active June 10, 2017 11:59
# kubectl apply -f admins.yaml --validate=false
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1alpha1
metadata:
name: miry-admin-binding
subjects:
- kind: User
name: [email protected]
roleRef:
kind: ClusterRole
name: cluster-admin
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1alpha1
metadata:
name: admin-role
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["*"]
---
kind: ClusterRoleBinding
@miry
miry / 10-kubeadm.conf.sh
Created March 26, 2017 23:11
Kubernets v1.6.0-rc.1 service config
cat <<EOF > /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--kubeconfig=/etc/kubernetes/kubelet.conf --require-kubeconfig=true"
Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true"
Environment="KUBELET_NETWORK_ARGS=--network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin"
Environment="KUBELET_DNS_ARGS=--cluster-dns=10.96.0.10 --cluster-domain=cluster.local"
Environment="KUBELET_AUTHZ_ARGS=--authorization-mode=Webhook --client-ca-file=/etc/kubernetes/pki/ca.crt"
Environment="KUBELET_EXTRA_ARGS=--cgroup-driver=systemd"
ExecStart=
ExecStart=/usr/bin/kubelet \$KUBELET_KUBECONFIG_ARGS \$KUBELET_SYSTEM_PODS_ARGS \$KUBELET_NETWORK_ARGS \$KUBELET_DNS_ARGS \$KUBELET_AUTHZ_ARGS \$KUBELET_EXTRA_ARGS
@miry
miry / roles.yml
Created March 26, 2017 23:06
Sample Kubernetes admin role for UI
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1alpha1
metadata:
name: kube-system-admin
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["*"]
---
@miry
miry / 01_extract_crt.rb
Last active September 3, 2023 06:32
Extract certificate from the kubernetes config.
require 'optparse'
require 'yaml'
require 'base64'
options = {
config_path: File.join(ENV['HOME'], '.kube', 'config'),
write_dir: File.join(ENV['HOME'], '.kube')
}
OptionParser.new do |opts|