Skip to content

Instantly share code, notes, and snippets.

View knowshan's full-sized avatar

Shantanu Pavgi knowshan

  • San Francisco, CA
View GitHub Profile
@knowshan
knowshan / common_dict_items.py
Created February 13, 2016 07:07
Common items in simple dictionary structure
#!/usr/bin/env python
dict_1 = {'apple': 'red', 'banana': 'yellow', 'guava': 'green', 'orange': 'orange'}
dict_2 = {'apple': 'red', 'banana': 'yellow', 'grapes': 'green', 'orange': 'orange', 'guava': 'red',}
# Nested list comps to get keys of common dict items
ks = [i for i in [k for k in dict_1 if k in dict_2] if dict_1[i] == dict_2[i] ]
for k in ks:
print k, dict_1[k]
@knowshan
knowshan / palindrome.py
Last active February 12, 2016 01:34
Palindrome test using range or loop operators
#!/usr/bin/env python
words = ['madam', 'dalada', 'kayak', 'civic']
print 'Palindrome test using range, loop and array index'
for word in words:
word_r = "".join([word[i] for i in range(len(word)-1, -1, -1)])
if word == word_r:
print "%s is palindrome" %word
@knowshan
knowshan / puppet-pre-commit.sh
Created July 16, 2012 20:34
A Git pre-commit hook for Puppet to validate syntax and style
#!/bin/bash
# Description: A Git pre-commit hook for Puppet manifests
# Validates Puppet manifest syntax amd style
# * Syntax validation: Using puppet parser as documented on Puppet wiki
# - http://projects.puppetlabs.com/projects/1/wiki/Puppet_Version_Control
# * Style validation: Using puppet lint
# Requirements:
# * Ruby 1.8.7
@knowshan
knowshan / clear-network-config.sh
Created May 7, 2012 15:55
Kickstart files for generic CentOS 6 VM image for OpenNebula
#!/bin/bash
# Clear VM's network config
rm /etc/udev/rules.d/70-persistent-net.rules
rm /etc/sysconfig/network-scripts/ifcfg-eth0
rm /etc/resolv.conf
rm /etc/sysconfig/network