Skip to content

Instantly share code, notes, and snippets.

@echohes
echohes / merge_2_sort_array_1.go
Last active February 28, 2022 14:46
Merge 2 sort array
package main
import "fmt"
func main() {
a := []int{1, 2, 4, 5}
b := []int{2, 5, 6, 7, 8, 9}
c := []int{}
bs := 0
i := 0
@echohes
echohes / buble_sort.lua
Last active February 26, 2022 22:46
Sort Algorithm
local a={}
for i=1,5000 do
a[i]=math.random(0, 650000)
end
local function bs(t)
for k,v in pairs(t) do
for kk,vv in pairs(t) do
if k~=kk then
@echohes
echohes / slices.go
Created March 3, 2022 07:09
Gorutine sync and change slice
package main
import (
"fmt"
"sync"
)
func test(n int, s []int, w *sync.WaitGroup) {
fmt.Println("start ", n)
for k, v := range s {
@echohes
echohes / example_custom_constraints.go
Last active March 22, 2022 07:09
Golang Generics examples
package main
import (
"fmt"
)
func main() {
var a, b uint
a = 1
@echohes
echohes / int32_to_binary.lua
Created August 22, 2022 10:03
Convert int32 to binary
function conv_to_bin(x)
t={}
if x>0 then
while x>0 do
table.insert(t,x%2)
x=math.floor(x/2);
end
end
if #t<32 then
@echohes
echohes / bin_to_int.lua
Created August 22, 2022 10:08
Convert binary to int
--a binary number is represented as values in a table
t_bin = {1,0,0,0,0,0,0,0}
function bin_to_in(x)
r=0
for k,v in pairs(x) do
r = r + (v*2^(8-k))
end
return math.floor(r)
end