Skip to content

Instantly share code, notes, and snippets.

Xiao Hanyu xiaohanyu

Block or report user

Report or block xiaohanyu

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@xiaohanyu
xiaohanyu / data-weekly-technology-list.md
Last active May 11, 2019
Data-weekly technology section list
View data-weekly-technology-list.md

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

@xiaohanyu
xiaohanyu / udp_test.erl
Created Aug 13, 2017
UDP server and client for factorial function.
View udp_test.erl
%% 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 / socket_examples.erl
Created Aug 13, 2017
Socket programming examples in erlang.
View socket_examples.erl
%% 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 / binary_search_with_simple_unittest.py
Created Mar 7, 2017
Simple binary search with simple unit test in Python.
View binary_search_with_simple_unittest.py
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
@xiaohanyu
xiaohanyu / powerset-in-haskell-and-python.org
Created Mar 6, 2017
A demo powerset function implemented in Haskell and Python.
View powerset-in-haskell-and-python.org

Here’re two powerset function implemented in Python and Haskell.

import copy

def powerset(s):
    if s == []:
        return [[]]
    elif len(s) == 1:
        return [[], s]
@xiaohanyu
xiaohanyu / draw_array_stack_by_tikz.org
Last active Mar 5, 2017
Demo of drawing an array stack by LaTeX TikZ in Emacs Org-mode.
View draw_array_stack_by_tikz.org

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

@xiaohanyu
xiaohanyu / perm.hs
Created Mar 3, 2017
Haskell permutation generation algorithm with list comprehension.
View perm.hs
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 / org-mode-babel-demo-with-python-and-latex.org
Created Dec 9, 2016
Org-mode's org-babel, literate programming with python and latex.
View org-mode-babel-demo-with-python-and-latex.org
import matplotlib.pyplot as plt
import numpy as np

L = 6
x = np.linspace(0, L)
ncolors = len(plt.rcParams['axes.color_cycle'])
shift = np.linspace(0, L, ncolors, endpoint=False)
for s in shift:
    plt.plot(x, np.sin(x + s), 'o-')
@xiaohanyu
xiaohanyu / binary_search_demo.exs
Last active Oct 22, 2016
A binary search demo in Elixir(from "Programming Elixir" book, Chapter 6)
View binary_search_demo.exs
defmodule Chop do
def guess(final, range) do
low..high = range
middle = div(low + high, 2)
_guess_helper(final, low, high, middle)
end
defp _guess_helper(final, _low, _high, middle) when final === middle do
middle
end
View linux-libertine-webfont.css
@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');
You can’t perform that action at this time.