Skip to content

Instantly share code, notes, and snippets.

@zeroxia
zeroxia / permutate_expr_sum.py
Last active May 24, 2016 13:17
For a list of numbers 1 2 3 4 5 6 7 8 9, add operators '+', '-', or none among them, to create an albegraic expression that evaluates to sum of 110.
#!/usr/bin/python
# vim: set ts=4 sts=4 et fileencoding=utf-8:
import itertools
target = 110
ops = [' + ', ' - ', '']
digit_list = list('123456789')
for op_list in itertools.product(ops, repeat=8):
expr = ''.join([ item for pair in zip(digit_list, op_list + ('',)) for item in pair ])
try:
@zeroxia
zeroxia / dl.py
Created May 14, 2016 14:21
Python 2.7.6 (on Ubuntu 14.04) does not support SSL verfication using urllib2, while with later python 2.7.x, ssl certificate verification is enabled by default. Here is some snippets on properly tackling these caveats.
#!/usr/bin/python
import socket
import httplib
import ssl
import urllib
import urllib2
# archaic python urllib2 documentation: 2.7.2
# https://python.readthedocs.io/en/v2.7.2/library/urllib2.html
@zeroxia
zeroxia / find_equal_len.py
Last active May 12, 2016 12:57
Find lines with equal "left" and "right" parts that are separated by the Chinese comma ","
#!/usr/bin/python3
# vim: set ts=4 et:
import re
p = re.compile("^(.*),(.*)。$")
with open("input.txt") as f:
for lno, line in enumerate(f):
mo = p.match(line.rstrip())
@zeroxia
zeroxia / pic16_io2uart.c
Created July 3, 2015 05:16
Using GPIO pin to emulate "TX" function of UART communication (TTL levels)
#include <xc.h>
/* Microcontroller MIPs (FCY) */
#define SYS_FREQ 4000000L
#define _XTAL_FREQ SYS_FREQ
/* #define FCY SYS_FREQ/4 */
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
@zeroxia
zeroxia / outlook_2013_dismiss_due_reminders.vbs
Created June 25, 2015 12:54
Dismiss annoying Outlook 2013 due reminders, but still buggy, who can improve it? Thanks!
' Declare this Wbject withEvents displaying all the events
Private WithEvents olRemind As Outlook.Reminders
Private Sub Application_Startup()
' Set olRemind = Outlook.Reminders
' KillOverdueReminders
End Sub
Private Sub KillOverdueReminders(Cancel As Boolean)
' Purpose: Kills all reminders for past due appointments.'
@zeroxia
zeroxia / etc_init.d_rcS
Created May 12, 2015 13:02
rcS file and my tweaking files for PogoPlug Series 4 box. The "rcS2" scripts aim to start the Samba service installed as optware on the mmcblkp0 device (the SD card slot).
#-*- 1. /etc/init.d/rcS changes -*-
#! /bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devpts none /dev/pts
mount -t tmpfs none /tmp
mkdir /tmp/var
@zeroxia
zeroxia / install-rar-as-alternatives.sh
Created May 7, 2015 13:11
To install various links for rarlinux commands and related files.
#!/bin/sh
update-alternatives --install /usr/local/bin/rar rar /opt/rar/rar_static 50 \
--slave /etc/rarreg.key rarreg.key /opt/rar/rarreg.key \
--slave /etc/rarfiles.lst rarfiles.lst /opt/rar/rarfiles.lst \
--slave /usr/local/lib/default.sfx default.sfx /opt/rar/default.sfx \
--slave /usr/local/share/man/man1/rar.1.gz rar.1.gz /opt/rar/rar.1.gz \
--slave /usr/local/bin/unrar unrar /opt/rar/unrar \
--slave /usr/local/share/man/man1/unrar.1.gz unrar.1.gz /opt/rar/unrar.1.gz
@zeroxia
zeroxia / modtracker.sh
Created May 7, 2015 12:13
Modify tracker URL of transmission tasks.
#!/bin/sh
## TODO: Fill the following placeholders:
## USERNAME, PASSWORD
## YOUR_PASSKEY
trr() {
transmission-remote 127.0.0.1:9091 -n USERNAME:PASSWORD "$@"
}
@zeroxia
zeroxia / run-dl.sh
Created March 8, 2015 08:28
xunlei-lixian batch invocation shell script
#!/bin/sh
LOG_FILE=./log.txt
if [ -z "$1" ]; then
echo "Usage: $0 LIST [LOG]"
exit 0
fi
if [ -n "$2" ]; then
@zeroxia
zeroxia / nmap-scan.sh
Created March 19, 2014 08:18
nmap command to scan the network
#!/bin/sh
#IFACE=eth1
# # LAN host discovery
# seq 0 255 | while read subnet; do
# echo subnet: 192.168.$subnet.0
# ##sudo ifconfig $IFACE 192.168.$subnet.100
# ##sudo nmap -n -sP -PA 192.168.$subnet.-99,101-
# done