Skip to content

Instantly share code, notes, and snippets.

View xuzhenglun's full-sized avatar
🐠
**WASTED**

Reficul xuzhenglun

🐠
**WASTED**
View GitHub Profile
@snowcrumble
snowcrumble / Go 基于 Interface 的泛型.md
Created September 26, 2020 08:00
Go 基于 Interface 的泛型

Go 基于 Interface 的泛型

Go 泛型的草案截止今日已经基本定型了,与其他语言最大的不同应该就是 Go 的泛型利用 Interface 做 Constraint,可以说是与现有的 Interface 充分结合,之前的草案本来要引入新的关键字 contracts 在这次改动后被现有的 interface 代替,这使得 Interface 的概念更像 Rust 的 trait(实际上 Go 的泛型概念也与 Rust 相似),不过 Go 中实现 Interface 不需要显示声明,所以我想先谈一下 Interface 这个 Go 语言中最出色的“发明”。

Interface

Interface 实现了 Go 风格的 Duck typing。它实现的方法查表方式与其他语言有些不同,有方法的语言大概有两个阵营

  1. C++ 和 Java 在编译时生成方法的静态方法表,比如 C++ 的 vtable
  2. Js 和 Python 动态查询,并花式缓存
@aghosn
aghosn / kvm.go
Created March 18, 2020 16:43
a small hacky kvm example in go
package main
// #include <linux/kvm.h>
// #include <stdio.h>
// #include <err.h>
//
// static int myhandler(void* r) {
// struct kvm_run* run = (struct kvm_run*) r;
// switch (run->exit_reason) {
// case KVM_EXIT_HLT:
#!/bin/bash
# function Extract for common file formats
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
else
if [ -f "$1" ] ; then
NAME=${1%.*}
@fuyufjh
fuyufjh / cheatsheet.py
Last active February 19, 2024 00:36
My Python Cheatsheet
Python Cheatsheet
=================
################################ Input & Output ###############################
name = input('please enter your name: ')
print('hello,', name)
ageStr = input('please enter your age: ')
age = int(ageStr)
@mikroskeem
mikroskeem / Arch Linux btrfs install.md
Last active October 8, 2023 18:27 — forked from artizirk/Arch Linux btrfs install.md
Arch Linux installation on btrfs subvolumes

Arch Linux btrfs install

NOTE: Last update to this gist was on Jun 2, 2018. Most of the things here are out of date (e.g consider using zstd for transparent compression instead of lzo), so do your own research as well. Take care!

0. Prerequisites

  • Plenty of storage - snapshots will take (sort of) a lot of space
  • Latest Arch Linux install iso because those have newer kernels and more bugfixes in btrfs.
  • Have previous experience with installing Arch (like you can install arch with a blind fold).
  • Read everything through
@codeinthehole
codeinthehole / user-data.sh
Created August 18, 2014 12:41
Get the value of an EC2 instance's tag
#!/usr/bin/env bash
#
# Get the value of a tag for a running EC2 instance.
#
# This can be useful within bootstrapping scripts ("user-data").
#
# Note the EC3 instance needs to have an IAM role that lets it read tags. The policy
# JSON for this looks like:
#
# {
@kevin-smets
kevin-smets / iterm2-solarized.md
Last active May 23, 2024 09:28
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

@chrisjacob
chrisjacob / README.md
Created February 18, 2011 03:44
Setup GitHub Pages "gh-pages" branch and "master" branch as subfolders of a parent project folder ("grandmaster").

Intro

Description: Setup GitHub Pages "gh-pages" branch and "master" branch as subfolders of a parent project folder ("grandmaster").

Author: Chris Jacob @_chrisjacob

Tutorial (Gist): https://gist.github.com/833223

The Result