Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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
;;
*)
#include <iostream>
template<class T>
class Out
{
private:
T& mValue;
public:
explicit Out(T& aValue)
@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
@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;
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)
#include <iostream>
#include <stddef.h>
namespace mozilla {
template<typename Iterator>
struct IteratorTraits
{
typedef typename Iterator::ValueType ValueType;
@upsuper
upsuper / gae_proxies
Created November 16, 2011 13:57
nginx GAE反向代理配置
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_pass http://ghs.google.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}