Skip to content

Instantly share code, notes, and snippets.

@ashayh
ashayh / jdk7_ubuntu_install.sh
Created September 6, 2012 21:40
Install Oracle JDK 7 on Ubuntu
#!/bin/bash
JAVA_BIN="/usr/lib/jvm/jdk1.7.0/bin/java"
JAVA_CURR_BIN=$(update-alternatives --query java | awk '/^Value/{print $2}')
if [[ ${JAVA_BIN} = ${JAVA_CURR_BIN} ]] ; then
echo "Correct java already in use. Set java: ${JAVA_CURR_BIN}"
echo "About to install: ${JAVA_BIN}"
echo "Exit with nothing to do"
exit
@ashayh
ashayh / Better Usage.md
Created October 9, 2012 20:45
Strip package scripts from .deb packages (postinst, postrm, preinst, prerm)

The best way to use this tool is to hook apt's use of dpkg to run it before doing any package installs.

In your apt.conf, put this:

DPkg::Pre-Install-Pkgs {"xargs -rL1 bash /path/to/stripdeb.sh 2>&1 | logger -t stripdeb"}

Then, a demo:

% sudo apt-get install mysql-server-5.1

@ashayh
ashayh / create_ebs.rb
Created October 15, 2012 00:01 — forked from lusis/create_ebs.rb
Small script to setup ec2 instances and EBS volumes for my blog post series
# Create 4 volumes and attach them to hdb
%w[sdi sdj sdk sdl].each do |dev|
volume = AWS.volumes.new :device => "/dev/#{dev}", :size => 5, :availability_zone => hdb.availability_zone
volume.server = hdb
volume.save
end
@ashayh
ashayh / manage_ebs_raid.rb
Created October 15, 2012 00:03 — forked from jbarciauskas/manage_ebs_raid.rb
Script to manage ebs raid volumes with logical names and timestamps
require 'rubygems'
require 'fog'
require 'ap'
require 'time'
def print_usage()
puts "Assumes all devices from sdc to sdz are available"
puts "Usage: volume attach [aws instance id] ['raid-name' tag value] ['snap-time' tag value]"
puts "Usage: volume detach ['raid-name' tag value] ['snap-time' tag value]"
puts "Usage: volume create ['raid-name' tag value] ['snap-time' tag value]"
@ashayh
ashayh / hostname.rb
Created October 16, 2012 04:26 — forked from hSATAC/hostname.rb
aws ec2 set hostname by tag name
#!/usr/bin/env ruby
require 'rubygems'
require 'aws-sdk'
instance_id = `wget "http://169.254.169.254/latest/meta-data/instance-id" -o /dev/null -O /dev/stdout`
config = {:access_key_id => '',
:secret_access_key => ''}
AWS.config(config)
ec2 = AWS::EC2.new
ec2 = ec2.regions['ap-northeast-1']
@ashayh
ashayh / ec2-metadata
Created October 16, 2012 04:27 — forked from yaronf/ec2-metadata
ec2-metadata: a simple tool for exploring Amazon EC2 metadata, extended with network and VPC info
#!/bin/bash
#
#########################################################################
#This software code is made available "AS IS" without warranties of any #
#kind. You may copy, display, modify and redistribute the software #
#code either by itself or as incorporated into your code; provided that #
#you do not remove any proprietary notices. Your use of this software #
#code is at your own risk and you waive any claim against Amazon #
#Digital Services, Inc. or its affiliates with respect to your use of #
#this software code. (c) 2006-2007 Amazon Digital Services, Inc. or its #
@ashayh
ashayh / gist:3921878
Created October 20, 2012 03:16 — forked from clintongormley/gist:3888120
Upgrading a running elasticsearch cluster

Yesterday I upgraded our running elasticsearch cluster on a site which serves a few million search requests a day, with zero downtime. I've been asked to describe the process, hence this blogpost.

To make it more complicated, the cluster was running elasticsearch version 0.17.8 (released 6 Oct 2011) and I upgraded it to the latest 0.19.10. There have been 21 releases between those two versions, with a lot of functional changes, so I needed to be ready to roll back if necessary.

Our setup:

  • elasticsearch

We run elasticsearch on two biggish boxes: 16 cores plus 32GB of RAM. All indices have 1 replica, so all data is stored on both boxes (about 45GB of data). The primary data for our main indices is also stored in our database. We have a few other indices whose data is stored only in elasticsearch, but are updated once daily only. Finally, we store our sessions in elasticsearch, but active sessions are cached in memcached.

@ashayh
ashayh / config-initializers-elasticsearch.rb
Created October 20, 2012 04:23 — forked from ches/config-initializers-elasticsearch.rb
Some Tire setup tips for ElasticSearch
# Use a prefix for the index names that Tire uses so that the test suite doesn't
# stomp on dev data and you can work on multiple apps with ES, but keep tidy
# unadorned names for production.
unless Rails.env.production?
Tire::Model::Search.index_prefix("#{Rails.application.class.parent_name.downcase}_#{Rails.env}")
end
@ashayh
ashayh / __readme.markdown
Created October 20, 2012 04:43 — forked from karmi/.gitignore
ElasticSearch bootstrap script and node configuration for Ubuntu [https://gist.github.com/2050769]

Helper files for the https://gist.github.com/2050769 gist

This repository contains files tailored for bootstrapping, installing and configuring ElasticSearch with Chef Solo on the Ubuntu operating system.

After you have downloaded the files, edit the node configuration:

$EDITOR node_ubuntu.json
@ashayh
ashayh / index.html
Created October 21, 2012 00:49 — forked from crofty/index.html
A example of using Google Map tiles with the Leaflet mapping library - http://matchingnotes.com/using-google-map-tiles-with-leaflet
<!DOCTYPE html>
<html>
<head>
<title>Leaflet</title>
<link rel="stylesheet" href="http://code.leafletjs.com/leaflet-0.3.1/leaflet.css" />
<script src="http://code.leafletjs.com/leaflet-0.3.1/leaflet.js"></script>
<script src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script>
<script src="https://raw.github.com/gist/2197042/2b90c41b39b7d5b3a851d8f256de2ebd3fe1fb74/leaflet-google.js"></script>
</head>
<body>