Skip to content

Instantly share code, notes, and snippets.

View bngsudheer's full-sized avatar

Sudheer Satyanarayana bngsudheer

View GitHub Profile
#!usr/bin/python
import urllib
from lxml import etree
import StringIO
url = "http://164.100.47.132/LssNew/Members/Alphabaticallist.aspx"
result = urllib.urlopen(url)
html = result.read()
@bngsudheer
bngsudheer / urllib_cookiejar_example.py
Created October 19, 2010 19:40
Cookiejar with urllib2 example
import urllib2
import urllib
from cookielib import CookieJar
cj = CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
values = {'username': 'admin', 'password': 'password'}
data = urllib.urlencode(values)
@bngsudheer
bngsudheer / gist:738910
Created December 13, 2010 11:27
that-anta-heli.py
#!/usr/bin/python
# Copyright Sudheer Satyanarayana, http://techchorus.net
# All rights reserved.
# That anta heli problem
# a, b, c, d and r are given as input
# Solve the problem
# a x b y c z d = r
# find x, y and z where x, y and z is either +, -, * or /
@bngsudheer
bngsudheer / greatest_common_divisor_euclids_algorithm.ph
Created December 15, 2010 17:16
Greatest common divisor using Euclid's algorithm
#!usr/bin/python
# Author - Sudheer Satyanarayana, http://techchorus.net
# Greatest common divisor using Euclid's algorithm
# Python 2.6 has Fractions module, see Fractions.gcd(a, b)
def gcd(m, n):
r = m % n
if r == 0:
return n
@bngsudheer
bngsudheer / that-anta-heli.c
Created December 25, 2010 12:32
That Anta Heli solution
#include <stdio.h>
#include <ctype.h>
/**
Author - Sudheer Satyanarayana, http://techchorus.net
All rights reserved
Solution for That Anta Heli problem
a, b, c, d and r are given as input
@bngsudheer
bngsudheer / postfix-bounce-count-per-domain.sh
Created January 21, 2011 11:19
Postfix bounce count for the day by domains
#!/bin/bash
domains="aol\.com yahoo\.com gmail\.com hotmail\.com"
datepart=`date "+%b %d"`
for domain in $domains
do
echo $domain
egrep "${datepart}.*${domain}.*bounced" /var/log/maillog | wc -l
done
@bngsudheer
bngsudheer / todays-editorial-text.py
Created June 24, 2011 13:05
Grab editorial news from Indian express
#!/usr/bin/python
import urllib
import lxml
from lxml import etree
import StringIO
parser = etree.HTMLParser()
todays_paper_url = "http://www.indianexpress.com/supplement/"
@bngsudheer
bngsudheer / smtp-example.py
Created June 25, 2011 07:59
Python SMTP Example
#!/usr/bin/evn python
from smtplib import SMTP
from email.MIMEText import MIMEText
try:
msg = MIMEText("body", "subject is this")
msg['Subject']= 'subject is this'
msg['From'] = 'sender@example.com'
conn = SMTP("mail.example.com")
@bngsudheer
bngsudheer / apache-data-transfer-day-report.awk
Created October 27, 2011 14:56
Show data transfer for a given day using Apache's access log file
#!/usr/bin/awk -f
# Usage is
# ./apache-data-transfer-day-report.awk -v date=20/Oct/2011 /path/to/access/log
# Typically, you have an access log file for a domain
# This has been tested only on CentOS 6.
# Fork or ask for a feature or bug fix.
#
BEGIN {
datepart = date
printf ("\nData transfer for the domain for %s:\n", datepart);
@bngsudheer
bngsudheer / des.py
Created January 28, 2013 08:58
Encrypt and decrypt using DES
# Encrpyt the string 'abcdefghijklmnop'
from Crypto.Cipher import DES
from Crypto import Random
iv = Random.get_random_bytes(8)
des1 = DES.new('issecret', DES.MODE_CFB, iv)
text = 'abcdefghijklmnop'
cipher_text = des1.encrypt(text)
print cipher_text