Skip to content

Instantly share code, notes, and snippets.

View fuweid's full-sized avatar
🎯
Focusing

Fu Wei fuweid

🎯
Focusing
View GitHub Profile
#! /bin/bash
set -euo pipefail
CODE=$(cat <<EOF
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define BUFFER_SIZE BUFFER_SIZE_T
@fuweid
fuweid / sh.c
Created September 20, 2016 03:06
Simplifed xv6 shell
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
@fuweid
fuweid / atom.c
Last active September 25, 2016 12:39
struct atom_t
#include "atom.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include <string.h>
#include <limits.h>
#define NELEMS(x) ((sizeof(x) / sizeof((x)[0])))
@fuweid
fuweid / mem.c
Last active September 27, 2016 06:15
Memory Management in C (Still no test cases for this)
#include "mem.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define NELEMS(arr) ((sizeof(arr) / sizeof((arr)[0])))
#define NDESCRIPTORS 512
@fuweid
fuweid / whatever.sh
Last active September 28, 2016 07:29
Filter Git Branch
git branch --list \
| cut -c 3- \
| sed 's/\(dev\)//g' \
| xargs -n 1
@fuweid
fuweid / Makefile
Created June 1, 2017 07:00 — forked from isaacs/Makefile
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@fuweid
fuweid / TrueColour.md
Created June 22, 2017 15:58 — forked from XVilka/TrueColour.md
True Colour (16 million colours) support in various terminal applications and terminals

Colours in terminal

It's a common confusion about terminal colours... Actually we have this:

  • plain ascii
  • ansi escape codes (16 colour codes with bold/italic and background)
  • 256 colour palette (216 colours + 16 ansi + 24 gray) (colors are 24bit)
  • 24bit true colour ("888" colours (aka 16 milion))
printf "\x1b[${bg};2;${red};${green};${blue}m\n"
@fuweid
fuweid / http_streaming.md
Created August 15, 2017 12:04 — forked from CMCDragonkai/http_streaming.md
HTTP Streaming (or Chunked vs Store & Forward)

HTTP Streaming (or Chunked vs Store & Forward)

The standard way of understanding the HTTP protocol is via the request reply pattern. Each HTTP transaction consists of a finitely bounded HTTP request and a finitely bounded HTTP response.

However it's also possible for both parts of an HTTP 1.1 transaction to stream their possibly infinitely bounded data. The advantages is that the sender can send data that is beyond the sender's memory limit, and the receiver can act on

@fuweid
fuweid / nginx-location
Last active November 14, 2017 05:06 — forked from luxixing/nginx-location
nginx location 匹配规则
https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms
1 普通匹配,遵循最长匹配规则,假设一个请求匹配到了两个普通规则,则选择匹配长度大的那个
例如:
location /{
[matches]
}
location /test{
[matches]
}
@fuweid
fuweid / clean-git-branch
Created December 1, 2017 10:33 — forked from VeryCB/clean-git-branch
This script helps removing Git branches. Run it from a git repo dir. It will open the Git branches list in your favorite editor. Delete some branches from the list. Save and close the file. The script applies the changes to the repo.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This script helps removing Git branches.
# Run it from a git repo dir. It will open the Git branches list
# in your favorite editor. Delete some branches from the list.
# Save and close the file. The script applies the changes to the repo.
from subprocess import call, Popen, PIPE
from os import getenv