Skip to content

Instantly share code, notes, and snippets.

View WolvenSpirit's full-sized avatar
🐺

Mihai WolvenSpirit

🐺
View GitHub Profile
// mem out
go test -run none -bench . -benchtime <seconds>s -benchmem -memprofile mem.out
// cpu out
go test -run none -bench . -benchtime <seconds>s -benchmem -cpuprofile cpu.out
// analyze
go tool pprof -alloc_space <dir>.test mem.out
package main
import (
"fmt"
"os"
"strconv"
"syscall"
"unsafe"
)
@WolvenSpirit
WolvenSpirit / cgo.md
Created January 30, 2022 13:02 — forked from zchee/cgo.md
cgo convert list

See also, http://libraryofalexandria.io/cgo/

Using Go cgo

cgo has a lot of trap.
but Not "C" pkg also directory in $GOROOT/src. IDE's(vim) Goto command not works.

So, Here collect materials.

@WolvenSpirit
WolvenSpirit / image_draw_example.go
Last active January 22, 2020 10:01
Using image library and draw to do basic draw operation on top of images.
package main
import (
"bytes"
"fmt"
"image"
"image/color"
"image/draw"
_ "image/gif"
"image/jpeg"
package main
import (
"log"
"reflect"
"unsafe"
)
func main() {
z := struct{ something string }{something: "..."}
@WolvenSpirit
WolvenSpirit / gen.js
Created September 8, 2019 17:26
Generate html
/* --- generate html from json ---
* ~ A lot of things are taken for granted here. ~
* - ajax has content-type hardcoded as json
* - div have bootstrap container class and schema section key as id
* - inputs have bootstrap form-control class
* - each content is a separate div container
* Limited custom behavior can be made by writing in custom
*/
var custom = ()=>{
document.getElementById("product").className="";
package main
import (
"bufio"
"fmt"
"io"
"log"
"net"
"os"
"strings"
package main
import ("fmt"
"net/http")
func server(){
http.HandleFunc("/",index_handler)
http.HandleFunc("/links",links_handler)
http.ListenAndServe("127.0.0.1:8000", nil)
}
@WolvenSpirit
WolvenSpirit / AF_UNIX_WrapperC.php
Last active October 29, 2022 22:04
AF_UNIX socket listener and client in PHP
<?php
/********************************************************************************
* Thin wrapper for basic I/O between scripts while still keeping them separate.*
* Switch to AF_INET and provide the host address:port to fetch from network. *
* <Github/WolvenSpirit> *
********************************************************************************/
// # work in progress #
class AF_UNIX_WrapperC
{
@WolvenSpirit
WolvenSpirit / RouterClass.php
Last active December 18, 2018 17:59
ProjectRoot/application/src/RouterClass.php
<?php
namespace Application\Source;
# The public index will require this file first,
/*
* ROUTER FILE
*/
class RouterClass
{
public static function init()