Skip to content

Instantly share code, notes, and snippets.

View perillo's full-sized avatar

Manlio Perillo perillo

  • Avellino, Italy
View GitHub Profile
const std = @import("std");
const fs = std.fs;
const unicode = std.unicode;
const Ascii = struct { u8, []const u8 };
const control_codes = [_]Ascii{
.{ '\x00', "NUL" },
.{ '\x01', "SOH" },
.{ '\x02', "STX" },
.{ '\x03', "ETX" },
@perillo
perillo / zig-parser-report
Last active January 12, 2023 17:34
report from zig-package-index command
+ build/zig-package-index -cache /data/cache /home/manlio/src/contrib/zig/github.com/perillo/zig-spec/grammar
check https://github.com/capy-ui/capy/blob/master/examples/balls.zig : error: exit status 1
running 1 tests...
FAIL: /data/cache/zig-package-index/351056766/examples/balls.zig: zig: 0, grammar: 1
<stdin>:58: syntax error
capy.Align(.{}, &canvas),
^
check https://github.com/ziglibs/zgl/blob/master/binding.zig : error: exit status 1
running 1 tests...
#!/usr/bin/env bash
if [ ! -x ./build/parser ]; then
echo 'ERROR: ./build/parser: not found.'
echo 'ERROR: you need to run `make` first.'
exit 1
fi
FILES=("$@")
@perillo
perillo / fuse.go
Created May 4, 2022 17:27
A FUSE filesystem with only one file that always returns EIO on close
// Adapted from https://pkg.go.dev/github.com/hanwen/go-fuse/v2@v2.1.0/fs#example-package-HandleLess
// Copyright (c) 2010 the Go-FUSE Authors. All rights reserved.
// This program creates a FUSE filesystem with only one file called "file".
// The filesystem is mounted on /tmp/fuse.
//
// The file supports open, flush, read, write operations. The flush operation
// always return EIO.
package main
@perillo
perillo / Makefile
Last active March 23, 2022 17:34
Makefile for Zig projects
# Copyright 2021 Manlio Perillo. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# A Makefile template for Zig projects.
# Variable definitions.
export ZIG := zig-0.10.0-dev
export ZIG_LOCAL := ~/.local
const std = @import("std");
const testing = std.testing;
fn counter(comptime start: i32) fn () i32 {
const Impl = struct {
var cnt = start;
pub fn next() i32 {
const i = cnt;
cnt += 1;
const std = @import("std");
const debug = std.debug;
const testing = std.testing;
test "arrays constness" {
{
// Test mutation of an array.
var array: [1]u8 = [_]u8{'a'};
array[0] += 1;
@perillo
perillo / tcpd.go
Created May 30, 2021 09:53
A simple TCP server
// Copyright 2019 Manlio Perillo. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// package tcpd implements a TCP server that can only handle a limited number
// of long-lived connections.
//
// The implementation uses a pool of MaxConns goroutines, each handling a
// connection.
package main
Building Go cmd/dist using /usr/lib/go. (go1.16.4 linux/amd64)
xexit 0
Building Go toolchain1 using /usr/lib/go.
xexit 0
==================
WARNING: DATA RACE
Read at 0x00000075c510 by goroutine 12:
main.xexit()
/home/manlio/src/contrib/go/go.googlesource.com/go/src/cmd/dist/util.go:364 +0x79
main.main.func1()
diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go
index 00e23ef179..636f6b4257 100644
--- a/src/cmd/dist/build.go
+++ b/src/cmd/dist/build.go
@@ -246,7 +246,6 @@ func xinit() {
if err := ioutil.WriteFile(pathf("%s/go.mod", workdir), []byte("module bootstrap"), 0666); err != nil {
fatalf("cannot write stub go.mod: %s", err)
}
- xatexit(rmworkdir)