Skip to content

Instantly share code, notes, and snippets.

Jitendra Singh stupidnetizen

Block or report user

Report or block stupidnetizen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@stupidnetizen
stupidnetizen / with_example.py
Created Jan 19, 2019
Own object following the context manager protocol
View with_example.py
import threading
some_lock = threading.lock()
with some_lock:
# Do something
@stupidnetizen
stupidnetizen / virtualenvwrapper
Created Jan 5, 2018
# config while working with git-sdk-Windows
View virtualenvwrapper
$ 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
View oneliners.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
View SfApi.py
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.
@stupidnetizen
stupidnetizen / filecount.py
Created Jun 17, 2013
Find the count of files in a directory ( only one level)
View filecount.py
import os
filecount = 0
for d in os.listdir("."): # the current directory /
filecount += len(os.listdir("./"+d))
print filecount
@stupidnetizen
stupidnetizen / usecx_oracle.py
Created May 22, 2013
cx_Oracle with threads
View usecx_oracle.py
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
@stupidnetizen
stupidnetizen / pylists.py
Last active Jun 4, 2016
python list comprehensions
View pylists.py
# 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
You can’t perform that action at this time.