Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <cassert>
#include <cmath>
using namespace std;
class BigInt
@qzchenwl
qzchenwl / minila2hhkb.xmodmap
Created December 21, 2015 02:45
xmodmap conf file to map minila to hhkb
!switch \| `~
keycode 0x31 = backslash bar backslash bar
keycode 0x33 = grave asciitilde grave asciitilde
!switch Super_L Alt_L
clear mod1
clear mod4
keycode 0x85 = Alt_L Meta_L Alt_L Meta_L
keycode 0x40 = Super_L NoSymbol Super_L
add mod1 = Alt_L Alt_R Meta_L
@qzchenwl
qzchenwl / Trigonometry Helper.markdown
Created November 25, 2015 02:56
Trigonometry Helper
@qzchenwl
qzchenwl / CEnum.hs
Last active November 6, 2015 10:54
Write C-style enum in Haskell
{-# LANGUAGE ViewPatterns #-}
module CEnum where
import Data.Maybe ( fromMaybe )
import Text.Read ( readMaybe )
import Text.Regex.PCRE
import Language.Haskell.TH
normalCons :: Con -> Name
@qzchenwl
qzchenwl / init-ubuntu-haskell.sh
Last active August 11, 2017 16:49
Install Haskell development environment.
#!/bin/bash
cat << EOF >> $HOME/.bashrc
export PATH="\$HOME/.local/bin:\$HOME/.cabal/bin:/opt/ghc/7.10.2/bin:/opt/cabal/head/bin:\$PATH"
alias tmux="tmux -2"
EOF
cat << EOF > $HOME/.gitconfig
@qzchenwl
qzchenwl / Pm.java
Created September 8, 2015 10:08
frameworks/base/cmds/pm/src/com/android/commands/pm
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@qzchenwl
qzchenwl / compressImage.html
Last active August 29, 2015 14:27
压缩图像示例
<input type="file" id="fileinput"/>
@qzchenwl
qzchenwl / l2tp.md
Last active October 22, 2016 13:29
在Ubuntu12.04上安装l2tp/ipsec VPN服务器

在Ubuntu12.04上安装l2tp/ipsec VPN服务器

因为众所周知的原因,l2tp也已沦陷,本文不再维护。

记录我在Ubuntu服务器上安装l2tp/ipsec VPN的过程,以供日后查询。ipsec用于验证和加密数据包,由openswan提供;l2tp即第二层隧道协议,由xl2tpd提供。

安装相关软件

默认配置即可,后面另有详细介绍。

module Main where
import Data.List
vertices = "ABCDEFGHIJK"
edges = ["ADB", "AEC", "AFHJ", "AGIK", "BJKC", "BHIE", "DFGE"]
combinations n = filter ((==n) . length) . subsequences
inSameEdge xs = or [ all (`elem` edge) xs | edge <- edges]
isTriangle (a:b:c:[]) = all inSameEdge [[a, b], [a, c], [b, c]] && not (inSameEdge [a, b, c])
triangles = filter isTriangle (combinations 3 vertices)
@qzchenwl
qzchenwl / filter-log.sh
Last active August 29, 2015 14:23
Filter HTTP request log by IP. Redirect log to file named with IP.
awk 'BEGIN{RS="\\+\\+\\+\\+\\+\\+\\+\\+\\+ Incoming Request \\+\\+\\+\\+\\+\\+\\+\\+\\+"; FS="\n"} { match($0, /X-Real-IP: ([0-9\.]+)/, ary); fn=ary[1]".txt"; print $0 >> fn }' debug.log
grep -l 'HTTP/1.1 412 Precondition Failed' *.txt | while read file; do mv $file 412; done