Skip to content

Instantly share code, notes, and snippets.

View guihao-liang's full-sized avatar
🍎
C++/Go/Python/Rust

Guihao Liang guihao-liang

🍎
C++/Go/Python/Rust
View GitHub Profile
package main
import "fmt"
//
// https://commandcenter.blogspot.com/2014/01/self-referential-functions-and-design.html
//
// self-referential definition
// recursive definition
// it's like linked list
@guihao-liang
guihao-liang / singleton.py
Created June 25, 2020 17:03
pythonic design patterns
class Example(object):
"""A singleton not thread safe
"""
_instance = None
@classmethod
def instance(cls):
if cls._instance is None:
cls._instance = cls.__new__(cls)
@guihao-liang
guihao-liang / hello_with_c.asm
Last active May 25, 2020 18:33
asm examples for for mach-o; referenced from https://cs.lmu.edu/~ray/notes/nasmtutorial/
; ----------------------------------------------------------------------------------------
;
; In macOS land, C functions (or any function that is exported from one module to another, really)
; must be prefixed with underscores.
;
; The call stack must be aligned on a 16-byte boundary.
;
; And when accessing named variables, a `rel` prefix is required.
;
; nasm -fmacho64 hello_with_c.asm && cc hello_with_c.o && ./a.out