Skip to content

Instantly share code, notes, and snippets.

View calebmadrigal's full-sized avatar

Caleb Madrigal calebmadrigal

View GitHub Profile
@calebmadrigal
calebmadrigal / for_loop.py
Last active September 24, 2015 15:48
Python for loop vs list comprehension speed test. This is just testing the speed of performing a particular operation in both a for loop and list comprehension. Note that the list comprehension version uses more memory because it is storing the results. This could be partially responsible for it being slower.
import sys
num = int(sys.argv[1])
def test(i):
return i+1
for i in range(num):
t = test(i)
@calebmadrigal
calebmadrigal / evil_child.py
Last active September 1, 2015 05:54
evil_child() kills all parents and siblings, leaving only itself alive to do what it pleases (like cleaning things up)
import os
import signal
import time
from multiprocessing import Process
def kill_all(parent_pid):
os.killpg(os.getpgid(parent_pid), signal.SIGKILL)
def evil_child(parent_pid):
print("Killing my parents and siblings...")
@calebmadrigal
calebmadrigal / log_example.py
Created June 18, 2015 18:10
Basic python logging example
import logging
config = { 'logfile': 'log_example.log', 'loglevel': 'DEBUG' }
logger = logging.getLogger('log_example')
log_handler = logging.FileHandler(config['logfile'])
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
log_handler.setFormatter(formatter)
logger.addHandler(log_handler)
logger.setLevel(logging.getLevelName(config['loglevel']))
@calebmadrigal
calebmadrigal / keybase.md
Created April 23, 2015 02:53
Keybase proof

Keybase proof

I hereby claim:

  • I am calebmadrigal on github.
  • I am calebm (https://keybase.io/calebm) on keybase.
  • I have a public key whose fingerprint is F775 F481 BE72 409E 856C E93E B870 87DD 2D11 1E54

To claim this, I am signing this object:

@calebmadrigal
calebmadrigal / yolo.py
Created February 24, 2015 20:43
FIFO, LIFO, YOLO
import random
from collections import deque
print("#FIFO")
queue = deque()
for i in range(10):
queue.append(i)
print([queue.popleft() for _ in range(len(queue))])
print("#LIFO")