Skip to content

Instantly share code, notes, and snippets.

@shantanuo
shantanuo / mongo-dump-csv.sh
Created August 8, 2016 08:56 — forked from mderazon/mongo-dump-csv.sh
Export all of Mongodb collections as csv without the need to specify fields
OIFS=$IFS;
IFS=",";
# fill in your details here
dbname=DBNAME
user=USERNAME
pass=PASSWORD
host=HOSTNAME:PORT
# first get all collections in the database
@shantanuo
shantanuo / persist_cache_to_disk.py
Created June 17, 2016 13:24 — forked from tohyongcheng/persist_cache_to_disk.py
Persisting a cache in Python to disk using a decorator
def persist_cache_to_disk(filename):
def decorator(original_func):
try:
cache = pickle.load(open(filename, 'r'))
except (IOError, ValueError):
cache = {}
atexit.register(lambda: pickle.dump(cache, open(filename, "w")))
def new_func(*args):
@shantanuo
shantanuo / s3-curl-backups.md
Created April 25, 2016 13:47 — forked from jareware/s3-curl-backups.md
Simple, semi-anonymous backups with S3 and curl

⇐ back to the gist-blog at jrw.fi

Simple, semi-anonymous backups with S3 and curl

Backing stuff up is a bit of a hassle, to set up and to maintain. While full-blown backup suites such as duplicity or CrashPlan will do all kinds of clever things for you (and I'd recommend either for more complex setups), sometimes you just want to put that daily database dump somewhere off-site and be done with it. This is what I've done, with an Amazon S3 bucket and curl. Hold onto your hats, there's some Bucket Policy acrobatics ahead.

There's also a tl;dr at the very end if you just want the delicious copy-pasta.

Bucket setup

@shantanuo
shantanuo / download.py
Created January 31, 2016 07:38 — forked from peterbe/download.py
Download from bugzilla.mozilla.org, Upload to autocompeter.com. See http://www.peterbe.com/plog/a-quicksearch-for-bugzilla-using-autocompeter for context.
import datetime
import json
import os
import hashlib
import time
import requests
def bulk_upload(auth_key, documents):
@shantanuo
shantanuo / gist:66fc8c42c6896a103801
Created January 28, 2016 10:59 — forked from griggheo/gist:2698152
dynamodb batchwriteitem in boto
import os
import sys
import subprocess
import re
import optparse
import boto
dynamodb_conn = boto.connect_dynamodb(aws_access_key_id='MY_ACCESS_KEY_ID', aws_secret_access_key='MY_SECRET_ACCESS_KEY')
table_name = 'mytable'
dynamodb_table = dynamodb_conn.get_table(table_name)
Sl NO. District Assembly Constituency Winning Candidate Party Total Vote Runner-Up Candidate Party Total Vote
1 PASHCHIM CHAMPARAN 1-VALMIKI NAGAR Dhirendra Pratap Singh Alias Rinku Singh IND 66860 Irshad Hussain INC 33280
2 PASHCHIM CHAMPARAN 2-RAMNAGAR Bhagirathi Devi BJP 82166 Purnmasi Ram INC 64178
3 PASHCHIM CHAMPARAN 3-NARKATIAGANJ Vinay Varma INC 57212 Renu Devi BJP 41151
4 PASHCHIM CHAMPARAN 4-BAGAHA Raghaw Sharan Pandey BJP 74476 Bhishm Sahani JD(U) 66293
5 PASHCHIM CHAMPARAN 5-LAURIYA Vinay Bihari BJP 57351 Ran Kaushal Pratap Singh RJD 39778
6 PASHCHIM CHAMPARAN 6-NAUTAN Narayan Prasad BJP 66697 Baidyanath Prasad Mahto JD(U) 52362
7 PASHCHIM CHAMPARAN 7-CHANPATIA Prakash Rai BJP 61304 N. N. Sahi JD(U) 60840
8 PASHCHIM CHAMPARAN 8-BETTIAH Madan Mohan Tiwari INC 66786 Renu Devi BJP 64466
@shantanuo
shantanuo / gist:1f8a0c680cdf0e5ba864
Created December 9, 2015 06:28 — forked from spinscale/gist:5466258
Geo location reproduction.
curl -X PUT localhost:9200/geotest/
curl -X PUT localhost:9200/geotest/geotest/_mapping -d '{
"geotest": {
"properties": {
"location": {
"type": "geo_point",
"lat_lon": true,
"geohash": true
}
@shantanuo
shantanuo / gist:44836d5b9a476ef3608a
Created November 30, 2015 11:34 — forked from markbirbeck/gist:1684494
[ElasticSearch] Insert 5 records and query for a single record, with facets: Successfully returns a count of 1 in the facets
# Create an index:
#
curl -XDELETE 'http://127.0.0.1:9200/articles'
curl -XPUT 'http://127.0.0.1:9200/articles'
# Insert the action mapping, as a child of articles:
#
curl -XPUT 'http://127.0.0.1:9200/articles/article/_mapping' -d '
{
"article": {
@shantanuo
shantanuo / s3etag.sh
Created November 22, 2015 14:26 — forked from emersonf/s3etag.sh
A Bash script to compute ETag values for S3 multipart uploads on OS X.
#!/bin/bash
if [ $# -ne 2 ]; then
echo "Usage: $0 file partSizeInMb";
exit 0;
fi
file=$1
if [ ! -f "$file" ]; then
@shantanuo
shantanuo / gist:bb4ff2d7af929df431bc
Last active September 3, 2015 12:27 — forked from iMilnb/gist:ba7b46dfc854544bf3c8
Dynamic ipsec and racoon configuration generation for AWS EC2 VPN using boto3 and Jinja2
#!/usr/bin/env python
# $ cat ipsec_conf.tmpl
# {#
#
# cgw_in_addr: customer_gateway tunnel_inside_address ip_address
# cgw_in_cidr: customer_gateway tunnel_inside_address network_cidr
# vgw_in_addr: vpn_gateway tunnel_inside_address ip_address
# vgw_in_cidr: vpn_gateway tunnel_inside_address network_cidr
# cgw_out_addr: customer_gateway tunnel_outside_address