Skip to content

Instantly share code, notes, and snippets.

@yankooo
yankooo / CodeContextProvider.java
Created November 28, 2024 08:44
CodeContextProvider.java
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.PsiReference;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.openapi.vfs.VirtualFile;
@yankooo
yankooo / mha.go
Created September 26, 2023 14:16
mha
package main
import (
"database/sql"
"fmt"
"log"
"time"
_ "github.com/go-sql-driver/mysql"
)

Install Zsh and Oh-my-zsh on CentOS 7

Based on this article

ALL INSTALLATIONS ASSUME YES WHEN PROMPTED, that's what -y does

This script can be copy paste to ssh as is. No hands installation. :-)

yum install zsh -y
@yankooo
yankooo / channel.go
Created September 17, 2020 10:26
channel.go
package garbage
import "testing"
var i int
func BenchmarkBoolInt(b *testing.B) {
c := make(chan int, b.N)
for i := 0; i < b.N; i++ {
c <- i
}
@yankooo
yankooo / string2byte.go
Last active September 1, 2020 10:28
string2bytes
func BytesToStringWithNoCopy(bytes []byte) string {
return *(*string)(unsafe.Pointer(&bytes))
}
func StringToBytesWithNoCopy(s string) []byte {
x := (*[2]uintptr)(unsafe.Pointer(&s))
h := [3]uintptr{x[0], x[1], x[1]}
return *(*[]byte)(unsafe.Pointer(&h))
}
@yankooo
yankooo / syscall.go
Created August 17, 2020 03:17
kill process by pid via port
func Kill(port string) {
output, _ := exec.Command("lsof", "-ti", "TCP:"+port).Output()
pid, err := strconv.ParseInt(strings.Trim(string(output), "\n"), 10, 64)
if err != nil {
return
}
syscall.Kill(int(pid), syscall.SIGTERM)
}
@yankooo
yankooo / cas_vs_mutex.go
Created June 28, 2020 03:56
cas vs mutex
package adder
import (
"sync"
"sync/atomic"
"testing"
)
type Counter interface {
Inc()
@yankooo
yankooo / http2_client.go
Created June 7, 2020 09:08
golang http2 example
package main
import (
"crypto/tls"
"crypto/x509"
"golang.org/x/net/http2"
"io/ioutil"
"log"
"net/http"
)