Skip to content

Instantly share code, notes, and snippets.

@zed
zed / ping.py
Created December 12, 2009 19:04
#!/usr/bin/env python
"""
A pure python ping implementation using raw socket.
Note that ICMP messages can only be sent from processes running as root.
Derived from ping.c distributed in Linux's netkit. That code is
/** Emulate `cmd1 | cmd2 | more` pipeline using recursion.
http://stackoverflow.com/questions/20434124/recursive-piping-in-unix-environment
*/
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@zed
zed / ytcallback-server.py
Last active April 7, 2024 21:26
Send telegrams about new videos on subscribed YouTube channels.
#!/usr/bin/env python3
"""Send telegrams about new videos on subscribed YouTube channels.
To try it, install dependencies:
$ python3 -mpip install aiohttp feedparser werkzeug
run the callback server:
$ env TELEBOT_TOKEN=<token> TELEBOT_CHAT_ID=<chat_id> python3 ytcallback-server.py
@zed
zed / .gitignore
Last active March 18, 2024 18:02
Receive udp messages and write summary info to file
/stats.json
@zed
zed / README.md
Last active March 18, 2024 06:27
Min-swap palindrome

To run application

./app.py

To make request to it

@zed
zed / cydot.pyx
Created March 16, 2012 18:25
Naive O(N**3) 2D np.dot() multithreaded implementation (CPython extension in Cython)
#cython: boundscheck=False, wraparound=False
import numpy as np
cimport numpy as np
from cython.parallel cimport prange
def dot(np.ndarray[np.float32_t, ndim=2] a not None,
np.ndarray[np.float32_t, ndim=2] b not None,
np.ndarray[np.float32_t, ndim=2] out=None):
"""Naive O(N**3) 2D np.dot() implementation."""
/** Pipeline between three processes.
http://stackoverflow.com/q/20056084/
See @chill's answer: http://stackoverflow.com/a/8092270
*/
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@zed
zed / .gitignore
Created January 17, 2011 16:08
What is faster x**.5 or math.sqrt(x) in Python?
.tox/
/MANIFEST
CFLAGS = -O2 -g \
-D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 \
-std=c99 -Wall -Wextra -pedantic \
-Wunused -Wimplicit -Wshadow -Wformat=2 \
-Wmissing-declarations -Wno-missing-prototypes -Wwrite-strings \
-Wbad-function-cast -Wnested-externs -Wcomment -Winline \
-Wchar-subscripts -Wcast-align \
-Wsequence-point \
LDFLAGS =
#!/usr/bin/env python
"""Translate text_to_translate using microsoft translator service."""
import json
import xml.etree.ElementTree as etree
try:
from urllib import urlencode
from urllib2 import urlopen, Request
except ImportError: # Python 3
from urllib.parse import urlencode
from urllib.request import urlopen, Request