Skip to content

Instantly share code, notes, and snippets.

View shimamura-sakura's full-sized avatar
🖥️
Coding…

lipsum shimamura-sakura

🖥️
Coding…
View GitHub Profile
@shimamura-sakura
shimamura-sakura / kaku.js
Last active June 25, 2024 03:00
Ohjelma romaaneiden lataamiseen kakuyomu:sta
'use strict';
module.exports = {
workNextData,
parseWorkHTML,
parseEpisodeHTML,
};
let lazy_JSDOM = null;
@shimamura-sakura
shimamura-sakura / box.zig
Created May 14, 2024 14:50
boxing a value in Zig
const std = @import("std");
const Allocator = std.mem.Allocator;
pub fn box(allocator: Allocator, value: anytype) !*@TypeOf(value) {
const ptr = try allocator.create(@TypeOf(value));
ptr.* = value;
return ptr;
}
test {
@shimamura-sakura
shimamura-sakura / struct-tuple-init.zig
Created April 20, 2024 16:17
Zig init struct with a tuple (so you can init it without writing field name)
const std = @import("std");
pub fn StructFieldsTuple(comptime T: type) type {
var info = switch (@typeInfo(T)) {
.Struct => |st| st,
else => @compileError("T must be a struct"),
};
var newFields = info.fields[0..info.fields.len].*;
inline for (&newFields, 0..) |*f, i| f.name = std.fmt.comptimePrint("{}", .{i});
info.decls = &.{};
@shimamura-sakura
shimamura-sakura / slice.zig
Last active February 6, 2024 08:52
A helper type for reading from memory files as a stream, referencing original memory.
fn Slice(comptime T: anytype) type {
return struct {
const Self = @This();
const Error = error{EOF};
left: T,
pub fn take(self: *Self, n: anytype) Error!@TypeOf(self.left[0..n]) {
if (self.left.len < n) return Error.EOF;
defer self.left = self.left[n..];
return self.left[0..n];
}
@shimamura-sakura
shimamura-sakura / goo-blog-copy.js
Created June 9, 2023 14:16
A javascript bookmark written for blog.goo.ne.jp blog articles
document.body.onclick = () => {
document.body.onclick = null;
navigator.clipboard.writeText(location.href + '\n\n' +
document.querySelector('article .mod-entry-set').innerText);
al = document.querySelectorAll('div.entry-bottom-pn>a');
if (al.length < 3) return alert('no next link');
window.location = al[2].href;
};
// bookmark this:
@shimamura-sakura
shimamura-sakura / libdeflate.zig
Created January 11, 2023 14:06
Read SMX file of SourceMod (SourcePawn) in Zig language. Decompress using libdeflate.
const c = @cImport(@cInclude("libdeflate.h"));
pub const Error = error{
LibDeflateAlloc,
LibDeflateBadData,
LibDeflateShortOutput,
LibDeflateInsufficientSpace,
LibDeflateOther,
};
@shimamura-sakura
shimamura-sakura / dsp-adpcm.zig
Last active January 4, 2023 15:38
Convert DSP-ADPCM (DSPADPCM) files to raw audio (s16le)
const std = @import("std");
const hea = std.heap.page_allocator;
pub fn main() anyerror!void {
const stderr = std.io.getStdErr().writer();
const argv = try std.process.argsAlloc(hea);
defer std.process.argsFree(hea, argv);
if (argv.len > 1) {
if (std.mem.eql(u8, argv[1], "mono")) {
if (argv.len != 4)
@shimamura-sakura
shimamura-sakura / kanda_lzs.zig
Last active January 4, 2023 10:52
Decompress .lzs files from Kanda Alice mo Suiri suru (神田アリスも推理スル). I think they are mostly BNTX files (Nintendo Switch BNTX).
const std = @import("std");
const mem = std.mem;
const hea = std.heap.page_allocator;
pub fn main() !void {
const stderr = std.io.getStdErr().writer();
const argv = try std.process.argsAlloc(hea);
defer std.process.argsFree(hea, argv);
  1. zig build-exe main.zig
  2. The video must be in resolution 1920 x 1080.
  3. ./run.sh video-file
  4. get file "file-out" at current directory
@shimamura-sakura
shimamura-sakura / KandaAlice.md
Last active April 15, 2024 08:07
Some research on game "Kanda Alice mo Suiri suru" (神田アリスも推理する)

romfs/01_script/*.bin (except info.bin) (all numbers are in little endian) file head

first 16 bytes: 0x52, 0x53, 0x34, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00.
then u32: length of instruction part
then u32: length of string part (all strings here)
then u32: length of string indices part (referring the previous table)
then 4 bytes unknown.