Skip to content

Instantly share code, notes, and snippets.

View eiyaya's full-sized avatar

stephen zhen eiyaya

  • Beijing. China.
View GitHub Profile
@eiyaya
eiyaya / optimize.sh
Created October 29, 2023 00:37 — forked from taurusxin/optimize.sh
Linux Optimization Script
#!/usr/bin/env bash
echo=echo
for cmd in echo /bin/echo; do
$cmd >/dev/null 2>&1 || continue
if ! $cmd -e "" | grep -qE '^-e'; then
echo=$cmd
break
fi
done
@eiyaya
eiyaya / UITextTypeWriter.cs
Created February 25, 2020 23:58 — forked from unitycoder/UITextTypeWriter.cs
Type out UI text one character at a time
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
// attach to UI Text component (with the full text already there)
public class UITextTypeWriter.cs : MonoBehaviour
{
Text txt;
@eiyaya
eiyaya / consul-a-install.txt
Created April 29, 2019 04:25 — forked from sdorsett/consul-a-install.txt
install 3 node consul cluster on Centos 7
yum install -y epel-release
yum install -y bind-utils unzip jq
cd ~/
wget https://releases.hashicorp.com/consul/1.0.2/consul_1.0.2_linux_amd64.zip
unzip consul_1.0.2_linux_amd64.zip
mv consul /usr/local/bin/
adduser consul
mkdir /etc/consul.d
chown -R consul:consul /etc/consul.d/
mkdir /var/consul
@eiyaya
eiyaya / master.md
Created January 3, 2019 13:57 — forked from GovardhanKanala/master.md
Install Consul Server on Centos 7
echo '
#! /bin/bash


####### yum update is optional #####
#yum -y update
yum install firewalld -y
systemctl start firewalld
firewall-cmd  --add-port=8300/tcp --add-port=8301/tcp --add-port=8302/tcp --add-port=8400/tcp --add-port=8500/tcp --add-port=80/tcp --add-port=443/tcp --permanent
@eiyaya
eiyaya / Coroutine.cs
Created December 30, 2018 12:51
Unity3d Timer
IEnumerator Start() {
while(true) {
yield return new WaitForSeconds(1f);
OutputTime();
}
}
void OutputTime() {
Debug.Log(Time.time);
}
@eiyaya
eiyaya / Unmarshal.go
Created December 21, 2018 13:40
Go program that uses json.Unmarshal
package main
import (
"encoding/json"
"fmt"
)
type Language struct {
Id int
Name string
@eiyaya
eiyaya / detectClosedConn.go
Created November 13, 2018 08:17
How to know TCP connection is closed in Golang net package
one := []byte{}
c.SetReadDeadline(time.Now())
if _, err := c.Read(one); err == io.EOF {
l.Printf(logger.LevelDebug, "%s detected closed LAN connection", id)
c.Close()
c = nil
} else {
var zero time.Time
c.SetReadDeadline(time.Now().Add(10 * time.Millisecond))
}
@eiyaya
eiyaya / GoSafe.go
Last active November 13, 2018 07:39
golang http server panic recover //StateHijacked, https://launchdarkly.com/blog/golang-pearl-its-dangerous-to-go-alone
import (
"github.com/launchdarkly/foundation/logger"
"runtime"
)
func GoSafely(fn func()) {
go func() {
defer func() {
if err := recover(); err != nil {
### IMPROVE SYSTEM MEMORY MANAGEMENT ###
# Increase size of file handles and inode cache
fs.file-max = 2097152
# Do less swapping
vm.swappiness = 10
vm.dirty_ratio = 60
vm.dirty_background_ratio = 2
@eiyaya
eiyaya / 1. Install Redis
Created November 1, 2018 23:42 — forked from pbolduc/1. Install Redis
Install redis on CentOS 7
# see How to Install Redis Server on CentOS 7 - http://linoxide.com/storage/install-redis-server-centos-7/
# --- Compiling ---
$ yum install gcc make tcl
$ REDIS_VER=3.2.3
$ wget http://download.redis.io/releases/redis-$REDIS_VER.tar.gz
$ tar xzvf redis-$REDIS_VER.tar.gz
$ cd redis-$REDIS_VER
$ make
$ make test