Skip to content

Instantly share code, notes, and snippets.

View amosshapira's full-sized avatar

Amos Shapira amosshapira

  • Sydney, Australia
View GitHub Profile
@amosshapira
amosshapira / gist:fc4bedeacf0686471d8e
Last active August 29, 2015 14:16
OBSOLETE - SEE COMMENT: Installing extra gem's in Vagrant environment
gem install --verbose -i ~/.vagrant.d/gems -n ~/.vagrant.d/gems/bin --no-ri --no-rdoc rspec-retry
@amosshapira
amosshapira / gist:e043ef116bfdfe92e3cd
Created March 2, 2015 01:31
Reading AWS cli keys into vagrant-aws configuration
# NOTE: Uses ~/.aws/config to get the region and ~/.aws/credentials to get
# AWS credentials.
# TODO: When running on EC2, use the auto-IAM data
config.vm.provider :aws do |aws, override|
aws_credentials = IniFile.load(File.expand_path('~/.aws/credentials'))
aws.access_key_id = aws_credentials['default']['aws_access_key_id']
aws.secret_access_key = aws_credentials['default']['aws_secret_access_key']
aws_config = IniFile.load(File.expand_path('~/.aws/config'))
aws.region = aws_config['default']['region']
end
Using jq 1.4.2 (http://stedolan.github.io/jq/)
Extract security group id's of all EC2 instances:
aws ec2 describe-instances | jq '.Reservations[].Instances[].SecurityGroups[].GroupId'
# URI of the local (caching) HTTP proxy
LOCAL_HTTP_PROXY = 'http://192.168.33.200:8123'
# Configures vagrant-cachier and vagrant-proxyconf.
# Should be called only on "local machine" providers.
def configure_caching(config)
if Vagrant.has_plugin?('vagrant-cachier')
config.cache.enable_nfs = true
config.cache.enable :gem
config.cache.enable :npm
@amosshapira
amosshapira / relocate
Created April 7, 2015 07:10
Relocating ElasticSearch shards to random data nodes
#!/bin/bash
# unset all proxy environment variables
eval $(env | fgrep -i proxy | awk -F= '{ print "unset", $1 }')
curl -s -XGET http://127.0.0.1:9200/_cat/shards | grep -w UNASSIGNED | awk '{ print "INDEX="$1, "SHARD="$2 }' |
while read input
do
echo $input
eval $input
@amosshapira
amosshapira / gist:37a38bbbe388f4271ce2
Created April 28, 2015 02:05
Extract subnet id's from AWS using jq and aws cli
# "vpc-12345678" is a default VPC we want to exclude
# "-r" tells jq not to quote the output
aws ec2 describe-subnets | \
jq -r '.Subnets[] | select(.VpcId != "vpc-12345678")| .SubnetId' | \
sort -u
@amosshapira
amosshapira / gist:bb062632ae2379df6a57
Created April 29, 2015 06:25
Fetch AWS instance console output via CLI. Requires "jq"
aws ec2 get-console-output --instance-id instance-id | jq -r '.Output'
@amosshapira
amosshapira / get-user-data
Created May 6, 2015 00:35
Get the "user-data" from a running EC2 instance
INSTANCE_ID=...
aws ec2 describe-instance-attribute --instance-id "$INSTANCE_ID" --attribute userData | \
jq -r '.UserData.Value' | \
base64 -D
@amosshapira
amosshapira / get-s3-size
Created June 4, 2015 03:39
Gert total size of all current accounts' S3 buckets
# Print total size of all buckets in TB's (1024^3 bytes)
# The second ("list-objects") call was taken from http://serverfault.com/a/644795/8972
aws s3api list-buckets |
jq -r '.Buckets[] | .Name' | \
while read bucket
do
aws s3api list-objects --bucket $bucket --output json --query "sum(Contents[].Size)"
done
| awk '{ s+= $1 } END '{ printf "%d\n", s/1024^3 }'

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this: