Skip to content

Instantly share code, notes, and snippets.

@sidharthshah
sidharthshah / fetchthumb.py
Created May 17, 2012 05:55
Python command line script to capture screenshots and resize it to Thumb nails
from pyvirtualdisplay import Display
from selenium import webdriver
import sys
from optparse import OptionParser
from PIL import Image
parser= OptionParser()
parser.add_option("--width",action="store", dest="w", type="int", default="300")
parser.add_option("--height",action="store", dest="h", type="int", default="250")
parser.add_option("--output",action="store", dest="op", type="string", default= './thumbnail.png')
(options,args)=parser.parse_args(sys.argv[1:])
@sidharthshah
sidharthshah / gist:3413472
Created August 21, 2012 08:22
Instructions to setup RoR on Ubuntu
sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev
curl -L https://get.rvm.io | bash -s stable --ruby
rvm remove ruby-1.9.3-p194
rvm pkg install zlib
rvm install ruby-1.9.3-p194
@sidharthshah
sidharthshah / gist:3433296
Created August 23, 2012 06:15
MailChimp integration via PyChimp
from postmonkey import PostMonkey
pm = PostMonkey('341a2fc9bc064c33a3481f905d22b069-us5')
#storytellers
pm.listSubscribe(id='d3bb445eae',email_address='iamsidd@gmail.com')
#basic_users
pm.listSubscribe(id='13cbfa7eb2',email_address='iamsidd@gmail.com')
@sidharthshah
sidharthshah / gist:3434268
Created August 23, 2012 08:30
Updating CouchDB's doc with additional field
>>> import couchdb
>>> couch = couchdb.Server()
>>> db = couch['catalog_users']
>>> doc = db['f893955fc22b7ff25fd5d3764a009354']
>>> doc
<Document 'f893955fc22b7ff25fd5d3764a009354'@'19-ea4b426d433b779ff9ed8267b989714e' {'home_zipcode': '', 'city': '', 'fb_user_id': '', 'zipcode': '', 'state': '', 'type': 'Publisher', 'email': 'iamsidd@gmail.com', 'media_url': '', 'status': 'active', 'bio': '', 'couchrest-type': 'Publisher', 'passwd': '97032c0a89cba64bd10f7d221c589f60', 'address1': '', 'address2': '', 'auth': '59b58778-eb69-11e0-9bea-1231390b25d1', 'dob': '', 'key': '59b58778-eb69-11e0-9bea-1231390b25d1', 'super_publisher_id': 'a36c91061da18c0c1ba1c3412409d8aa', 'created_ts': 1338361447, 'name': '', 'access_token': '', 'gender': '', 'publisher_revenue': 0.5, 'customer_type': 'storyteller', 'stories': ['273374'], 'updated_ts': 1338361470, 'published': True}>
>>> doc['internal_rating'] = 4
>>> db.save(doc)
('f893955fc22b7ff25fd5d3764a009354', '20-f5c36653f45f853570f3399793ea560f')
@sidharthshah
sidharthshah / gist:3798088
Created September 28, 2012 05:30
Email Sending Snippet from Gearman
def email_story(worker,job):
email = json.loads(job.data)
if email.has_key("html"):
text_subtype = 'html'
else:
text_subtype = 'plain'
send_to = []
send_to = parse_emails(email['to'])
content="""\
# -*- coding: utf-8 -*-
import os
import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
from hashlib import md5
from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db = client.skoovbot
@sidharthshah
sidharthshah / format_name.py
Last active November 8, 2015 04:49
Simple way to format name
from string import strip
def format_name(name):
#Step 1: Split by ,
#Step 2: Remove any extrac white space in tokens using Map
#Step 3: Reverse List using ::-1
#Step 4: Join with White Space
return " ".join(map(strip, name.split(","))[::-1])
>>> format_name("Shah, Saheb")
'Saheb Shah'
cd ../../frontend/
rm -rf dist
yeoman build
cd ../src/ratingui
rm -rf static/styles
rm -rf static/scripts
rm -rf templates/layout/rating.jinja
cp -vr ../../frontend/dist/styles static
cp -vr ../../frontend/dist/scripts static
cp ../../frontend/dist/index.html templates/layout/rating.jinja
@sidharthshah
sidharthshah / GameControllerSerial.ino
Created October 5, 2013 03:50
Simple sketch that allows to take input from four button and write data to serial, which is then read by Processing and displayed
int inPins[] = {2,3,4,5};
int totalInPins = 4;
const int DELAY_PERIOD = 70;
void setup() {
for(int i=0; i < totalInPins; i++){
pinMode(inPins[i], INPUT);
}
import processing.serial.*;
int serialData = 0;
Serial GamePad;
int x = 100;
int y = 70;
void setup() {
size(200, 200);