https://medium.com/@walkert/fun-building-shared-libraries-in-go-639500a6a669
https://www.darkcoding.net/software/building-shared-libraries-in-go-part-2/
| package main | |
| import ( | |
| "fmt" | |
| "go/ast" | |
| "go/parser" | |
| "go/token" | |
| ) | |
| var src = `package mypackage |
| 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))), |
| import time | |
| import struct | |
| f = open(r'\\.\pipe\NPtest', 'r+b', 0) | |
| i = 1 | |
| while True: | |
| s = 'Message[{0}]'.format(i).encode('ascii') | |
| i += 1 | |
| // 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); |
| package main | |
| import ( | |
| "context" | |
| "flag" | |
| "fmt" | |
| "log" | |
| "net/http" | |
| "os" | |
| "os/signal" |
| #! /bin/bash | |
| for n in {1..100}; do | |
| dd if=/dev/urandom of=file$( printf %d "$n" ).bin bs=1 count=$(( RANDOM + 1024 )) | |
| done |
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.
| 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) |