Skip to content

Instantly share code, notes, and snippets.

View sanfx's full-sized avatar
🎯
Focusing

Sanjeev Kumar sanfx

🎯
Focusing
  • London
  • 06:42 (UTC +01:00)
View GitHub Profile
#!/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
@sanfx
sanfx / fileDownloader.py
Created June 14, 2014 15:41
Download multiple files parallel with multiple threads for each download.
import urllib2
import os
import sys
import time
import threading
urls = ["http://broadcast.lds.org/churchmusic/MP3/1/2/nowords/271.mp3",
"http://s1.fans.ge/mp3/201109/08/John_Legend_So_High_Remix(fans_ge).mp3",
"http://megaboon.com/common/preview/track/786203.mp3"]
@sanfx
sanfx / daemon_non_daemon.py
Created June 16, 2014 04:32
A daemon thread is ended when it's parent thread has ended, a non-daemon thread will keep the parent thread alive until the non-daemon is finished.
import threading
import time
import logging
logging.basicConfig(level=logging.DEBUG,
format='(%(threadName)-10s) %(message)s',
)
def daemon():
logging.debug('Starting')
@sanfx
sanfx / emitSignal_1.py
Created July 4, 2014 17:31
This example shows how to emit signal from a function at module level , signal in turn is connected to SLOT in the class that can perform some action.
from PyQt4.QtCore import pyqtSignal, pyqtSlot
from PyQt4.QtGui import QWidget, QApplication
from PyQt4 import QtCore
import sys
_qObject = QtCore.QObject()
class SomeOtherClass(QWidget):
@sanfx
sanfx / emitSignal_2.py
Created July 4, 2014 17:35
How to emit signal from one class and connect it to SLOT in a different class.
from PyQt4.QtCore import pyqtSignal, pyqtSlot
from PyQt4.QtGui import QWidget, QApplication
import sys
class SomeClass(QWidget):
# Declare a new signal - passes Exception
has_error = pyqtSignal(Exception)
def __init__(self, parent=None):
super(SomeClass, self).__init__(parent)
"""
Find maximum memory consumed by a process specified at the command-line.
Usage:
$ python memory-usage-wait3.py cmd arg1 arg2
"""
import os
import sys
import threading
import threading
def f(arg):
global running
running += 1
print("Spawned a thread. running=%s, arg=%s" % (running, arg))
for i in range(100000):
pass
running -= 1
print("Done")