Skip to content

Instantly share code, notes, and snippets.

@yzyzsun
yzyzsun / sum
Last active July 29, 2021 18:12
A polyglot summation challenge
The summation challenge, extended from the classical a-plus-b problem, is a
programming challenge for beginners. A programmer is asked to write a program to
read multiple integers separated by whitespace from a single line and then print
out their sum. Although not difficult, different solutions to this problem can
exhibit different characteristics of programming languages. Once I start to
learn a new language, I will add a new solution here.
@yzyzsun
yzyzsun / Y-combinator.hs
Last active November 8, 2021 06:27
Fixed-point combinators using iso-recursive types
newtype Rec a = Fold { unfold :: Rec a -> a }
fix :: (a -> a) -> a
fix f = (\x -> f (unfold x x)) (Fold (\x -> f (unfold x x)))
@yzyzsun
yzyzsun / http_server.c
Created November 27, 2018 10:08
Simple Web Server
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#define SERV_PORT 4746
#define BACKLOG 10
#define DATA_LEN 100000
# fino-time.zsh-theme
# Modified by yzyzsun on 2018-06-12
# Use with a dark background and 256-color terminal.
# Borrowing shamelessly from these oh-my-zsh themes:
# bira
# robbyrussell
#
# Also borrowing from http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/
@yzyzsun
yzyzsun / example.st
Created October 19, 2017 01:51
Smalltalk syntax on a postcard
exampleWithNumber: x
|y|
true & false not & (nil isNil) ifFalse: [self halt].
y := self size + super size.
#($a #a 'a' 1 1.0)
do: [:each | Transcript
show: (each class name);
show: (each printString);
show: ' '].
^ x < y
@yzyzsun
yzyzsun / shadowsocks-libev.sh
Last active August 16, 2023 05:38
shadowsocks-libev server setup script on CentOS 7
cd /etc/yum.repos.d
curl -O https://copr.fedorainfracloud.org/coprs/librehat/shadowsocks/repo/epel-7/librehat-shadowsocks-epel-7.repo
yum -y install shadowsocks-libev
setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/ss-server
cat > /etc/shadowsocks-libev/config.json << 'EOF'
{
"server": "0.0.0.0",
"server_port": 443,
"password": "p@$$w0rd",
"method": "aes-128-gcm"