Skip to content

Instantly share code, notes, and snippets.

View sanfx's full-sized avatar
🎯
Focusing

Sanjeev Kumar sanfx

🎯
Focusing
  • London
  • 10:06 (UTC +01:00)
View GitHub Profile
@sanfx
sanfx / test_filterList.py
Created October 12, 2013 01:00
basic example of how mocking is done using mox.
import unittest
import filterList
import mox
class TestFilterList(unittest.TestCase):
""" docstring for TestFilterList
"""
def setUp(self):
self._filterby = 'B'
@sanfx
sanfx / mockNamespace.py
Last active May 10, 2016 09:59
mock argparse's Namespace behaviour.
class Namespace(object):
"""Mock for argparse's NameSpace
"""
def __init__(self, lst=None, flter=None):
super(Namespace, self).__init__()
self.filter = flter
self.lst = lst
def __repr__(self):
return 'Namespace(filter=self.filter, lst = self.lst)'
@sanfx
sanfx / slideShow.py
Created November 17, 2013 10:45
PyQt4 based slideShow , currently in evolving stage.
class SlideShowPics(QtGui.QWidget):
"""docstring for SlideShowPics"""
def __init__(self, path):
super(SlideShowPics, self).__init__()
QtGui.QWidget.__init__(self, None, QtCore.Qt.WindowStaysOnTopHint)
self._path = path
self.setStyleSheet("QWidget{background-color: #000000;}")
self.animFlag = True
from PyQt4 import QtCore,QtGui
import sys
class AnimatedWindow(QtGui.QWidget):
"""docstring for AnimatedWindow"""
def __init__(self, parent = None):
super(AnimatedWindow, self).__init__(parent)
animation = QtCore.QPropertyAnimation(self, "windowOpacity")
animation.setDuration(1000);
@sanfx
sanfx / dynamicControls.py
Created January 11, 2014 12:37
generate controls in a modal dialog prompt. The data is passed in the form of python dictionary.
import sys
from PyQt4 import QtCore, QtGui
class MessageBox(QtGui.QDialog):
"""docstring for MessageBox"""
def __init__(self, data=None, parent=None):
super(MessageBox, self).__init__(parent)
self._data = data
self.buildUi()
@sanfx
sanfx / colorDiff.py
Last active February 7, 2018 23:59
convert git diff to color HTML for embed to webpage or email using python
def getHtml(diffData):
""" This method convertes git diff data to html color code
"""
openTag = "<span style='font-size: .80em; color: "
openTagEnd = ";font-family: courier, arial, helvetica, sans-serif;'>"
nbsp = '&nbsp;&nbsp;&nbsp;&nbsp;'
return ''.join([("%s%s%s%s%s</span><br>" % (openTag, '#ff0000' if line.startswith('-') else ('#007900' if line.startswith('+') else '#000000'), openTagEnd, nbsp*line.count('\t') ,line)) for line in diffData])
#!/usr/bin/env python
# Copyright (C) 2006 by Johannes Zellner, <johannes@zellner.org>
# modified by mac@calmar.ws to fit my output needs
# modified by crncosta@carloscosta.org to fit my output needs
# Source: http://emerg3nc3.wordpress.com/2012/07/28/full-256-color-support-for-vim-andor-xterm-on-ubuntu-12-04/
import sys
import os
def echo(msg):
import nuke
import nukescripts
import re
class TriagePanel(nukescripts.PythonPanel):
def __init__(self):
nukescripts.PythonPanel.__init__(self, 'TriagePanel', 'com.ohufx.TriagePanel')
self.convergence = nuke.Double_Knob( 'convergence' )
self.convergence.setRange( -20, 20)
self.LogTolin = nuke.Boolean_Knob("LogTolin/enable specifed nodes","LogTolin")
week = ['Sun', 'Mon', 'Tue', 'Wed', 'Thurs', 'Fri']
print "If you break out of For else doesnt execute becuase its a part of for loop."
print "Enter something/ some single letter."
var = raw_input('>>')
msg = ''
for day in week:
print day
if day.endswith(var):
break
msg = "No day ends with %s" % var
@sanfx
sanfx / tryExceptElse_example.py
Created April 8, 2014 11:47
if ther is not exception then else block will execute, but if error occurs
value = None
try:
print "in try"
value = int(input())
print "No Error Occured"
except:
print "In Except: Value: %s" % value
else:
print "In else: Value %s" % value