Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<script>
function onChangeCheck(c, cls) {
const found = document.getElementsByClassName(cls);
for (const elem of found) {
if (c.checked) {
elem.classList.add('highlighted');
} else {
@yoh2
yoh2 / japanese-dvorakjp.scm
Last active April 8, 2020 01:59
uim-skk と DvorakJP を組み合わせて使う ref: http://qiita.com/yoh2/items/66d70e33e47d6fb68d2f
(define ja-dvorakjp-rule-basic
'(
((("c" "a"). ())("か" "カ" "カ"))
((("c" "i"). ())("き" "キ" "キ"))
((("c" "u"). ())("く" "ク" "ク"))
((("c" "e"). ())("け" "ケ" "ケ"))
((("c" "o"). ())("こ" "コ" "コ"))
((("c" "y"). ("y" "k"))("" "" ""))
((("c" "n"). ("y" "k"))("" "" ""))
@yoh2
yoh2 / alloc_error.zen
Created December 17, 2019 14:22
heap.create で分かりにくいエラー (std/heap.zen 中で error[E04001]: use of undefined value) が出るもの
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 December 6, 2019 14:37
Kotlin で Brainf*ck
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 November 11, 2019 13:01
大雑把改行カウント
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;
}
}
#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 March 7, 2019 12:31
ループも再帰も使わず (ある意味再帰ではあるが) Hello, World! を出力し続ける上にめっちゃ止めにくいやつ。
#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 January 9, 2019 16:27
1000000バイト
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
vVnHyXn+THQJRbwzYaMQ7eNdYRqqGVoKOI23l3ZMx8RDpbYfqBBVRYokO3n0EFDDfW/W6fxDaYgK
@yoh2
yoh2 / hoge.rs
Last active July 25, 2018 15:23
並列化失敗例
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 June 21, 2018 13:47
片っ端から iconv 変換を試してみる
#!/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 ==========================