Skip to content

Instantly share code, notes, and snippets.

@jonathan-kosgei
jonathan-kosgei / plugin.php
Created August 15, 2017 10:29
Wordpress enqueue scripts
function ensure_select2() {
wp_enqueue_style( 'select2', plugin_dir_url( __FILE__ ) . 'assets/css/select2.min.css' );
wp_enqueue_script( 'select2', plugin_dir_url( __FILE__ ) . 'assets/js/select2.js', array(), '1.0.0', true );
}
add_action( 'admin_head' , 'ensure_select2' );
@jonathan-kosgei
jonathan-kosgei / functions.php
Created August 15, 2017 07:37
Woocommerce auto update cart on quantity change
add_action( 'wp_footer', 'cart_update_qty_script' );
function cart_update_qty_script() {
if (is_cart()) :
?>
<script>
jQuery('div.woocommerce').on('change', '.qty', function(){
jQuery("[name='update_cart']").trigger("click");
});
</script>
<?php
@jonathan-kosgei
jonathan-kosgei / Vagrantfile
Created July 19, 2017 09:05
Kubernetes Vagrant Setup
$script = <<SCRIPT
# Install docker
curl -fsSL get.docker.com | sh
# Install kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
# Install kubeadm
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
@jonathan-kosgei
jonathan-kosgei / docker_clean_ci.sh
Last active July 15, 2017 07:18
Delete all images in order of dependency excluding selected base images for faster builds
#!/bin/bash
function list_include_item { local list="$1"; local item="$2"; if [[ $list =~ (^|[[:space:]])"$item"($|[[:space:]]) ]] ; then result=0; else result=1; fi; return $result;};
bases="alpine:latest nginx:1.11.3-alpine"
delete=
# append latest tag to each image
for item in $(docker images --format "{{.Repository}}:{{.Tag}}@{{.ID}}")
do
export IFS=' '
IFS='@'; arr=($item); unset IFS;
@jonathan-kosgei
jonathan-kosgei / docker_image_clean.sh
Last active July 12, 2017 13:08
Clear all images on a Docker host except base images
#!/bin/bash
# set variable with base image names
# get base image ids and set in other list
all_images=`mktemp`
base_images=`mktemp`
#base_image_names="alpine linux"
#ids=`docker images --no-trunc -q $(base_image_names)`
bases="sha256:7328f6f8b41890597575cbaadc884e7386ae0acc53b747401ebce5cf0d624560 sha256:33aa78cbda15ae84375c46dfc3fc07560c9af8e7b8f37745d2c6542e2affec9f"
docker images -q --no-trunc > $all_images
@jonathan-kosgei
jonathan-kosgei / thirdpartypaths.json
Created May 3, 2017 06:47
Kubernetes Third Party Path json
{
"/apis/{fqdn}/v1/{resource}": {
"get": {
"security": [
{
"Bearer": [
]
}
],
FROM debian:jessie
MAINTAINER a.mulholland
RUN apt-get update && apt-get upgrade -y &&\
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - &&\
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list &&\
curl -sL https://deb.nodesource.com/setup_6.x | bash -
apt-get install -y nodejs yarn nginx php5-fpm php5-mysqlnd php5-curl php5-mcrypt php5-gd git curl mysql-client openssh-client
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
""" Make sure to create the "backup" tag on the volumes you want to backup.
For authentication, setup the aws policy and user as specified in the snapshot-trust.json and snapshot-policy.json
Inspired by: https://serverlesscode.com/post/lambda-schedule-ebs-snapshot-backups/
"""
from time import gmtime, strftime
import boto3
region = "us-west-2"
backup_tag = "backup"
@jonathan-kosgei
jonathan-kosgei / largest_number_in_nested_number_list.py
Last active March 5, 2017 19:02
Find largest number in nested number list Python
def max_in_nested_number_list(numbers):
largest = 0
for item in numbers:
if isinstance(item, list):
numbers.append(max_in_nested_number_list(item))
else:
largest = item if item>largest else largest
return largest
@jonathan-kosgei
jonathan-kosgei / installing_calico_for_docker_networking.sh
Last active March 3, 2017 11:57
Installing Calico for Docker Networking
#!/bin/sh
# Setup Calico for Docker on Ubuntu 16.04
# Change to the internal ip of your node
NODE_IP=ip route get 8.8.8.8 | awk '{print $NF; exit}'
# Install docker
sudo apt-get install -y --no-install-recommends \
apt-transport-https \
ca-certificates \