Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
"""Show current wheather in Moscow, Russia in terminal and web browser.
http://weather.yandex.ru
http://stackoverflow.com/q/20308901
"""
import xml.etree.ElementTree as etree
from urllib.request import urlopen
# https://github.com/emacsmirror/yandex-weather/blob/master/yandex-weather.el
#!/usr/bin/env python3
"""Start command, sleep until specified local time, send input.
Bash analog:
$ rm -f pipe; mkfifo pipe
$ at TIMESPEC <<< 'echo -n INPUT >pipe'
$ COMMAND <pipe
Usage:
/** 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>
#!/usr/bin/env python
"""Retrieve json using t.w.c.getPage().
http://stackoverflow.com/questions/20460352/python-json-decoder-error
"""
import json
import sys
import urllib
from twisted.internet import reactor
from twisted.python.util import println
#!/usr/bin/env python
"""Print symlinks in the $PATH that point to `*.py` files."""
import os
seen = set()
for dirpath in os.environ.get('PATH', '').split(os.pathsep):
if not os.path.isdir(dirpath): # this follows symlinks
continue # visit only directories
# visit "each" directory only once
@zed
zed / getcert.py
Last active September 29, 2024 09:03
Show server's ssl certificate as json.
#!/usr/bin/env python3
"""Show server's certificate as json.
Usage:
$ %(prog)s HOST [PORT]
"""
import json
import socket
import ssl
import sys
@zed
zed / lcm.c
Last active December 31, 2015 09:59
/** Find least common multiple (LCM) of series of numbers.
It accepts input on stdin (one integer per line) and writes the
final result to stdout.
Result is always positive.
It uses gmplib (-lgmp) to support arbitrary precision integer arithmetic.
http://stackoverflow.com/questions/20581925/how-to-avoid-overflow-error-when-finding-lcm-for-series-of-large-integers
@zed
zed / Makefile
Last active December 31, 2015 11:49
Makefile template for a simple C project
NAME := $(patsubst %.c,%,$(wildcard *.c))
CC := gcc -std=c89
CFLAGS = -pedantic -Wall \
-Wno-missing-braces -Wextra -Wno-missing-field-initializers -Wformat=2 \
-Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith \
-Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Winline \
-Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code \
-Wlogical-op -Wfloat-equal -Wstrict-aliasing=2 -Wredundant-decls \
-Wold-style-definition -Werror \
-ggdb3 \
#!/usr/bin/env python2.6
"""Fill textarea.
http://stackoverflow.com/q/20621751
"""
import cgi
text = u'the text <that> you want & "to" put into textarea \u263a'
html_safe_text = cgi.escape(text, quote=True) # < > & " -> &lt; &gt; &amp; &quot;
textarea_html = u'<textarea placeholder="{0}"></textarea>'.format(
"""Show that a list argument can find multiple (different) tags."""
from bs4 import BeautifulSoup
soup = BeautifulSoup("""<!doctype html>
<title>Search multiple tags</title>
<i>i</i><b>b</b>""")
print(soup.find_all('i')) # only i
print('i'*60)
print(soup.find_all('b')) # only b
print('b'*60)