Skip to content

Instantly share code, notes, and snippets.

View futurist's full-sized avatar

James Yang futurist

  • China
View GitHub Profile
@miguelmota
miguelmota / main.go
Created December 29, 2018 01:14
Golang file descriptor opening and closing example
package main
import (
"fmt"
"log"
"os"
"syscall"
)
func main() {
@codesections
codesections / actix-web.rs
Created December 20, 2018 22:03
Basic static file server with actix-web
extern crate actix_web;
use actix_web::{fs, server, App};
fn main() {
server::new(|| {
App::new()
.handler(
"/",
fs::StaticFiles::new("./public")
.unwrap()
@codesections
codesections / server.rs
Last active March 20, 2022 04:35
Naive static file server in rust
use std::io::prelude::*;
use std::net::TcpListener;
use std::net::TcpStream;
mod app;
fn main() {
let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
for stream in listener.incoming() {
let stream = stream.unwrap();
handle_connection(stream);
@fnky
fnky / ANSI.md
Last active May 11, 2025 04:58
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@paolocarrasco
paolocarrasco / README.md
Last active April 7, 2025 22:13
How to understand the `gpg failed to sign the data` problem in git

Problem

You have installed GPG, then tried to commit and suddenly you see this error message after it:

error: gpg failed to sign the data
fatal: failed to write commit object

Debug

//CommandTimeoutWithContext command timeout with background context
func CommandTimeoutWithContext(command string, timeout time.Duration) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
cmd := exec.CommandContext(ctx, "/bin/bash", "-c", command)
out, err := cmd.CombinedOutput()
if ctx.Err() == context.DeadlineExceeded {
fmt.Println("Command timed out")
@Makio64
Makio64 / rollup.config.js
Created August 5, 2018 23:46
Rollup Config with : es6 ( Babel ) / Dynamic CodeSplitting / Stylus / Paths setup / LiveReload / Minifiers / esm export / ..
// ROLLUP CONFIG from @makio64
//-------------------------------------------------------------------------- PLUGINS
import includePaths from 'rollup-plugin-includepaths'
import rootImport from 'rollup-plugin-root-import'
import resolve from 'rollup-plugin-node-resolve'
import builtins from 'rollup-plugin-node-builtins'
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
@superseb
superseb / defaultdns.md
Last active April 25, 2025 12:16
Change default DNS nameserver used by Kubernetes pods

Change default DNS nameserver used by Kubernetes pods

This can be applied generically but usually applies to Linux nodes that have a local caching nameserver running, which means pointing to an IP in the loopback range (127.0.0.0/8). Ubuntu 18.04 Bionic Beaver does this by default.

Option 1: Change host configuration

sudo systemctl mask systemd-resolved
rm -f /etc/resolv.conf
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
@fakihariefnoto
fakihariefnoto / Setup Golang.md
Last active October 7, 2023 22:27
Setup golang, goroot, gopath, gobin

After download and move to your interested folder, add this line to ~/.bashrc and ~/.profile

export GOPATH=$HOME/gowork
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOPATH/bin
export GOROOT=/usr/local/go

export PATH=$PATH:$GOROOT/bin
@nginx-gists
nginx-gists / batch-api-min.conf
Last active February 16, 2023 03:01
Batching API Requests with NGINX Plus and the NGINX JavaScript Module
js_import batch-api-min.js;
# keyval_zone for APIs where the last portion of the URI is an argument
# The key is the portion of the URL before the last part
keyval_zone zone=batch_api:64k state=/etc/nginx/state-files/batch-api.json;
keyval $uri_prefix $batch_api zone=batch_api;
# keyval_zone for APIs where the last portion of the URI is an argument
# The key is the URI
keyval_zone zone=batch_api2:64k state=/etc/nginx/state-files/batch-api2.json;