Skip to content

Instantly share code, notes, and snippets.

@lextoumbourou
lextoumbourou / word_wrap.py
Created April 25, 2012 04:34
My version of the 13 characters per line problem described here: http://blog.8thlight.com/uncle-bob/2012/04/20/Why-Is-Estimating-So-Hard.html (estimated 10 minutes, took me 30)
the_str = """Four score and seven years ago our fathers brought forth upon this \
continent a new nation, conceived in liberty and dedicated to the \
proposition that all men are created equal..."""
def word_wrap(the_str, chars_per_line):
'''
Returns formatted string based on number of characters per line
'''
iterator,space_pos,line_count = 0,0,0
output = the_str
lex@server:~> python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.get_version()
'1.4'
@lextoumbourou
lextoumbourou / parallel-tcpdump.yml
Last active December 29, 2015 03:59
parallel-tcpdump.yml
- hosts: all
sudo: yes
vars:
cap_file: packet_capture_{{ ansible_hostname }}_{{ ansible_date_time['epoch'] }}.cap
tasks:
- name: start tcpdump
command: /usr/sbin/tcpdump -i eth0 -s 0 -w /tmp/${cap_file}
async: 60
poll: 0
from os import fork
from time import sleep
# Fork the process
pid = fork()
if pid == 0: # We're in the child process
print "Child process up in this."
else: # We're in the parent process
print "Parent here, I just created child", pid
@lextoumbourou
lextoumbourou / stdout-fork
Created November 24, 2013 00:49
fork.py terminal output
> python fork.py
Parent here, I just created child 19478
Child process up in this.
from os import fork, getppid
from time import sleep
pid = fork()
if pid == 0: # We're in the child process
print "Child process up in this."
print "My parent is", getppid()
else:
print "Parent here, I just created child", pid
> python fork_ppid.py
Parent here, I just created child 19741
Child process up in this.
My parent is 19740
from os import fork, getppid
from time import sleep
pid = fork()
if pid == 0:
print "I'm about to become an orphan!"
for _ in range(3):
sleep(1)
print "My parent is", getppid()
> python fork_orphan.py
Parent here, I just created child 19683
Child process up in this.
Right now, my parent is 19682
> Right now, my parent is 1
Right now, my parent is 1
from os import fork, getppid, wait
from sys import exit
from time import sleep
pid = fork()
if pid == 0:
print "Hope my parent doesn't forget me this time!"
for _ in range(3):
sleep(1)