Skip to content

Instantly share code, notes, and snippets.

View straight-shoota's full-sized avatar

Johannes Müller straight-shoota

View GitHub Profile
@straight-shoota
straight-shoota / array.cr
Last active October 30, 2024 17:27
Examples for breaking concurrency-safety in Crystal stdlib
ary = [1, 2, 3]
ch = Channel(Nil).new
spawn do
loop do
ch.receive
ary.shift
end
end
@straight-shoota
straight-shoota / photobox-trigger.service
Last active April 30, 2024 20:30
Photoboy key trigger
# /etc/systemd/system/multi-user.target.wants/photobox-trigger.service
[Unit]
Description=Photobox Trigger Service
After=multi-user.target
[Service]
Type=idle
User=pi
ExecStart=/usr/bin/python3 /home/pi/photobox/trigger.py
Restart=on-failure
@straight-shoota
straight-shoota / errno_location.cr
Created January 11, 2024 13:56
Errno location
ERNNOS = Hash(Pointer(Int32), Int32).new(0)
enum Errno
def self.pointer
{% if flag?(:netbsd) || flag?(:openbsd) || flag?(:android) %}
LibC.__errno
{% elsif flag?(:linux) || flag?(:dragonfly) %}
LibC.__errno_location
{% elsif flag?(:wasi) %}
raise NotImplementedError.new("Errno.pointer")
@straight-shoota
straight-shoota / README.md
Last active January 5, 2024 21:48
Gl-iNET AR300M Network Mode Toggle
  1. Download network-mode.sh
  2. Set executable flag and upload network-mode.sh to router (at $IP)
    chmod +x network-mode.sh
    scp network-mode.sh root@$IP:/etc/gl-switch.d/network-mode.sh
  3. Go to router web UI (http://$IP).
  4. Go to System > Toggle Button Settings, select Network Mode.
  5. Profit.
@straight-shoota
straight-shoota / Makefile
Last active January 13, 2024 23:31
Crystal combined `unreachable` tallies
## Generate database of def tallies
## $ make
SOURCES := $(shell find src -name '*.cr')
SPEC_SOURCES := $(shell find spec -name '*.cr')
CRYSTAL := bin/crystal
SQLITE := sqlite3
SQLITE-UTILS := sqlite-utils
@straight-shoota
straight-shoota / README.md
Last active August 25, 2023 20:50
crystal-tool-demo unreachable results

This output is generated by the prototype unreachable tool from bcardiff/crystal-tool-demo.

Usage (working directory is expected to be the crystal repository)

git clone https://github.com/bcardiff/crystal-tool-demo
cd crystal-tool-demo
sed -i -E 's|require "compiler/crystal/\*\*"|require "compiler/requires"|' src/unused.cr
make bin/unused
cd ..

This output is generated by a prototype of crystal tool unreachable (straight-shoota:feat/tool-unreachable@81ea65e8).

Usage:

git fetch [email protected]:straight-shoota/crystal feat/tool-unreachable
git checkout FETCH_HEAD
make crystal
bin/crystal tool unreachable src/compiler/crystal.cr -c src/compiler/ > unreachable.log
[
{
"author": "HertzDevil",
"state": "APPROVED",
"pr": "PR_kwDOAGkZhc5QGNG7"
},{
"author": "HertzDevil",
"state": "APPROVED",
"pr": "PR_kwDOAGkZhc5QGL6i"
},{
@straight-shoota
straight-shoota / regession-io.no-debug.ll.diff
Last active January 20, 2023 11:16
[Regression] Dwarf loader breaks socket IO in Crystal 1.7 (LLVM IR diff)
This file has been truncated, but you can view the full file.
diff --git 1/regression-io.no-debug.bad.ll 2/regression-io.no-debug.good.ll
index 6e89ec43b..6d5084431 100644
--- 1/regression-io.no-debug.bad.ll
+++ 2/regression-io.no-debug.good.ll
@@ -123,16 +123,14 @@ target triple = "x86_64-unknown-linux-gnu"
%"struct.LibC::Addrinfo" = type { i32, i32, i32, i32, i32, %"struct.LibC::Sockaddr"*, i8*, %"struct.LibC::Addrinfo"* }
%"struct.LibC::Sockaddr" = type { i16, [14 x i8] }
%"struct.LibC::StackT" = type { i8*, i32, i64 }
+%"Char::Reader" = type { %String*, i32, i32, i32, %"(UInt8 | Nil)", i1 }
+%"(UInt8 | Nil)" = type { i32, [1 x i64] }
@straight-shoota
straight-shoota / id_ed25519.pub
Last active October 13, 2022 16:22
SSH keys
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOZzoh/ZzxqO6+SVFlTrdVqkrq842RvfV6UonV7sdAZ5 Johannes@Milos