Skip to content

Instantly share code, notes, and snippets.

View mah0x211's full-sized avatar
🥑
the daily bento-making for my daughter has begun...

Masatoshi Fukunaga mah0x211

🥑
the daily bento-making for my daughter has begun...
View GitHub Profile
@mah0x211
mah0x211 / test_async_ops_with_libpq.c
Created September 12, 2023 15:56
test code for asynchronous processing with libpq.
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
// header files for libpq
#include <libpq-fe.h>
#include <postgres_ext.h>
#define OK 0
@mah0x211
mah0x211 / example_cgo_filelock.go
Created February 14, 2019 06:40
cgoを使ったファイルロック
// example of file locking by cgo
// Created by Masatoshi Fukunaga on 2019/02/14
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
@mah0x211
mah0x211 / gist:44434125fa9bb0ac731d678b5a8941a7
Created September 14, 2018 04:31
Memo:Git で歴史の書き換え
# rewriting content history
git filter-branch -f --tree-filter <script> --tag-name-filter cat -- --all
# rewriting commit message history
git filter-branch -f --msg-filter <script> --tag-name-filter cat -- --all
@mah0x211
mah0x211 / rh_hash_table.hpp
Created June 19, 2017 08:22 — forked from ssylvan/rh_hash_table.hpp
Quick'n'dirty Robin Hood hash table implementation. Note, I have implemented this algorithm before, with tons of tests etc. But *this* code was written specifically for the blog post at http://sebastiansylvan.com/post/robin-hood-hashing-should-be-your-default-hash-table-implementation/, it has not been extensively tested so there may be bugs (an…
#define USE_ROBIN_HOOD_HASH 1
#define USE_SEPARATE_HASH_ARRAY 1
template<class Key, class Value>
class hash_table
{
static const int INITIAL_SIZE = 256;
static const int LOAD_FACTOR_PERCENT = 90;
struct elem
@mah0x211
mah0x211 / pre-commit
Last active September 13, 2018 00:34
git pre-commit hook for luarocks repository
#!/bin/sh
#
# this script create a luarocks manifest file
# .git/hooks/pre-commit
#
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object(MAGIC number)
@mah0x211
mah0x211 / settings.json
Last active July 18, 2019 22:55
mah0x211's vscode user settings
// mah0x211's vscode user settings
{
// appearance settings
"breadcrumbs.enabled": true,
"window.zoomLevel": 0,
// "editor.wordWrap": false,
"workbench.colorTheme": "Quiet Light",
"workbench.sideBar.location": "left",
// font settings
@mah0x211
mah0x211 / normalize.c
Created February 19, 2015 19:37
realpathを使わないパスの正規化。realpathを使うと実際にファイルシステムを辿るためその前に正規化したいケースで使う。
/*
* Copyright 2015 Masatoshi Teruya. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@mah0x211
mah0x211 / grn_table_iterator
Last active March 4, 2024 01:51
table list API
typedef struct _grn_table_iter {
grn_ctx *ctx;
grn_table_cursor *cur;
} grn_table_iter;
grn_rc grn_table_iter_init( grn_ctx *ctx, grn_table_iter *it )
{
if( ( it->cur = grn_table_cursor_open( ctx, grn_ctx_db( ctx ), NULL, 0,
NULL, 0, 0, -1, 0 ) ) ){
@mah0x211
mah0x211 / siphash.c
Created August 6, 2013 23:25
experimental implementation of SipHash. referenced from; https://131002.net/siphash/ https://131002.net/siphash/siphash.pdf.
/*
* siphash.c
*
* Created by Masatoshi Teruya on 13/08/06.
*
*/
#include <unistd.h>
#include <limits.h>
#include <stdint.h>
@mah0x211
mah0x211 / segfault.lua
Created April 19, 2013 03:26
luajitがSegmentation faultで落ちる。こまた。
-- change string metatable
do
local meta = debug.getmetatable( '' );
meta.__index = function( str, field )
return nil;
end
meta.__add = function( op1, op2 )
local t1 = type( op1 );
local t2 = type( op2 );