Skip to content

Instantly share code, notes, and snippets.

View sanfx's full-sized avatar
🎯
Focusing

Sanjeev Kumar sanfx

🎯
Focusing
  • London
  • 12:07 (UTC +01:00)
View GitHub Profile
from multiprocessing import Pool
def calculate(number):
return number
if __name__ == '__main__':
pool = Pool()
result = pool.map(calculate, range(4))
from concurrent.futures import ProcessPoolExecutor
def calculate(number):
return number
with ProcessPoolExecutor() as executor:
result = executor.map(calculate, range(4))
You can write the threaded example as:
import concurrent.futures
import itertools
import random
def generate_random(count):
return [random.random() for _ in range(count)]
if __name__ == "__main__":
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
@sanfx
sanfx / gist:3280d9c731e07f0b5614
Created January 9, 2015 11:57
Nuke NoOp node with expression to sample pixel and x, y coordinates
set cut_paste_input [stack 0]
version 8.0 v6
push $cut_paste_input
NoOp {
name NoOp2
selected true
xpos 824
ypos -172
addUserKnob {20 User}
addUserKnob {12 pixelCoordinate}
@sanfx
sanfx / SimpleVideo.py
Created March 22, 2015 16:16
Python Module for Kivy basic UI
from kivy.app import App
# kivy.require("1.8.0")
from kivy.uix.label import Label
class SimpleKivy(App):
def build(self):
return Label()
class Book(object):
def __init__(self,title, author):
self.title = title
self.author = author
print self.__dict__
def __iter__(self):
for each in self.__dict__.keys():
yield self.__getattribute__(each)
@sanfx
sanfx / logging.conf
Created May 1, 2015 04:04
Log to shell
[loggers]
keys=root
[handlers]
keys=consoleHandler
[formatters]
keys=simpleFormatter
[logger_root]
@sanfx
sanfx / logging.ini
Last active August 29, 2015 14:20
Log to shell and log to file with different formatters
#The "loggers" section contains the key names for all the loggers in this
#configuration. These are not the actual channel names, but values used to
#identify where the parameters for each logger are found in this file.
#The section for an individual logger is named "logger_xxx" where the "key"
#for a logger is "xxx". So ... "logger_root", "logger_appName", etc
#Logger key names can be any identifier, except "root" which is reserved for
#the root logger. (The names "lognn" are generated by the GUI configurator.)
[loggers]
keys=root, appName
@sanfx
sanfx / decoratorExample.py
Last active August 29, 2015 14:20
usage of a decorater to make a few attempts before failing on query in db
import time
def loop_query(fn, offset=0):
""" Decorator to make a few attempts before failing on query in db
Args:
func (function): Function holding the query
Kwargs:
offset(float): Offset to desynchronize the query
@sanfx
sanfx / class_object_as_list.py
Created May 6, 2015 12:31
How to set value of class object argument as if its a dict using __setItem__
import collections as _collections
Point = _collections.namedtuple("Point", ("x", "y", "z"))
# print help(_collections.namedtuple)
class PointLocation(object):
def __init__(self, x, y, z):
self._x = x
self._y = y