Skip to content

Instantly share code, notes, and snippets.

View zergon321's full-sized avatar
🎮
Fan of Touhou Project

RedBull zergon321

🎮
Fan of Touhou Project
View GitHub Profile
@imantung
imantung / ast_print_struct_fields.go
Created June 3, 2020 11:07
Print struct field using golang AST
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
)
var src = `package mypackage
@NaniteFactory
NaniteFactory / messagebox.go
Last active April 24, 2024 17:58
Win32 API MessageBox() in Golang
import (
"syscall"
"unsafe"
)
// MessageBox of Win32 API.
func MessageBox(hwnd uintptr, caption, title string, flags uint) int {
ret, _, _ := syscall.NewLazyDLL("user32.dll").NewProc("MessageBoxW").Call(
uintptr(hwnd),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(caption))),
@fikovnik
fikovnik / getxkblayout.c
Created February 7, 2018 09:43
Get keyboard layout using X11
// compile with `gcc -I/usr/include getxkblayout.c -lX11 -lxkbfile`
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XKBrules.h>
int main(int argc, char **argv) {
Display *dpy = XOpenDisplay(NULL);
@enricofoltran
enricofoltran / main.go
Last active June 26, 2024 12:16
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
@schollz
schollz / files.sh
Last active July 30, 2023 00:19
Go upload/recieve files via POST
#! /bin/bash
for n in {1..100}; do
dd if=/dev/urandom of=file$( printf %d "$n" ).bin bs=1 count=$(( RANDOM + 1024 ))
done
@voidexp
voidexp / go-env-with-msys2.md
Last active February 19, 2024 19:44
Go development environment on Windows with MSYS2

Go development environment on Windows with MSYS2

Normally, it is sufficient to grab the Go MSI installer from the website in order to set up the toolchain. However, some packages that provide Go wrappers for C libraries rely on cgo tool, which in turn, needs the GCC toolchain in order to build the glue code. Also, 3rd-party dependencies are usually hosted on services like GitHub, thus Git is also needed. This mini-guide illustrates how to setup a convenient development environment on Windows using MSYS2.

@asukakenji
asukakenji / 0-go-os-arch.md
Last active July 18, 2024 06:42
Go (Golang) GOOS and GOARCH

Go (Golang) GOOS and GOARCH

All of the following information is based on go version go1.17.1 darwin/amd64.

GOOS Values

GOOS Out of the Box
aix
android
@ryohey
ryohey / convert.js
Created May 23, 2017 04:13
Convert YUV420(I420) Progressive Planar to RGB in JavaScript
const WIDTH = 176
const HEIGHT = 144
const progRGB = yuv420ProgPlanarToRgb(base64ToArrayBuffer(yuv420ProgPlanarImage()), WIDTH, HEIGHT)
const canvas = document.createElement("canvas")
document.body.appendChild(canvas)
const ctx = canvas.getContext("2d")
const imageData = ctx.createImageData(WIDTH, HEIGHT)
putRGBToRGBA(imageData.data, progRGB, WIDTH, HEIGHT)
ctx.putImageData(imageData, 0, 0)
@walm
walm / main.go
Last active May 15, 2024 06:01
Simple Golang DNS Server
package main
import (
"fmt"
"log"
"strconv"
"github.com/miekg/dns"
)