Skip to content

Instantly share code, notes, and snippets.

@firemiles
firemiles / context_keys_as_struct_not_int_or_string.md
Created September 6, 2022 06:36 — forked from ww9/context_keys_as_struct_not_int_or_string.md
Why use empty struct{} and not int or string for context.Value() key types in #go

Use struct{} as keys for context.Value() in Go

In the other file of this gist I detail why we should use struct{} as context.Value() keys and not int or string. Open gist to see main.go but the TLDR is:

	type key struct{}
	ctx = context.WithValue(ctx, key{}, "my value") // Set value
	myValue, ok := ctx.Value(key{}).(string) // Get value
# https://github.com/gpakosz/.tmux
# (‑●‑●)> dual licensed under the WTFPL v2 license and the MIT license,
# without any warranty.
# Copyright 2012— Gregory Pakosz (@gpakosz).
# -- navigation ----------------------------------------------------------------
# if you're running tmux within iTerm2
# - and tmux is 1.9 or 1.9a
@firemiles
firemiles / index.go
Last active December 11, 2019 05:22
kubernetes indexer update function
type Indexer interface {
Store
// Index returns the stored objects whose set of indexed values
// intersects the set of indexed values of the given object, for
// the named index
Index(indexName string, obj interface{}) ([]interface{}, error)
// IndexKeys returns the storage keys of the stored objects whose
// set of indexed values for the named index includes the given
// indexed value
IndexKeys(indexName, indexedValue string) ([]string, error)
@firemiles
firemiles / exec-in-docker-for-windows-vm.sh
Created January 20, 2019 06:43
exec in to mobylinuxvm
docker run --privileged -it -v /var/run/docker.sock:/var/run/docker.sock jongallant/ubuntu-docker-client
docker run --net=host --ipc=host --uts=host --pid=host -it --security-opt=seccomp=unconfined --privileged --rm -v /:/host alpine /bin/sh
chroot /host
@firemiles
firemiles / tmux-cheatsheet.markdown
Created February 14, 2018 14:59 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname

如何在路由器中实现透明代理?

0 互联网现状

目前整个互联网环境,被破坏最严重地部分,是 Web 服务体验。当直接破坏难以实现时,就会从流程链的上下游着手,如:DNS 污染。

其它地互联网服务类型,例如:邮件,可能小部分会受到 Web 服务上下游破坏地余震,但整体上基本不受影响。

@firemiles
firemiles / 0_reuse_code.js
Created May 31, 2016 11:51
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@firemiles
firemiles / gpio_mmap.c
Created May 31, 2016 11:46
通过 mmap 在用户层操作 gpio
#include <stdio.h>
#include <stdlib.h>
#include<sys/mman.h>
#include<fcntl.h>
#define GPIO_CTL_BASE 0x56000000
#define rGPBCON 0x10
#define rGPBDAT 0x14
#define rGPBUP 0x18
@firemiles
firemiles / glpk-mip-sample.c
Created March 29, 2016 04:24 — forked from msakai/glpk-mip-sample.c
Sample for solving MIP (mixed integer programming) problem with GLPK
#include <stdlib.h>
#include <stdio.h>
#include <glpk.h>
/*
Maximize
obj: x1 + 2 x2 + 3 x3 + x4
Subject To
c1: - x1 + x2 + x3 + 10 x4 <= 20
c2: x1 - 3 x2 + x3 <= 30
@firemiles
firemiles / virtual_break_private.cpp
Created March 4, 2016 07:12
virtual function can break permission in cpp class.
#include <iostream>
class A {
public:
virtual void fun() {
std::cout<<"A"<<std::endl;
}
};
class B:public A {