Skip to content

Instantly share code, notes, and snippets.

View ffledgling's full-sized avatar
🏠
🔢

Anhad Jai Singh ffledgling

🏠
🔢
View GitHub Profile
@ffledgling
ffledgling / k8s-create-deployment.go
Created July 12, 2017 11:37
kubernetes client-go example: Create a Deployment based on json
package main
import (
"encoding/json"
"log"
"os"
// We use pretty instead of the common go-spew or pretty-printing because,
// go-spew is vendored in client-go and causes problems
"github.com/kr/pretty"
@ffledgling
ffledgling / rbd-create.go
Created July 10, 2017 14:44
ceph-go example: create rbd volume with image features
func createRBDStorage() error {
// Runs the equivalent of rbd --pool ffledgling-pool ls
// Contains basic connection logic that's reusable
log.Println("Function started...") // We have this because connection setup etc take a while.
// If like me, you tried this first and expected it to work, it doesn't:
/*
conn, _ := rados.NewConn()
args := []string{"--name", "client.ffledgling", "--conf", "/home/ffledgling/ceph.conf"}
@ffledgling
ffledgling / rbd-ls.go
Last active July 10, 2017 14:47
ceph-go example: List volumes in a particular pool
func listRBDVols() error {
// Runs the equivalent of rbd --pool ffledgling-pool ls
// Contains basic connection logic that's reusable
log.Println("Function started...") // We have this because connection setup etc take a while.
// If like me, you tried this first and expected it to work, it doesn't:
/*
conn, _ := rados.NewConn()
args := []string{"--name", "client.ffledgling", "--conf", "/home/ffledgling/ceph.conf"}
@ffledgling
ffledgling / ceph-osd-lspools.go
Last active July 10, 2017 14:16
ceph-go example: Connect to cluster, list osd pools
func listOSDPools() {
// Runs the equivalent of ceph osd lspools
// Contains basic connection logic that's reusable
log.Println("Function started...") // We have this because connection etc take a while.
// If like me, you tried this first and expected it to work, it doesn't:
/*
conn, _ := rados.NewConn()
args := []string{"--name", "client.ffledgling", "--conf", "/home/ffledgling/ceph.conf"}
@ffledgling
ffledgling / verify-postbuild-groovy-changes.groovy
Created March 14, 2017 14:26
Use this script to check that we managed to modify all of the groovy post build scripts correctly. Search for a pattern in the text of the script. For example to check if a URL was changed correctly, or to make sure there are no jobs with a particular influxdb URL in their postbuild
def ji = Jenkins.instance
def job_pattern = /.*/ //Job Name pattern, used to select jobs we want to select
def script_pattern = /http:\/\/influx.mydomain.com:8086\/write\?db=k8s-vm-parity/
def matchedJobs = ji.items.findAll { job ->
job.name =~ job_pattern
}
@ffledgling
ffledgling / filter-job-builds-by-param-values.groovy
Created March 14, 2017 11:20
Groovy script for use with Jenkins to get builds of jobs that were run with a a certain parameter set to a certain value.
//def hi = hudson.model.Hudson.instance
// Just use Jenkins.instance, it's the same thing
def ji = Jenkins.instance
def param_name = "GERRIT_REFSPEC"
def job_pattern = /.*/ //Job Name pattern, used to select jobs we want to select
def param_value_filter = /.*/ // Pattern to select values of
def matchedJobs = ji.items.findAll { job ->
@ffledgling
ffledgling / primes.cpp
Created September 3, 2016 18:55
Compute Primes
/* Calculate primes upto the first 10^6 numbers
* Checked and tested the first 1000 primes for sanity sake
*/
#define PRIME_SIZE 500000 // Half of 10^6, we really don't need to store even numbers
#define PRIME_SIZE_ROOT 708 // precomputed sqrt(PRIME_SIZE)
#include<iostream>
#include<cstdio>
using namespace std;
@ffledgling
ffledgling / Makefile
Created August 25, 2016 15:57
Fire up a cloud instance of Fedora 22 locally with qemu-kvm
# This is a makefile to use the default fedora cloud image to start a container.
# It lets you create projects and save them separately, based off of a common base image
# Define and declare variables
SHELL := /bin/bash
IMG_STORE := /spare/local/$(USER)/.qemu-kvm-image-store
#IMG_NAME := Fedora-Cloud-Base-24-1.2.x86_64.qcow2
IMG_NAME := Fedora-Cloud-Base-22-20150521.x86_64.qcow2
#IMG_URL := https://download.fedoraproject.org/pub/fedora/linux/releases/24/CloudImages/x86_64/images/$(IMG_NAME)
IMG_URL := https://dl.fedoraproject.org/pub/fedora/linux/releases/22/Cloud/x86_64/Images/$(IMG_NAME)
@ffledgling
ffledgling / yamlls.sh
Created June 21, 2016 11:25
Function to pretty prit yaml file groups in a directory
yamlls() {
local f
local t
local _color
declare -A types=()
for f in *.*.yaml; do
t=${f%.yaml}
@ffledgling
ffledgling / fd2.sh
Created September 4, 2015 16:29
File descriptor demo; bash; How to isolate and collect error messages for particular from function calls, across subshells etc.
#!/bin/bash
# Create file to accumulate errors
errfile=$(mktemp)
echo "Error File is ${errfile}"
# Have fd 3 point to where fd 2 points currently
exec 3>&2
# wrapper function