Skip to content

Instantly share code, notes, and snippets.

@snipsnipsnip
snipsnipsnip / gpm.rb
Last active August 29, 2015 14:15
gpm.rb
require 'strscan'
=begin
http://parametron.blogspot.jp/search/label/Christopher%20Strachey%E3%81%AEGPM
program = token*
token = argexpansion | macrocall | literal | constant
literal = [^$;<>,]+
argexpansion = ~ \d+
@snipsnipsnip
snipsnipsnip / machineof.cpp
Created February 2, 2015 00:37
引数で渡された Windows 実行形式ファイルの Machine タイプを判別する
//
// 引数で渡された Windows 実行形式ファイルの Machine タイプを判別する
// http://dsas.blog.klab.org/archives/51752824.html
//
#if !defined(UNICODE)
#define UNICODE
#define _UNICODE
#endif
#include <windows.h>
class Node
attr_accessor :value, :left, :right
def initialize(val)
@value = val # ノードが保持する値
@left = nil # 左側のノード
@right = nil # 右側のノード
end
end
# 描画に必要な情報を計算
@snipsnipsnip
snipsnipsnip / print-8.3-name.bat
Created January 12, 2015 19:16
print-8.3-name.bat
@echo %~s1
@snipsnipsnip
snipsnipsnip / tell-x86-or-x64.bat
Created January 7, 2015 18:29
tell-x86-or-x64.bat
@if "%PROCESSOR_ARCHITECTURE%%PROCESSOR_ARCHITEW6432%" EQU "x86" (
@echo truly x86
) else (
@echo x64
)
@snipsnipsnip
snipsnipsnip / amalgamator.py
Last active August 29, 2015 14:10
amalgamator.py (混汞器): #include-only dumb C Preprocessor
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# MIT License. @snipsnipsnip
"""
混汞器/アマルガメータ (Konkohki/amalgamator): #include-only dumb C Preprocessor
Sqliteのamalgamationみたいなことをするツール。
(本家を見るなら tool/mksqlite3c.tcl 参照)
つまり、#includeだけを部分的に実行するCプリプロセッサ。
@snipsnipsnip
snipsnipsnip / lookup-inode.sh
Last active August 29, 2015 14:06
lookup-inode.sh: inode番号からディレクトリ名を逆引き
#!/bin/sh
# taken from http://unix.stackexchange.com/questions/35292/quickly-find-which-files-belongs-to-a-specific-inode-number
if [ "$1" ] && [ "$2" ]; then
exec sudo debugfs -R "ncheck $2" "$1" 2> /dev/null
else
echo "usage: $0 device inode-number"
fi
@snipsnipsnip
snipsnipsnip / example.txt
Last active August 29, 2015 14:04
lvbar.rb is a `pvs` wrapper that shows allocation status of LVM logical volumes in bar chart
$ sudo ruby lvbar.rb
/dev/sda0
[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb]
a: vg_foo/lv_bar (54%)
b: (unallocated) (46%)
/dev/sda1
[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]
a: vg_foo/lv_baz (100%)
@snipsnipsnip
snipsnipsnip / name_value_table.ijs
Created June 18, 2014 03:27
name_value_table.ijs: Hashのようなもの
coclass 'NameValueTable'
PREFIX =: 'ENTRY'
NB. =: Indirectly Used Copula. http://www.jsoftware.com/help/dictionary/d001.htm
set =: dyad define
(PREFIX , x) =: y
)
NB. ~ as Evoke. http://www.jsoftware.com/help/dictionary/d220n.htm
@snipsnipsnip
snipsnipsnip / attr.ijs
Created June 14, 2014 17:43
attr_reader, attr_writer and attr_accessor in J
coclass 'attr'
attr_reader =: monad define
loc =. > coname ''
names =. ;: y
dup =. ((# names) & $) & <
fullnames =. names ,. dup ('_' , loc , '_')
". joinstring"1 (dup 'get_') ,. fullnames ,. (dup '=: 3 : ''') ,. names ,. (dup '''')
)