Skip to content

Instantly share code, notes, and snippets.

@yoh2
yoh2 / alloc_error.zen
Created Dec 17, 2019
heap.create で分かりにくいエラー (std/heap.zen 中で error[E04001]: use of undefined value) が出るもの
View alloc_error.zen
const std = @import("std");
const heap = std.heap;
var buffer: [4096]u8 = undefined;
var allocator = heap.FixedBufferAllocator{ .buffer = &buffer };
fn Node(comptime T: type) type {
return struct {
next: ?*Node(T),
data: T,
@yoh2
yoh2 / Bf.kt
Last active Dec 6, 2019
Kotlin で Brainf*ck
View Bf.kt
import java.io.IOException
class Bf(private val program: BfProgram, memorySize: Int) {
private val memory = Array<Byte>(memorySize, {0})
private var pointer = 0
private var data
get() = memory[pointer]
set(value) { memory[pointer] = value }
fun execute(): BfResult<Unit> {
@yoh2
yoh2 / lf_count.c
Created Nov 11, 2019
大雑把改行カウント
View lf_count.c
size_t simple_count(const char buf[], size_t n)
{
size_t count = 0;
for(size_t i = 0; i < n; i++)
{
if(buf[i] == '\n')
{
++count;
}
}
View cdsh.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
const char *get_dir(int argc, char *argv[])
{
if(argc <= 1)
{
const char *home = getenv("HOME");
return (home == NULL) ? "/" : home;
@yoh2
yoh2 / hello-endless.c
Created Mar 7, 2019
ループも再帰も使わず (ある意味再帰ではあるが) Hello, World! を出力し続ける上にめっちゃ止めにくいやつ。
View hello-endless.c
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
puts("Hello, World!");
if(fork() == 0)
{
execlp(argv[0], argv[0], (const char *)NULL);
}
@yoh2
yoh2 / 9799-base64-2
Created Jan 9, 2019
1000000バイト
View 9799-base64-2
This file has been truncated, but you can view the full file.
/Td6WFoAAATm1rRGAgAhARYAAAB0L+WjAe1v/Td6WFoAAATm1rRGAgAhARYAAAB0L+WjAe1W/Td6
WFoAAATm1rRGAgAhARYAAAB0L+WjAe0+/Td6WFoAAATm1rRGAgAhARYAAAB0L+WjAe0m/Td6WFoA
AATm1rRGAgAhARYAAAB0L+WjAe0P/Td6WFoAAATm1rRGAgAhARYAAAB0L+WjAez2/Td6WFoAAATm
1rRGAgAhARYAAAB0L+WjAeze/Td6WFoAAATm1rRGAgAhARYAAAB0L+WjAezG/Td6WFoAAATm1rRG
AgAhARYAAAB0L+WjAeyy/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4PAK7/5dAH6Ny0WC5oM4+eHt
0vlHXxXkfZoM64Er1xnsSbNSZHKWALPjEkBQGqInILobCwkTFanzaaIZ632Nr+4+xVrHZDiVzoEh
JY+LSU9dQ3umjlt2fy6zmUkbX8pMf7kZk8RWEF4wwka/RcaPLOV8zOUSQcvKX5gJJcgAEPywXc6o
xQEVs4qkuMr+i0z5BHlCSBldbcNrOws2hrZgIqTdIJHcF4uBlIAhOfbeiMBecRuUx5lg932Y0Mu0
6Xv8aTIZABa2XEy6qWG/ok350wxDVh130NFjBLW4CCpEAexnOv05D4nyx8J3lYvbPCd14C7SlPV5
@yoh2
yoh2 / hoge.rs
Last active Jul 25, 2018
並列化失敗例
View hoge.rs
use std::ops::{Index, IndexMut};
use std::thread;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
// 適当行列クラス
pub struct Matrix {
nr_cols: usize,
v: Vec<f64>, // len = nr_cols * (暗黙の nr_rows)
}
@yoh2
yoh2 / hoge.sh
Created Jun 21, 2018
片っ端から iconv 変換を試してみる
View hoge.sh
#!/bin/bash
readonly infile=hoge.txt
iconv -l | while read enc; do
if iconv -f $enc -t utf-8 < $infile > tmp.txt 2>/dev/null; then
cat tmp.txt
echo --
echo $enc
echo ==========================
@yoh2
yoh2 / fizzbuzz.cpp
Last active Feb 8, 2018
型レベル FizzBuzz という字面のみから連想したもの。FizzBuzz 判定部では四則演算を用いずに型だけで何とかしてみた。
View fizzbuzz.cpp
#include <iostream>
#include <sstream>
// リスト
template<typename... TS> struct L
{
template<typename T>
using cons = L<T, TS...>;
@yoh2
yoh2 / Hoge.cs
Last active Jan 26, 2018
a == 1 && a == 2 && a == 3 を真に。
View Hoge.cs
public class Hoge
{
public static void Main(string[] args)
{
var a = new Hoge();
System.Console.WriteLine("{0}", a == 1 && a == 2 && a == 3);
}
public static bool operator==(Hoge hoge, int n)
{