Skip to content

Instantly share code, notes, and snippets.

View vishalsodani's full-sized avatar
🏠
Working from home

Vishal Sodani vishalsodani

🏠
Working from home
View GitHub Profile
@vishalsodani
vishalsodani / Odesk_skills_to_csv
Created February 11, 2014 12:29
Get json data of odesk skills and write list to CSV file
import requests
import csv
odesk_output = requests.get('https://www.odesk.com/api/profiles/v1/metadata/skills.json')
skills = odesk_output.json()['skills']
csvfile = 'odesk_skills.csv'
with open(csvfile, "w")as output:
writer = csv.writer(output, lineterminator='\n')
for skill in skills:
@vishalsodani
vishalsodani / counter_datastructure
Created May 5, 2013 13:38
Count frequency of items in a list
from collections import Counter
cnt = Counter()
some_data = ['a','b','v','c','l','c']
for item in some_data:
cnt[item] += 1
print cnt
@vishalsodani
vishalsodani / freq_dict
Last active December 17, 2015 00:28
Count frequency of items using dictionary
frequency_count = dict()
some_data = ['a','b','v','c','l','c']
for item in some_data:
if item in frequency_count:
frequency_count[item] += 1
else:
frequency_count[item] = 1
print frequency_count
@vishalsodani
vishalsodani / freq_defaultdict
Last active December 17, 2015 00:28
Count frequency of items in a list using defaultdict
from collections import defaultdict
some_data = ['a','b','v','c','l','c']
frequency_count = defaultdict(int)
for item in some_data:
frequency_count[item] += 1
print frequency_count
@vishalsodani
vishalsodani / gist:5567806
Created May 13, 2013 11:56
More elegant use of counter
from collections import Counter
some_data = ['a','b','v','c','l','c']
result = Counter(some_data)
@vishalsodani
vishalsodani / Bitstarter_AWS
Last active December 19, 2015 13:39
Simple setup of node project using Nginx on AWS
* First allot an Elastic IP. This option is available under Network and Security
* Right click the IP shown and associate the IP with the ubuntu instance.
* Add a security rule for http with port 80.
* Install Nginx
* Test Nginx sudo /etc/init.d/nginx start
** Go to web browser and type your elastic ip assigned. You should see 'Welcome to Nginx"
* Then go to /etc/nginx/sites-available and setup your default. Add the following lines
server {
@vishalsodani
vishalsodani / gist:6593153
Created September 17, 2013 11:34
Make an empty formset required
from django.forms.formsets import BaseFormSet
class RequiredFormSet(BaseFormSet):
def __init__(self, *args, **kwargs):
super(RequiredFormSet, self).__init__(*args, **kwargs)
for form in self.forms:
form.empty_permitted = False
@vishalsodani
vishalsodani / date_py_mongo
Last active December 25, 2015 01:29
Handling date in Python for Mongodb
from datetime import datetime, time
# getting date from form
dt = datetime.strptime(request.form['date'], '%Y-%m-%d')
# adding date for a record
record = {}
# need to add time (0,0)
record['date'] = datetime.combine(dt, time())
@vishalsodani
vishalsodani / dog.rs
Last active May 20, 2016 04:36
Daily programmer May 16th Easy => 2nd Version in Rust
fn print_non_wining_places(won_place: i32) {
let mut display = String::new() ;
let mut string_number ;
for x in 0..200 {
if x != won_place && x != 0 {
string_number = x.to_string() ;
let mut copy_string_number = x.to_string() ;