Skip to content

Instantly share code, notes, and snippets.

View srs81's full-sized avatar

Suman srs81

  • USA
View GitHub Profile
@srs81
srs81 / runEC2instances.py
Created September 26, 2012 17:29
Python: Run new EC2 instances, giving them names and assigning IP addresses
#!/usr/bin/python
#
# Start new EC2 instances
#
import boto, sys, time
print "Please enter your AWS credentials below."
# AWS credentials
@srs81
srs81 / ec2_mount.sh
Created December 5, 2012 18:17
Attach, format and mount a new EBS volume on an EC2 instance
# Variables
VOLUME=/dev/sdf
DIRECTORY=/var/www/html/
USER=apache
GROUP=apache
# Commands
mkfs -t ext4 $VOLUME
mount $VOLUME $DIRECTORY
echo "$VOLUME $DIRECTORY ext4 noatime 0 0" | sudo tee -a /etc/fstab
@srs81
srs81 / write_speed.php
Last active December 10, 2015 15:38
Test the speed of writing 10,000 random strings 100 times each (1,000,000 lines total) to disk. Run as "time php write_speed.php"
<?php
// Length of each line
$length = 40;
// Open up a file
$file = fopen("test.txt", "w");
// Generate 10,000 strings
for ($iii=0; $iii<=10000; $iii++) {
import happybase, sys, os, string
# VARIABLES
# HBase Thrift server to connect to. Leave blank for localhost
server = ""
# Connect to server
c = happybase.Connection(server)
# Get the full list of tables
@srs81
srs81 / happybase_test_put_counter.py
Created May 30, 2012 22:49
Python code to test HappyBase library (HBase), and counter and put speeds
import happybase
import time, random
# Number of test iterations
ITERATIONS = 10000
# Make the HBase connection
connection = happybase.Connection()
# Create the test table, with a column family
@srs81
srs81 / glacier_layer2.py
Created October 15, 2012 22:57
Sample boto AWS Glacier connection/upload/delete code
# Author: Suman
# Import boto's layer2
import boto.glacier.layer2
# Various variables for AWS creds, vault name, local file name
awsAccess = "AKIAxxxx"
awsSecret = "YouRSecRetKeY"
vaultName = "YourVaultName"
fileName = "LocalFileName"
@srs81
srs81 / ec2_auto_stop_start.py
Created August 10, 2012 21:01
Python: Auto start and stop EC2 instances at certain times of the day
#!/usr/bin/python
#
# Auto-start and stop EC2 instances
#
import boto, datetime, sys
from time import gmtime, strftime, sleep
# AWS credentials
aws_key = "AKIAxxx"
aws_secret = "abcd"
@srs81
srs81 / hbase_export_csv.py
Last active July 14, 2020 13:19
Export all data from HBase database to CSV in this format: row-key, column-key, value
import happybase, sys, os, string
# VARIABLES
# Output directory for CSV files
outputDir = "/mnt"
# HBase Thrift server to connect to. Leave blank for localhost
server = ""
# Connect to server
c = happybase.Connection(server)
@srs81
srs81 / android_version_model.py
Created May 3, 2012 21:32
From useragent => find Android version, model, device (tablet/phone)
#
# Given a useragent string, return these results:
# Android version, device model name, type (tablet/phone)
#
import re
def android_details (useragent):
result = {}
result["aVersion"] = "Other"
result["amake"] = "Other"