Skip to content

Instantly share code, notes, and snippets.

View ambakshi's full-sized avatar

Amit Bakshi ambakshi

View GitHub Profile
@ambakshi
ambakshi / puppet-node-extract.awk
Last active August 29, 2015 14:04
Awk script to extract class decls from pp files
#!/usr/bin/env gawk
#
# Only print stuff inside the puppet class:
#$0 ~ /^[ \t]*$/ {on = 0}
#
BEGIN {
cls_name="";
}
#!/bin/bash
set -e
## requires running as root because filesystem package won't install otherwise,
## giving a cryptic error about /proc, cpio, and utime. As a result, /tmp
## doesn't exist.
[ $( id -u ) -eq 0 ] || { echo "must be root"; exit 1; }
tmpdir=$( mktemp -d )
@ambakshi
ambakshi / go-vs-aws.txt
Last active August 29, 2015 14:04
Go compiled binary to query an instance for tags vs aws cli.
$ time aws ec2 describe-instances --instance-ids "$(curl -s http://169.254.169.254/latest/meta-data/instance-id)" --query 'Reservations[*].Instances[*].Tags' --output text
Owner amit.bakshi
Billing_Code ops
Name ops-deploy-003
Hostgroup ops-deploy
Megatron_Deployment deploy
real 0m1.016s
user 0m0.321s
sys 0m0.134s
OPTS_SPEC="\
$(basename $0 .sh) subcommand <options>
subcommands:
data - download a dataset
--
h,help show help
d,debug debug output
v,verbose verbose output
$ ~/parse-with-help-from-git.sh data --game-tag foo
Hi from the data command
INPUT_FILE=
DATASET=
GAME_TAG=foo
[amit.bakshi@gii1302greendog bin (master)]
$ ~/parse-with-help-from-git.sh data --bad-arg foo
error: unknown option `bad-arg'
usage: parse-with-help-from-git subcommand <options>
subcommands:
@ambakshi
ambakshi / jenkins-master.conf
Last active August 29, 2015 14:06
Jenkins upstart script
#upstart script for a jenkins swarm agent
description "upstart script for jenkins-master"
start on started networking
stop on runlevel [016]
# respawn the job up to 10 times within a 10 second period.
# If the job exceeds these values, it will be stopped and
# marked as failed.
@ambakshi
ambakshi / block-device-map.json
Last active August 29, 2015 14:06
Using jq to modify a Json object
// Modify the following JSON object such that the SnapshotId of device /dev/sda1 is 'snap-12345678' and size is 4,
// while maintaining the structure of the of the object.
// You can't make assumptions about how it is formatted, except to say it's legal json.
[
{
"Ebs": {
"VolumeSize": 32,
"SnapshotId": "snap-ee16314e",
"DeleteOnTermination": true
@ambakshi
ambakshi / parse-with-help-from-git.sh
Last active August 29, 2015 14:06
Use git-rev-parse to do the dirty work for you
#!/bin/bash
OPTS_SPEC="\
$(basename $0 .sh) subcommand <options>
subcommands:
data - download a dataset
--
h,help show help
d,debug debug output
@ambakshi
ambakshi / aws-sdb-example.md
Last active April 24, 2017 14:42
Accessing sdb from the awscli
$ aws configure set preview.sdb true
$ aws sdb create-domain skv
$ aws sdb put-attributes --domain-name skv --item-name ami_idx --attributes Name=app-mwios-asg,Value=1
$ aws sdb put-attributes --domain-name skv --item-name ami_idx --attributes Name=app-ccand-asg,Value=5

$ aws sdb get-attributes --domain-name skv --item-name ami_idx --attribute-names app-mwios-asg
{
"Attributes": [

{

@ambakshi
ambakshi / jdk8-update-alternatives.sh
Last active August 29, 2015 14:06
Update system java to jdk8
#!/bin/bash
## JDK=$(cd /usr/java/jdk1.8* && pwd)
JDK=/usr/java/latest
update-alternatives \
--install /usr/bin/java java $JDK/jre/bin/java 18000 \
--slave /usr/lib/jvm/jre jre $JDK/jre \
--slave /usr/bin/javac javac $JDK/bin/javac \
--slave /usr/bin/javah javah $JDK/bin/javah \
--slave /usr/bin/javap javap $JDK/bin/javap \
--slave /usr/bin/jar jar $JDK/bin/jar \