Skip to content

Instantly share code, notes, and snippets.

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

Xiao Hanyu xiaohanyu

🏠
Working from home
View GitHub Profile
@font-face {
font-family: 'Linux Libertine'; /* normal */
src: url('/static/fonts/linux-libertine/LinLibertine_R.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'Linux Libertine'; /* italic */
src: url('/static/fonts/linux-libertine/LinLibertine_RI.woff') format('woff');
@xiaohanyu
xiaohanyu / draw_array_stack_by_tikz.org
Last active May 3, 2023 11:33
Demo of drawing an array stack by LaTeX TikZ in Emacs Org-mode.

This is a demo solution for exercise 10.1-1 of the famous CLRS’s Introduction to Algorithms, 3rd Edition book.

@xiaohanyu
xiaohanyu / socket_examples.erl
Created August 13, 2017 11:30
Socket programming examples in erlang.
%% socket examples from Joe Armstrong's "Programming Erlang, Second Edition".
-module(socket_examples).
-compile(export_all).
-import(lists, [reverse/1]).
string2value(Str) ->
{ok, Tokens, _} = erl_scan:string(Str ++ "."),
{ok, Exprs} = erl_parse:parse_exprs(Tokens),
Bindings = erl_eval:new_bindings(),
{value, Value, _} = erl_eval:exprs(Exprs, Bindings),
@xiaohanyu
xiaohanyu / perm.hs
Created March 3, 2017 16:14
Haskell permutation generation algorithm with list comprehension.
import Data.List
perm :: (Eq a) => [a] -> Int -> [[a]]
perm _ 0 = [[]]
perm xs r | length xs < r = [[]]
| otherwise = [x:ys | x <- xs, ys <- perm (delete x xs) (r - 1)]
@xiaohanyu
xiaohanyu / data-weekly-technology-list.md
Last active May 11, 2019 06:38
Data-weekly technology section list

This gist and its comments contains some topics for technology section of data weekly

@xiaohanyu
xiaohanyu / nanoc_pandoc.rb
Created March 30, 2014 02:37
Improved nanoc pandoc filter
# This file provide two pandoc filters for html and pdf output
module Nanoc::Filters
class PandocHtml < Nanoc::Filter
identifier :pandoc_html
type :text => :text
def run(content, params = {})
input_format = case item[:extension]
@xiaohanyu
xiaohanyu / udp_test.erl
Created August 13, 2017 11:48
UDP server and client for factorial function.
%% udp test client and server, from joe armstrong's "programming erlang, second
%% edition"
-module(udp_test).
-export([start_server/0, client/1]).
start_server() ->
spawn(fun() -> server(4000) end).
%% the server
server(port) ->
@xiaohanyu
xiaohanyu / yaml_to_json.rb
Created September 1, 2014 06:29
convert yaml to json in ruby
require 'json'
require 'yaml'
input_filename = ARGV[0]
output_filename = input_filename.sub(/(yml|yaml)$/, 'json')
input_file = File.open(input_filename, 'r')
input_yml = input_file.read
input_file.close
@xiaohanyu
xiaohanyu / knight.org
Last active April 12, 2017 10:22
Knight problem

Problem

There’s a chess board of size $N × N$, and an piece Knight, which has the initial position $(x, y)$.

Knight can step by going forward or backward two units in one direction, and one units in the other direction.

Find a way to position $(N, N)$ for this Knight piece.

@xiaohanyu
xiaohanyu / binary_search_with_simple_unittest.py
Created March 7, 2017 16:30
Simple binary search with simple unit test in Python.
import unittest
def binary_search(array, t):
l = 0
h = len(array) - 1
while (l <= h):
m = (l + h) // 2
if (array[m] == t):
return m