Skip to content

Instantly share code, notes, and snippets.

View hibariya's full-sized avatar

Hibariya hibariya

View GitHub Profile
@hibariya
hibariya / docker-compose.yml
Last active March 3, 2024 09:58
IPC example between containers with named pipes (FIFOs)
x-env: &env
- PROC_INPUT=/var/run/sample/proc-in
- PROC_OUTPUT=/var/run/sample/proc-out
- PROC_LOCK=/var/run/sample/proc.lock
volumes:
ipc:
services:
web:
@hibariya
hibariya / monty_hall.rb
Created January 31, 2021 13:13
Try Monty Hall problem a lot of times
def doit(change:, doors: [1, 2, 3])
jackpot = doors.sample
chosen = doors.sample
rest = (doors - [chosen])
drop = (rest - [jackpot]).first
finally_chosen =
if change
(rest - [drop]).first
else
#N canvas 1382 583 859 639 10;
#X obj 90 236 osc~ 400;
#X obj 90 258 *~;
#X obj 90 280 *~ 0.1;
#X obj 90 362 dac~;
#X obj 294 210 line~;
#X obj 294 131 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
1;
#X msg 294 188 \$1 100;
#X obj 294 109 r btn;
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$
EAPI=5
DESCRIPTION="Fast, reliable, and secure dependency management. https://yarnpkg.com"
HOMEPAGE="https://yarnpkg.com/"
LICENSE="BSD"
KEYWORDS="amd64"
SRC_URI="https://github.com/yarnpkg/yarn/releases/download/v${PVR}/yarn-v${PVR}.tar.gz"
@hibariya
hibariya / hi.rb
Created August 30, 2016 03:41
I never knew 'literal'.freeze is compiled in 1 instruction (not 2)
# 1 instruction
puts RubyVM::InstructionSequence.compile(%('hi')).disasm
# == disasm: #<ISeq:<compiled>@<compiled>>================================
# 0000 trace 1 ( 1)
# 0002 putstring "hi"
# 0004 leave
# 1 instruction
puts RubyVM::InstructionSequence.compile(%('hi'.freeze)).disasm
# == disasm: #<ISeq:<compiled>@<compiled>>================================
@hibariya
hibariya / UNI-VGA2C.rb
Last active June 12, 2018 18:23
Convert font (bdf) file to c file
File.write 'font.c', "const UINTN[][16] = {\n" + (Array.new(31) + File.read('u_vga16.bdf').split(/\nENCODING\s+/).tap(&:shift))[32..126].map {|char| " {\n" + char.match(/BITMAP[0-9A-F\n]+ENDCHAR/)[0].scan(/\n[0-9A-F]{2}+/).map(&:strip).map {|e| r = e.each_char.map {|a| "%04d" % Integer("0x#{a}").to_s(2) }.join; " 0b#{r}" }.join(",\n") + "\n }" }.join(",\n") + "\n};"
@hibariya
hibariya / Makefile
Last active May 1, 2021 21:22
Trying to get 4KB paging in long-mode...
all: bootable.bin
bootable.bin:
nasm boot.s -o $@
clean:
rm -rf *.bin
run: bootable.bin
qemu-system-x86_64 -monitor stdio bootable.bin
@hibariya
hibariya / Makefile
Created June 19, 2016 06:17
Calling c function from x86-64 assembly code (System V AMD64 ABI)
OBJECTS = func.o main.o
CC = gcc
CFLAGS = -std=c11 -m64 -Wall -Wextra -Werror -c
AS = nasm
ASFLAGS = -f elf64
all: $(OBJECTS)
gcc -m64 $(OBJECTS) -o main
run: all
@hibariya
hibariya / Makefile
Last active November 11, 2022 10:35
Calling c function from x86 assembly code (cdecl)
OBJECTS = func.o main.o
CC = gcc
CFLAGS = -std=c11 -m32 -Wall -Wextra -Werror -c
AS = nasm
ASFLAGS = -f elf
all: $(OBJECTS)
gcc -m32 $(OBJECTS) -o main
run: all