Skip to content

Instantly share code, notes, and snippets.

@upsuper
upsuper / myext.py
Last active January 14, 2016 00:12
Mercurial extension for my local Mozilla repo
# - * - coding: UTF-8 - * -
import re
import os
import os.path
import marshal
from mercurial import cmdutil, patch, revset
from mercurial.error import ParseError
from mercurial.node import bin, hex
r=lambda s:s.replace("\\","\\\\").replace("\"","\\\"");a,b="r=lambda s:s.replace(\"\\\\\",\"\\\\\\\\\").replace(\"\\\"\",\"\\\\\\\"\");a,b=\"","\";print(a+r(a)+\"\\\",\\\"\"+r(b)+b)";print(a+r(a)+"\",\""+r(b)+b)
@upsuper
upsuper / tone-mark-positioning.html
Last active August 29, 2015 14:14
Tone mark positioning polyfill
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<title>Polyfill demo for tone mark positioning</title>
<style>
body {
-webkit-writing-mode: vertical-rl;
-ms-writing-mode: tb-rl;
writing-mode: vertical-rl;
@upsuper
upsuper / maketiles.py
Created December 25, 2014 03:36
Customize Firefox Tiles
#!/usr/bin/env python3
import sys as _sys
import json as _json
import base64 as _base64
import logging as _logging
import mimetypes as _mimetypes
import urllib.parse as _url
import configparser as _configparser
#include <iostream>
template<class T>
class Out
{
private:
T& mValue;
public:
explicit Out(T& aValue)
@upsuper
upsuper / gist:6f67f933fa583d3750ae
Created November 25, 2014 22:49
Clear left .orig & .rej in hg repo
#!/bin/sh
files=$(hg status | awk '$1 == "?" && $2 ~ /\.(orig|rej)$/ { print $2 }')
echo "$files"
read -r -p "Remove these files? [y/N]" resp
case $resp in
[yY][eE][sS]|[yY])
rm $files
;;
*)
@upsuper
upsuper / check_patch.py
Last active August 29, 2015 14:07
Check difference between local patches and submitted ones
#!/usr/bin/env python3
# - * - coding: UTF-8 - * -
import sys
import json
import concurrent.futures as futures
from pathlib import Path
from difflib import Differ
from urllib.request import urlopen
@upsuper
upsuper / convert.c
Last active May 29, 2018 15:34
解包暖暖环游世界中 picData_rw.db 文件的工具代码
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
if (argc < 3) {
printf("usage: %s inputfile outputfile\n", argv[0]);
exit(2);
}
@upsuper
upsuper / wait4pid.c
Created April 19, 2014 11:47
Wait for another process
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/ptrace.h>
const char *name;
void usage()
@upsuper
upsuper / client.rb
Created April 12, 2014 13:27
Secure password - Implementation of a challenge-style password checking flow based on ECDSA. By this method, server will never know the password while it is still able to verify.
#!/usr/bin/env ruby
require "socket"
require "OpenSSL"
Group = OpenSSL::PKey::EC::Group.new("secp160k1")
def send(server, data)
puts ">>> #{data}"
server.puts data