Skip to content

Instantly share code, notes, and snippets.

View makeittotop's full-sized avatar

abhishek pareek makeittotop

  • Canada
  • 17:51 (UTC -08:00)
View GitHub Profile
@makeittotop
makeittotop / upload_latest_file_to_s3
Last active May 17, 2016 12:54
uploading a file to aws s3 using the Python boto API.
#!/usr/bin/env python
import sys, os, glob
# amazon web services api
import boto
AWS_ACCESS_KEY_ID='****'
AWS_SECRET_ACCESS_KEY='****'
@makeittotop
makeittotop / upload_file_to_glacier.py
Created March 17, 2015 16:59
Script to upload a given file to the amazon glacier
#!/usr/bin/env python
import sys
# amazon web services api
import boto
from boto.glacier.exceptions import UnexpectedHTTPResponseError
AWS_ACCESS_KEY_ID='****'
AWS_SECRET_ACCESS_KEY='****'
@makeittotop
makeittotop / find_info.js
Last active May 17, 2016 11:46
A mongodb function to wade through a collection and report the `status` of a particular `stream`.
function find_info(stream, status) {
var query = {};
var key = stream + "_status";
query[key] = status;
db.tasks.find(query).forEach(
function(doc) {
print("Task " + status + ": " + doc[stream+"_id"] +", owner: " + doc.task_owner);
}
);
}
@makeittotop
makeittotop / get_droplet_status.py
Created March 18, 2015 09:34
Get a health / status check on your digitalocean droplets. Put this in a tiny flask app for example, and you can check their status anytime on the go.
import digitalocean
manager = digitalocean.Manager(token="****")
my_droplets = manager.get_all_droplets()
'''
for d in my_droplets:
print("Droplet name: ", d.name)
@makeittotop
makeittotop / create_droplet.py
Created March 18, 2015 09:38
Create a digitalocean droplet on the fly. I put this in a flask web app to speed up the process even more.
#!/usr/bin/env python
import digitalocean
droplet = digitalocean.Droplet(
token="****",
name='test',
region='nyc2', # NewYork 2
image='ubuntu-14-04-x64', # ubuntu 14.04 x64
size_slug='512mb', # 512MB
@makeittotop
makeittotop / mongo_js_function_loader.js
Created March 19, 2015 13:47
A special system collection named system.js, can store JavaScript functions for reuse. Made use of this feature to implement the auto-increment feature found in traditional rdbms.
# To store a function use the db.collection.save() method
db.system.js.save(
{
_id: "foo_bar",
value : function(x, y) { return x * y; }
}
)
db.system.js.save(
@makeittotop
makeittotop / mongo_cursor_iterate.js
Last active August 29, 2015 14:17
query data and iterate over the matched data
var cur = db.tasks.find({
'$or': [
{'upload_status': 'active'},
{'upload_status': 'pending'}]
});
while(cur.hasNext()) {
printjson(cur.next());
}
@makeittotop
makeittotop / git_api
Last active August 29, 2015 14:17
git api
# user info
curl -XGET https://api.github.com/users/makeittotop -vv
# note the X-RateLimit-Limit and X-RateLimit-Remaining headers. This indicates how many requests
# a client can make in a rolling time period (typically an hour) and how many of those requests
# the client has already spent.
curl -XGET https://api.github.com/users/makeittotop -vv -i
@makeittotop
makeittotop / goog_cloud_storage.py
Created March 23, 2015 11:04
List all your google cloud storage bucket
# https://cloud.google.com/storage/docs/gspythonlibrary
# https://github.com/pyca/pyopenssl/issues/128
# faced issue with pyopenssl version 0.10 and 0.14 both on the system in different dirs, lib64 and lib respectively. Needed to remove
# lib64 one.
'''
In [1]: import OpenSSL
@makeittotop
makeittotop / goog_cloud_storage_create_bucket.py
Created March 23, 2015 11:55
Create a bucket on google nearline if it doesn't already exist
#!/usr/bin/env python
import boto
import gcs_oauth2_boto_plugin
import os, sys
import shutil
import StringIO
import tempfile
import time