Skip to content

Instantly share code, notes, and snippets.

View hajimehoshi's full-sized avatar
:octocat:
ギットハブ

Hajime Hoshi hajimehoshi

:octocat:
ギットハブ
View GitHub Profile
@hajimehoshi
hajimehoshi / global_function_call.go
Last active November 10, 2024 09:45
Go AST memo
// https://cs.opensource.google/go/x/tools/+/refs/tags/v0.27.0:go/types/typeutil/callee.go might be better
func checkGlobalFunctionCall(call *ast.CallExpr, pkg *packages.Package) (pkgPath, funcName string, ok bool) {
switch caller := call.Fun.(type) {
case *ast.SelectorExpr:
// Skip if the selector is a method call.
if sel := pkg.TypesInfo.Selections[caller]; sel != nil {
return
}
ident, ok := caller.X.(*ast.Ident)
@hajimehoshi
hajimehoshi / index.html
Created October 10, 2024 23:58
Loading screen
<!DOCTYPE html>
<style>
body {
background-color: black;
margin: 0;
padding: 0;
overflow: hidden;
font-family: sans-serif;
color: white;
// SPDX-License-Identifier: 0BSD
package font
import (
"image"
"image/color"
"golang.org/x/image/font"
"golang.org/x/image/math/fixed"
2022/08/23 11:56:34 SO: /usr/lib/wine/../x86_64-linux-gnu/wine/ntdll.dll.so
2022/08/23 11:56:34 SO: /usr/lib/wine/../x86_64-linux-gnu/wine/kernel32.dll.so
2022/08/23 11:56:34 SO: /usr/lib/wine/../x86_64-linux-gnu/wine/kernelbase.dll.so
2022/08/23 11:56:34 SO: /usr/lib/wine/../x86_64-linux-gnu/wine/advapi32.dll.so
2022/08/23 11:56:34 SO: /usr/lib/wine/../x86_64-linux-gnu/wine/winmm.dll.so
2022/08/23 11:56:34 SO: /usr/lib/wine/../x86_64-linux-gnu/wine/user32.dll.so
2022/08/23 11:56:34 SO: /usr/lib/wine/../x86_64-linux-gnu/wine/gdi32.dll.so
2022/08/23 11:56:34 SO: /usr/lib/wine/../x86_64-linux-gnu/wine/version.dll.so
2022/08/23 11:56:34 SO: /usr/lib/wine/../x86_64-linux-gnu/wine/msvcrt.dll.so
2022/08/23 11:56:34 SO: /usr/lib/wine/../x86_64-linux-gnu/wine/ole32.dll.so
----
Update count per frame: 1
Internal image sizes:
2: (16, 16)
3: (16, 16)
4: (4096, 4096)
5: (1024, 1024)
6: (1600, 1200)
Graphics commands:
new-image: result: 1, width: 1024, height: 1024, screen: false
@hajimehoshi
hajimehoshi / benchstat_darwin_vs_go2cpp.txt
Last active November 7, 2021 15:01
Benchmark (Go (GOOS=darwin) vs Go (GOOS=js) vs go2cpp@v0.1.3)
name old time/op new time/op delta
SprintfPadding 221ns ± 2% 748ns ± 1% +238.78% (p=0.008 n=5+5)
SprintfEmpty 18.8ns ± 1% 111.3ns ± 3% +490.87% (p=0.008 n=5+5)
SprintfString 51.4ns ± 0% 246.9ns ± 3% +379.98% (p=0.016 n=4+5)
SprintfTruncateString 94.0ns ± 1% 359.7ns ± 1% +282.49% (p=0.008 n=5+5)
SprintfTruncateBytes 92.0ns ± 2% 362.8ns ± 1% +294.35% (p=0.008 n=5+5)
SprintfSlowParsingPath 62.4ns ± 3% 281.0ns ± 1% +350.13% (p=0.008 n=5+5)
SprintfQuoteString 357ns ± 1% 1304ns ± 2% +264.88% (p=0.008 n=5+5)
SprintfInt 42.3ns ± 1% 228.4ns ± 8% +439.50% (p=0.008 n=5+5)
SprintfIntInt 83.2ns ± 1% 391.2ns ± 0% +370.36% (p=0.008 n=5+5)
diff --git a/renderer/replacepixels.go b/renderer/replacepixels.go
index 2de8786..72c9dd6 100644
--- a/renderer/replacepixels.go
+++ b/renderer/replacepixels.go
@@ -8,11 +8,17 @@ import (
"github.com/hajimehoshi/ebiten/v2"
)
-var screenBuffer *image.RGBA
+var (
@hajimehoshi
hajimehoshi / Dockerfile
Last active January 24, 2021 09:13
Cgo Cross-compile
FROM ubuntu:latest
RUN apt-get update && apt-get install -y \
gcc-10-aarch64-linux-gnu \
gcc-10-multilib \
wget
# Install Go
RUN wget -O go.tar.gz https://dl.google.com/go/go1.15.7.linux-amd64.tar.gz && \
tar -C /usr/local -xzf go.tar.gz && \
package main
import (
"image"
"image/color"
"image/draw"
"image/png"
"os"
"strings"
#!/bin/sh
# Copyright 2012 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# git gofmt pre-commit hook
#
# To use, store as .git/hooks/pre-commit inside your repository and make sure
# it has execute permissions.
#