Skip to content

Instantly share code, notes, and snippets.

@tomi77
tomi77 / bad.py
Created April 29, 2020 13:33
PyZMQ and "cannot switch to a different thread"
import zmq
from django.conf import settings
def send(func):
context = zmq.Context()
dealer = context.socket(zmq.DEALER)
dealer.connect(settings.ZMQ_ROUTER_URI)
@tomi77
tomi77 / evostreamms.service
Last active September 19, 2018 20:10
EvoStream Media Server SystemD service
[Unit]
Description=EvoStream Media Server
After=network.target
[Service]
Type=forking
ExecStart=/usr/bin/evostreamms --daemon --pid=/run/evostreamms/evostreamms.pid /etc/evostreamms/config.lua
PIDFile=/run/evostreamms/evostreamms.pid
User=evostreamd
Group=evostreamd
@tomi77
tomi77 / mp.py
Created December 30, 2014 13:57
from multiprocessing import Pool
def cube(x):
return x**3
if __name__ == '__main__':
pool = Pool(processes=4)
results = [pool.apply(cube, args=(x,)) for x in range(1, 7)]
def test(i):
i += 1
def test2(i):
i.append(1)
a = 0
b = []
print a
# coding=UTF-8
"""
“This is the “nester.py" module, and it provides one function called print_lol() which prints lists that may or
may not include nested lists.
"""
def print_lol(the_list):
""" This function takes a positional argument called “the_list",
which is any Python list (of, possibly, nested lists).
import netifaces as nif
def mac_for_ip(ip):
'Returns a list of MACs for interfaces that have given IP, returns None if not found'
for i in nif.interfaces():
addrs = nif.ifaddresses(i)
try:
if_mac = addrs[nif.AF_LINK][0]['addr']
if_ip = addrs[nif.AF_INET][0]['addr']
except IndexError, KeyError: #ignore ifaces that dont have MAC or IP
@tomi77
tomi77 / gcd.py
Created August 27, 2014 18:59
greatest common divisor of two positive integers
def GCD(a, b):
while True:
if a == 0:
return b
elif b == 0:
return a
else:
a, b = b, a % b
@tomi77
tomi77 / .inputrc
Created April 21, 2013 08:28
Allows you to search through bash history using the up and down arrows.
"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on
@tomi77
tomi77 / main.js
Created April 20, 2013 19:30
RequireJS "main config file" for Bootstrap
require.config({
paths: {
'bootstrap-affix': '../vendors/bootstrap/js/bootstrap-affix',
'bootstrap-alert': '../vendors/bootstrap/js/bootstrap-alert',
'bootstrap-button': '../vendors/bootstrap/js/bootstrap-button',
'bootstrap-carousel': '../vendors/bootstrap/js/bootstrap-carousel',
'bootstrap-collapse': '../vendors/bootstrap/js/bootstrap-collapse',
'bootstrap-dropdown': '../vendors/bootstrap/js/bootstrap-dropdown',
'bootstrap-modal': '../vendors/bootstrap/js/bootstrap-modal',
'bootstrap-popover': '../vendors/bootstrap/js/bootstrap-popover',
@tomi77
tomi77 / main.js
Last active December 16, 2015 11:28
RequireJS "main config file" for jQueryUI
require.config({
paths: {
'jquery.effect': '../vendors/jquery-ui/jquery.effect',
'jquery.effect-blind': '../vendors/jquery-ui/jquery.effect-blind',
'jquery.effect-bounce': '../vendors/jquery-ui/jquery.effect-bounce',
'jquery.effect-clip': '../vendors/jquery-ui/jquery.effect-clip',
'jquery.effect-drop': '../vendors/jquery-ui/jquery.effect-drop',
'jquery.effect-explode': '../vendors/jquery-ui/jquery.effect-explode',
'jquery.effect-fade': '../vendors/jquery-ui/jquery.effect-fade',
'jquery.effect-fold': '../vendors/jquery-ui/jquery.effect-fold',