Skip to content

Instantly share code, notes, and snippets.

@Hexcles
Hexcles / up.sh
Created March 24, 2012 12:41
Setting up DNS according to OpenVPN dhcp-option (used with openvpn --up)
#!/bin/sh
# Setting up DNS according to OpenVPN dhcp-option
# used with openvpn --up
mv /etc/resolv.conf /etc/resolv.conf.old
for (( i=1; 1; i++))
do
optname="foreign_option_$i"
option=${!optname}
@Hexcles
Hexcles / down.sh
Created March 24, 2012 12:41
Restore original DNS settings (used with openvpn --down)
#!/bin/bash
# Restore original DNS settings
# used with openvpn --down
if [ -f /etc/resolv.conf.old ]
then
rm /etc/resolv.conf
mv /etc/resolv.conf.old /etc/resolv.conf
echo "resolv.conf restored"
fi
@Hexcles
Hexcles / sunpinyin_speedup.sh
Last active December 12, 2018 05:41
Sunpinyin Speedup
#!/bin/bash
#sunpinyin_speedup.sh
# Sunpinyin Speedup Script (by memory caching using shm, and no data loss)
# You can run this script in background on GNOME logging in.
# Hexcles Ma(http://robotshell.org/), Published in Public Domain
# Capture the exit signal, make sure it is the FIRST uncommented line.
trap "do_exit" SIGHUP SIGINT SIGQUIT SIGTERM
# Backup checking interval(seconds)
@Hexcles
Hexcles / vpn.sh
Last active October 9, 2021 05:06
ZJU VPN dial up script (xl2tpd + systemd, for Archlinux)
#!/bin/bash
PPP_TIMEOUT=15
L2TPD_TIMEOUT=5
L2TPD_CONTROL_FILE=/var/run/xl2tpd/l2tp-control
VPN_ACCOUNT=zjuvpn-a
function start_xl2tpd
{
systemctl start xl2tpd
@Hexcles
Hexcles / stylish-font-replacement.css
Last active January 2, 2022 03:35
Font substitute CSS for web pages
/*
* Replace ugly Chinese bitmap fonts with system default sans-serif.
* ATTENTION: this will intentionally change the appearance of web pages!
* Most Chinese websites do not mean to use serif fonts, especially for these ugly ones.
*/
@font-face {
font-family: "宋体";
src: local("sans-serif");
}
@Hexcles
Hexcles / vpn-dorm.sh
Created September 14, 2013 15:15
ZJU Zijingang Campus dormitory VPN dial up script (xl2tpd + systemd, for Archlinux)
#!/bin/bash
PPP_TIMEOUT=30
L2TPD_TIMEOUT=5
L2TPD_CONTROL_FILE=/var/run/xl2tpd/l2tp-control
VPN_ACCOUNT=zjuvpn
function start_xl2tpd
{
systemctl start xl2tpd
@Hexcles
Hexcles / url_base64.php
Last active August 29, 2015 13:56
URL安全的Base64编码(用'-'代替'+',用'_'代替'/',去掉末尾的padding),PHP实现
<?php
// public url_base64_encode(bin) {{{
/**
* url_base64_encode 生成URL安全的Base64编码
*
* @param string $bin
* @access public
* @return string
*/
@Hexcles
Hexcles / zjuwlan.sh
Created May 19, 2014 02:38
ZJUWLAN login script (curl, force HTTPS)
#!/bin/bash
# Abort when curl fails
set -e
USERNAME=
PASSWORD=
echo -n "Force logging off: "
curl 'https://net.zju.edu.cn/rad_online.php' -H 'Origin: https://net.zju.edu.cn' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: */*' -H 'Referer: https://net.zju.edu.cn/srun_port1.php?url=http://www.example.com/' --data "action=auto_dm&username=${USERNAME}&password=${PASSWORD}" >/dev/null 2>&1
echo "success!"
@Hexcles
Hexcles / urldecode.py
Last active August 29, 2015 14:10
Rename urlencoded (quoted) filenames
#!/usr/bin/env python3
from sys import argv
from os import path, system
from urllib.parse import unquote
if len(argv) == 1:
print("Usage: urldecode.py FILES...")
exit
@Hexcles
Hexcles / .ycm_extra_conf.py
Created May 7, 2015 22:15
YouCompleteMe extra conf for Linux kernel
# .ycm_extra_conf.py for kernel
import os
# Attention:
# File path not starting with / or = will be expanded.
flags_c = [
'-Wall',
'-Wundef',
'-Wstrict-prototypes',