Skip to content

Instantly share code, notes, and snippets.

View yen3's full-sized avatar

Yen3 yen3

  • Taiwan
View GitHub Profile
@yen3
yen3 / h99_p01_10.hs
Last active September 15, 2016 15:43
Practice for H-99: Ninety-Nine Haskell Problems( http://www.haskell.org/haskellwiki/H-99:_Ninety-Nine_Haskell_Problems )
-- Problem 1
myLast [] = error "empty list."
myLast [x] = x
myLast (x:xs) = myLast xs
-- Problem 2
myButLast x = head . drop 1 . reverse $ x
-- Problem 3
elementAt (x:xs) n =
@yen3
yen3 / zshrc.zsh
Created October 10, 2016 14:11
Try set zshrc with zplug
source ~/.zplug/init.zsh
zplug "zplug/zplug"
#zplug "zsh-users/zsh-history-substring-search"
#zplug "zsh-users/zsh-completions"
#zplug "zsh-users/zsh-syntax-highlighting"
# Prezto
zplug "modules/prompt", from:prezto
zstyle ':prezto:module:prompt' theme 'yen3'
@yen3
yen3 / build_ctags_cscope_gcc.sh
Last active November 11, 2016 03:32
A simple script to create ctags & cscope files for gcc 6.2.0
#!/usr/bin/env bash
find . -type f ! -path "*testsuite*" \
! -path "./.git/*" \
! -path "./gcc/testsuite/*" \
! -path "./INSTALL/*" \
! -path "./config/*" \
! -path "./libquadmath/*" \
! -path "./libssp/*" \
! -path "./libgo/*" \
! -path "./libtm/*" \
@yen3
yen3 / dump_call_graph.cpp
Last active November 11, 2016 14:09
GCC plugin: dump call graph for a single file.
#include "gcc-plugin.h"
#include "plugin-version.h"
#include "tree.h"
#include "cgraph.h"
#include <string>
#include <vector>
#include <map>
@yen3
yen3 / custom.css
Last active December 4, 2016 13:20
My gitit custom css. The original link is loss. If you know the original link, tell me. I will add the link in the page.
@import url("reset-fonts-grids.css");
@import url("hk-pyg.css"); /* for syntax highlighting */
html { background: #f9f9f9; color: black; }
body { margin: 10px; font-family: verdana; }
fieldset { border: 1px solid #ccc; padding: 1em; }
legend { font-weight: bold; margin-left: 1em; padding: 4px; }
h1, h2, h3, h4, h5, h6 { font-weight: bold; font-family: Georgia, serif; }
table, tr, td, th { border: none; }
hr { height: 1px; color: #aaa; background-color: #aaa; border: 0; margin: .2em 0 .2em 0; }
@yen3
yen3 / striter.py
Created March 9, 2018 09:31 — forked from anacrolix/striter.py
A Python IO class wrapping an iterable of strings.
import io
class StringIteratorIO(io.TextIOBase):
def __init__(self, iter):
self._iter = iter
self._left = ''
def readable(self):
return True
@yen3
yen3 / api_doc_gen.py
Last active April 22, 2018 08:55
tornado memo
# Credit: https://github.com/hfaran/Tornado-JSON/blob/master/tornado_json/api_doc_gen.py
import re
import inspect
import types
import itertools
import tornado.web
from tornado.web import RequestHandler
goldbach :: Int -> Maybe (Int, Int)
goldbach n = let ps = [(x, n-x) | x <- [2..(n `div` 2)], isPrime x, isPrime (n-x)]
in safeFst ps
where isPrime n = and (map (\x -> n `mod` x /= 0) [2..(n-1)])
safeFst [] = Nothing
safeFst (x:xs) = Just x
@yen3
yen3 / Dockerfile
Created August 5, 2018 09:01
Build Tapir LLVM for fun
FROM ubuntu:18.04
RUN sed -i 's/archive.ubuntu.com/tw.archive.ubuntu.com/g' /etc/apt/sources.list \
&& rm /etc/dpkg/dpkg.cfg.d/excludes \
&& apt update \
&& dpkg -l | grep ^ii | cut -d' ' -f3 | xargs apt install -y --reinstall \
&& apt install -y build-essential git man python cmake\
&& git clone --recursive https://github.com/wsmoses/Tapir-Meta.git \
&& cd /Tapir-Meta \
&& ./build.sh release \
@yen3
yen3 / epubs2t_opencc.py
Last active November 21, 2018 12:18
Convert epub content from simple chinese to traditional chinese using OpenCC (https://code.google.com/p/opencc/)
#!/usr/bin/env python
#-*- coding: utf8 -*-
from __future__ import print_function
from optparse import OptionParser
import zipfile
from sys import argv, exit
from subprocess import Popen, PIPE, check_output
import os.path