Skip to content

Instantly share code, notes, and snippets.

@yugui
yugui / extension.ja.rdoc
Last active May 27, 2023 08:36
extension.ja.rdoc -- extension library

CのデータをRubyオブジェクトにする

Cの世界で定義されたデータ(構造体)をRubyのオブジェクトとして取り扱いたい場合がありえます.このような場合はTypedData_XXX マクロ群を用いて構造体へのポインタとRubyのオブジェクトとを互いに変換できます.

# 古い(非Typedな)Data_XXXマクロ群は非推奨になりました.

# 将来のバージョンのRubyでは古いマクロは動作しなくなる可能性があります.

#include <stdio.h>
#define IS_ARRAY(ary) ((void*)(ary) == (void*)&(ary))
#define TEST(ary, expected) \
printf( \
"%s:%u: expected %s, actually %s\n", \
__FILE__, \
__LINE__, \
expected, \
(IS_ARRAY(ary) ? "array" : "ptr"))
@yugui
yugui / keybase.md
Last active September 10, 2019 13:51

Keybase proof

I hereby claim:

  • I am yugui on github.
  • I am yugui (https://keybase.io/yugui) on keybase.
  • I have a public key ASAfseopmrn1MrW_aSjjSeTm_IjW98wEtRAO6LjvmGNAmAo

To claim this, I am signing this object:

// Code generated by protoc-gen-go. DO NOT EDIT.
// source: custom-options.proto
/*
Package main is a generated protocol buffer package.
It is generated from these files:
custom-options.proto
It has these top-level messages:
load("@com_github_gengo_rules_pypi//pypi:def.bzl", "pypi_universal_repository")
BUILD_FILE = """
py_library(
name = "library",
srcs = glob(["lib/python*/site-packages/**/*.py"]),
imports = [
"lib/python2.7/site-packages",
"lib/python3.5/site-packages",
],
@yugui
yugui / gist:33963
Created December 9, 2008 16:47
How meta^n classes work in Ruby 1.9. This requires http://github.com/yugui/evil-ruby/tree/master .
require 'test/unit'
require '/Users/yugui/dev/evil-ruby/lib/evil'
class Object
alias_method :c, :actual_class
end
class Class
alias_method :s, :actual_superclass
end
class Foo; end
@yugui
yugui / apcupsd.patch
Created April 18, 2010 14:12
patch for apcupsd in order to make it a solaris pkg
diff --git a/.gitignore b/.gitignorenew file mode 100644
index 0000000..01bee7b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,30 @@
+.obj
+.deps
+*.a
+config.log
+config.out
On the 6th of May, 1709, I took a solemn leave of his majesty, and
all
my friends. This prince was so gracious as to order a guard to
conduct me to Glanguenstald, which is a royal port to the south-
west part of the island. In six days I found a vessel ready to
carry me to Japan, and spent fifteen days in the voyage.
@yugui
yugui / romantable.txt
Last active November 14, 2016 05:03
roman-kana mapping table for Google Japanese Input to type Japanese characters with ANSI keyboard
3 あ
e い
4 う
5 え
6 お
# ぁ
E ぃ
$ ぅ
% ぇ
^ ぉ
package main
import (
"log"
"github.com/golang/protobuf/jsonpb"
)
func main() {
const input = `{"create_request": {"key": "Zm9v"}}`