Skip to content

Instantly share code, notes, and snippets.

View xujihui1985's full-sized avatar
🎯
Focusing

AngrySean xujihui1985

🎯
Focusing
  • ByteDance
  • Singapore
View GitHub Profile
@xujihui1985
xujihui1985 / main.rs
Last active August 27, 2024 08:53
tls
use std::{
fs::File,
io::{self, BufReader},
};
use hyper::{
server::conn::AddrIncoming,
service::{make_service_fn, service_fn},
Body, Method, Request, Response, Server, StatusCode,
@xujihui1985
xujihui1985 / ingress.yaml
Last active May 13, 2019 08:56
ingress controller traffic split
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
spanner.ingress.kubernetes.io/service-weights: |
revision-0001: 90%
revision-0002: 10%
name: my-app
spec:
rules:
// AtomicWriteFile atomically writes data to a file by first writing to a
// temp file and calling rename.
func AtomicWriteFile(filename string, data []byte, perm os.FileMode) error {
buf := bytes.NewBuffer(data)
return atomicWriteFile(filename, buf, int64(len(data)), perm)
}
// atomicWriteFile writes data to a file by first writing to a temp
// file and calling rename.
func atomicWriteFile(filename string, r io.Reader, dataSize int64, perm os.FileMode) error {
@xujihui1985
xujihui1985 / reverse.js
Created February 7, 2017 06:43
reverse sentense
const assert = require('assert');
function reverse(sentences) {
const tokens = sentences.split(' ');
const half = Math.floor(tokens.length / 2)
for(let i = 0; i < half; i++) {
const a = tokens[i];
const b = tokens[tokens.length - (i + 1)];
if (b === undefined) {
return;
package main
import (
"fmt"
"sync"
"time"
"github.com/xujihui1985/safemap/safemap"
)
@xujihui1985
xujihui1985 / shortcut
Created October 18, 2014 01:40
mac chrome shortcut
Continue: F8 or Command-/ (forward slash) on Mac or Control-/ (forward slash) on other platforms.
Step over: F10 or Command-' (apostrophe) on Mac or Control-' (apostrophe) on other platforms.
Step into: F11 or Command-; (semi-colon) on Mac or Control-; (semi-colon); on other platforms.
Step out: Shift-F11 or Shift-Command-; (semi-colon) on Mac or Shift-Control-; (semi-colon) on other platforms.
Next call frame: Control-. (period) on all platforms.
Previous call frame: Control-, (comma) on all platforms.
@xujihui1985
xujihui1985 / flatten.js
Last active August 29, 2015 14:05
array flatten
function flatten(arr) {
var result=[],
concat = Array.prototype.concat,
push = Array.prototype.push,
element,
array = arr.slice(); //shadow copy the array
for(var i = 0, l = array.length; i < l; i++) {
element = arr[i];
if(isArray(element)) {
//for proformance reason, if all element flattened already, do not recurcivly call
@xujihui1985
xujihui1985 / asyncwithgenerator.js
Created August 5, 2014 14:08
asyncwithgenerator.js
function request(url) {
// this is where we're hiding the asynchronicity,
// away from the main code of our generator
// `it.next(..)` is the generator's iterator-resume
// call
makeAjaxCall( url, it.next.bind(it) );
// Note: nothing returned here!
}
//otherwise I got Method Generator.prototype.next called on incompatible receiver undefined