Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View h3xh4wk's full-sized avatar

Jitendra Singh h3xh4wk

  • Research & Technical Writing
  • New Delhi, India
View GitHub Profile
@h3xh4wk
h3xh4wk / with_example.py
Created January 19, 2019 12:36
Own object following the context manager protocol
import threading
some_lock = threading.lock()
with some_lock:
# Do something
@h3xh4wk
h3xh4wk / virtualenvwrapper
Created January 5, 2018 15:18
# config while working with git-sdk-Windows
$ cat ~/.bashrc
# config while working with git-sdk-Windows
export HOME=/home
export PATH=/usr/bin:$PATH
alias python=/usr/bin/python2
export WORKON_HOME="$HOME/.virtualenvs"
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python2
source /usr/bin/virtualenvwrapper.sh
# inline substitution based on condtion using regexp match processing all lines in a given file<filename>
# Note: Don't know why this wasn't working in git bash but worked when used Console2 + git bash
perl -pn -i'.bkup' -e 's/toreplace/replacewith/ if /regex/' filename
from suds.client import Client
from suds.sax.element import Element
url = "file:///home/jitendra/obs/wsdl.jsp.xml"
client = Client(url)
token = "xxxxxxxxxxxxxxxxxxxxxxxx"
print client
LoginResult = client.service.login("userId", "pwd"+token)
#Specifies the server URL as the target for subsequent service requests. The login server supports only login calls.
@h3xh4wk
h3xh4wk / filecount.py
Created June 17, 2013 13:47
Find the count of files in a directory ( only one level)
import os
filecount = 0
for d in os.listdir("."): # the current directory /
filecount += len(os.listdir("./"+d))
print filecount
@h3xh4wk
h3xh4wk / usecx_oracle.py
Created May 22, 2013 09:41
cx_Oracle with threads
import cx_Oracle
CONN_STR = """(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=%s)(PORT=%s))
(CONNECT_DATA=(SID=%s)))"""
CONN_STR = CONN_STR % (host, port, sid)
conn = cx_Oracle.connect(user, pwd, CONN_STR, threaded=True) # can connect using multi threads
conn.autocommit = True # will always use because could not figure out the place for explicit commit
"""
if not hasattr(self, "conn"):
self.conn = conn
@h3xh4wk
h3xh4wk / pylists.py
Last active June 4, 2016 21:04
python list comprehensions
# search elements of one list in another list without nested loops
tosearch = ['x','z',10]
tobesearched = ['x','y',1,2,3]
found = [item
for item in tosearch
for item2 in tobesearched if item == item2]
print found