Skip to content

Instantly share code, notes, and snippets.

@evanslai
evanslai / list.h
Last active April 12, 2023 12:07
C: Linux kernel linked list, modified for userspace
#ifndef _LINUX_LIST_H
#define _LINUX_LIST_H
#include <stdio.h>
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
/**
* container_of - cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.
@evanslai
evanslai / git-env-setup-01
Last active June 9, 2020 12:25
Git: First-time System Setup #git
# First-time system setup
git config --global user.name "Evans Lai"
git config --global user.email "evanslai@example.com"
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
git config --global color.log auto
git config --global alias.co checkout
git config --global core.editor "vim"
git config --global core.autocrlf false
@evanslai
evanslai / c-get_eth_mac.c
Last active October 21, 2020 06:08
C: How to get MAC address of your machine using a C program
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/if.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
int main()
{
struct ifreq s;
@evanslai
evanslai / gist:3737002
Last active October 10, 2015 19:08
Git 常用指令
# 列出遠端有哪些 branch
git branch -a
# If you want to check out a local working branch based on origin/test (checkout remote branch)
git checkout -b test origin/test
# Create branch $new_branch based on branch $other and switch to it
git checkout -b $new_branch $other
@evanslai
evanslai / git-merge-01
Created January 6, 2018 09:00
Git: Merge all changes from another branch as a single commit #git
git merge --squash <feature branch>
git commit
@evanslai
evanslai / git-log-01
Last active May 15, 2018 01:44
Git: show graphical commit history #git
git config --global alias.sb "log --graph --pretty=format:'%Cred%h%Creset %Cgreen(%cr) -%C(yellow)%d%Creset %s %C(bold blue)<%an>%Creset%n' --abbrev-commit --branches"
// Oneline
git log --pretty="%C(Yellow)%h %C(reset)%ad (%C(Green)%cr%C(reset))%x09 %C(Cyan)%an: %C(reset)%s" --date=short
@evanslai
evanslai / c-if_process_is_running.c
Last active November 9, 2022 00:09
C: Determine whether a process is running in C?
/*
https://stackoverflow.com/questions/11785936/how-to-find-if-a-process-is-running-in-c?
https://stackoverflow.com/questions/6898337/determine-programmatically-if-a-program-is-running
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>
@evanslai
evanslai / c-macro_FILE_short.c
Created January 23, 2018 01:18
C: Make the predefined MACRO __FILE__ become short path
#include <string.h>
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
@evanslai
evanslai / README.md
Last active January 29, 2018 13:23 — forked from Jxck/README.md
libuv TCP server/client sample #lib

how to compile

$ gcc -g -Wall -I /path/to/libuv/include /path/to/libuv/uv.a -framework CoreServices server.c -o server
$ gcc -g -Wall -I /path/to/libuv/include /path/to/libuv/uv.a -framework CoreServices client.c -o client
@evanslai
evanslai / .vimrc
Created November 27, 2018 10:33
vimrc
"https://github.com/amix/vimrc
set runtimepath+=~/.vim_runtime
source ~/.vim_runtime/vimrcs/basic.vim
source ~/.vim_runtime/vimrcs/filetypes.vim
source ~/.vim_runtime/vimrcs/plugins_config.vim
source ~/.vim_runtime/vimrcs/extended.vim
try
source ~/.vim_runtime/my_configs.vim