Skip to content

Instantly share code, notes, and snippets.

"""
Physics simulation with PyODE followed by a (basic) rendering with Vapory
See the result here: http://i.imgur.com/TdhxwGz.gifv
Zulko 2014
This script is placed in the Public Domain (Licence Creative Commons 0)
"""
from pycallgraph import PyCallGraph
from pycallgraph import Config
from pycallgraph import GlobbingFilter
from pycallgraph.output import GraphvizOutput
class ProfilerMiddleware(object):
includes = []
excludes = []
#!/usr/bin/env python
"""
A pure Python "ping" implementation, based on a rewrite by Johannes Meyer,
of a script originally by Matthew Dixon Cowles. Which in turn was derived
from "ping.c", distributed in Linux's netkit. The version this was forked
out of can be found here: https://gist.github.com/pklaus/856268
The versions this script derived from are licensed under GPL v2, this makes
mandatory that this is licensed under the same terms as well. If it were up
@alex-bender
alex-bender / ping.py
Last active August 29, 2015 14:20 — forked from pyos/ping.py
import time
import random
import select
import socket
def chk(data):
x = sum(a + b * 256 for a, b in zip(data[::2], data[1::2] + b'\x00')) & 0xFFFFFFFF
x = (x >> 16) + (x & 0xFFFF)
x = (x >> 16) + (x & 0xFFFF)
def hexdump(src, length=16, sep='.'):
"""
@brief Return {src} in hex dump.
@param[in] length {Int} Nb Bytes by row.
@param[in] sep {Char} For the text part, {sep} will be used for
non ASCII char.
@return {Str} The hexdump
"""
result = []
@alex-bender
alex-bender / prevent_syscall_test.py
Last active August 31, 2015 09:44 — forked from yoggy/prevent_syscall_test.py
prevent_syscall_test.py - python-ptrace sample program
#!/usr/bin/python
#
# prevent_syscall_test.py - python-ptrace sample program
#
# python-ptrace
# https://bitbucket.org/haypo/python-ptrace/wiki/Home
#
# Debian / Ubuntu
# $ sudo apt-get install python-ptrace
#
@alex-bender
alex-bender / gist:456d56024925424f22d2
Created November 4, 2015 08:15 — forked from mailletf/gist:3484932dd29d62b36092
Display a mel-scaled power spectrogram using librosa
# Mostly taken from: http://nbviewer.ipython.org/github/bmcfee/librosa/blob/master/examples/LibROSA%20demo.ipynb
import librosa
import matplotlib.pyplot as plt
# Load sound file
y, sr = librosa.load("filename.mp3")
# Let's make and display a mel-scaled power (energy-squared) spectrogram
S = librosa.feature.melspectrogram(y, sr=sr, n_mels=128)
@alex-bender
alex-bender / gist:2e7398f98a8a2b9d14b5
Created November 4, 2015 08:18 — forked from mailletf/gist:c49063d005dfc51a2df6
Simplified version of real-time audio scoring for goal detection
import pyaudio
import librosa
import numpy as np
import requests
# ring buffer will keep the last 2 seconds worth of audio
ringBuffer = RingBuffer(2 * 22050)
def callback(in_data, frame_count, time_info, flag):
audio_data = np.fromstring(in_data, dtype=np.float32)
@alex-bender
alex-bender / gist:fd65ae11a66c1388b93a0d3cd392a322
Created May 8, 2016 16:41 — forked from rygorous/gist:e0f055bfb74e3d5f0af20690759de5a7
A bit of background on compilers exploiting signed overflow
Why do compilers even bother with exploiting undefinedness signed overflow? And what are those
mysterious cases where it helps?
A lot of people (myself included) are against transforms that aggressively exploit undefined behavior, but
I think it's useful to know what compiler writers are accomplishing by this.
TL;DR: C doesn't work very well if int!=register width, but (for backwards compat) int is 32-bit on all
major 64-bit targets, and this causes quite hairy problems for code generation and optimization in some
fairly common cases. The signed overflow UB exploitation is an attempt to work around this.
@alex-bender
alex-bender / kvm
Created October 5, 2016 14:34 — forked from leberus/kvm
# aptitude install qemu-kvm libvirt-bin
# create a bridge with your current interface
auto eth1
iface eth1 inet manual
auto br0
iface br0 inet dhcp
bridge_ports eth1