Skip to content

Instantly share code, notes, and snippets.

View redraiment's full-sized avatar
🏠
Working from home

Zhang, Zepeng (redraiment) redraiment

🏠
Working from home
View GitHub Profile
@redraiment
redraiment / try-catch.c
Created August 4, 2014 05:32
Implement try-catch exception in C
#include <stdlib.h>
#include <stdio.h>
#include <setjmp.h>
jmp_buf __exception_context;
#define try if(!setjmp(__exception_context))
#define catch else
#define throw_exception longjmp(__exception_context, 1)
@redraiment
redraiment / gist:ec31dcb7b753f445a06c
Created September 4, 2014 10:13
layer.cornerRadius for left only
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_toggle.bounds
byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft)
cornerRadii:CGSizeMake(8.0, 8.0)];
CAShapeLayer *maskLayer = [CAShapeLayer new];
maskLayer.frame = _toggle.bounds;
maskLayer.path = maskPath.CGPath;
_toggle.layer.mask = maskLayer;
@redraiment
redraiment / .gitconfig
Created October 15, 2014 12:41
Store git https password
[user]
email = [email protected]
name = redraiment
[push]
default = simple
[credential]
helper = store
@redraiment
redraiment / DefaultKeyBinding.dict
Last active February 4, 2020 02:20
~/Library/KeyBindings/DeafultKeyBinding.dict 解决OSX Option 快捷键输出奇葩字符的问题
/*
* Ctrl(C): ^
* Option(M): ~
*/
{
"^/" = "undo:";
"^a" = "moveToBeginningOfLine:";
"^e" = "moveToEndOfLine:";
"^g" = "_cancelKey:";
"^t" = "transpose:";
@redraiment
redraiment / http.clj
Created January 17, 2016 07:10
简易的HTTP服务器,用于检测各种HTTP Client对KeepAlive的支持
(ns me.zzp.http
(:require [clojure.string :refer [blank?]])
(:import java.io.PrintStream
java.net.ServerSocket
java.util.Scanner
java.util.concurrent.atomic.AtomicLong)
(:gen-class))
(defonce generitor (AtomicLong.))
@redraiment
redraiment / pkg.sh
Created February 20, 2017 06:11
ArchLinux pacman 参数别名
#!/bin/bash
case $1 in
install|reinstall)
options=S
;;
remove)
options=Rc
;;
search)
@redraiment
redraiment / spoils.1.sql
Last active May 10, 2018 03:01
用SQL解海盗分金问题
create table spoils (
id int primary key,
amount int
);
comment on table spoils is '分赃表';
comment on column spoils.id is '海盗编号';
comment on column spoils.amount is '可获得的最高金额,null代表死亡';
create or replace function divide(amount_total int, pirate_count int)
returns setof spoils as $$
@redraiment
redraiment / web.py
Created May 29, 2018 06:15
提供简单的上传和下载功能的Python Web服务
#!/usr/bin/env python
import BaseHTTPServer
import cgi
import mimetypes
import os
import posixpath
import shutil
if not mimetypes.inited:
@redraiment
redraiment / Chart.py
Created August 7, 2019 18:23
基于Matplotlib的图表库简单封装,方便绘制直方图、圆饼图、折线图、散点图和箱形图。
#!/usr/bin/env python3
# -- 非线程安全 --
from matplotlib.font_manager import FontProperties
from operator import itemgetter
from itertools import groupby
import matplotlib.pyplot as canvas
import numpy as np
@redraiment
redraiment / check.sh
Created August 21, 2019 15:23
从重复到重用
#!/bin/sh
if [ $# -eq 0 ]; then
 echo "usage: $0 <c-source-file>" >&2
 exit -1
fi
input=$(cat <<EOF
William 35 25000
Kishore 41 35000
Wallace 37 30000
Bruce 39 29999