Skip to content

Instantly share code, notes, and snippets.

View vaiorabbit's full-sized avatar
🎮
busy playing video games

vaiorabbit

🎮
busy playing video games
View GitHub Profile
@vaiorabbit
vaiorabbit / fiddletest1.rb
Created February 11, 2014 03:30
Fiddle 実験 : 文字列は2個しかないが関数呼び出しで参照された8回分のFiddle::Pointerが生成されている(どこかで作られたNULL相当の1個は除く)。インスタンス8個に対してptrは2種類しかない点に注目
require 'fiddle/import'
module M
extend Fiddle::Importer
dlload "/usr/lib/libstdc++.dylib"
extern "int strcmp(char*, char*)"
extern "int strlen(char*)"
end
str0 = "abc"
@vaiorabbit
vaiorabbit / fiddletest2.rb
Created February 11, 2014 03:35
Fiddle 実験 : 一方同じ内容の文字列から作ったFiddle::Pointerインスタンスを引数として渡せば無駄な生成は起きない(どこかで作られたNULL相当の1個は除く)
require 'fiddle/import'
module M
extend Fiddle::Importer
dlload "/usr/lib/libstdc++.dylib"
extern "int strcmp(char*, char*)"
extern "int strlen(char*)"
end
=begin
@vaiorabbit
vaiorabbit / packed_data.rb
Created February 11, 2014 13:49
Arrayはすげ替えつつFiddle::Pointerは使い回すクラス・PackedData
# -*- coding: utf-8 -*-
require 'fiddle'
# Array -> Fiddle::Pointer conversion
class PackedData
attr_reader :data, :pointer
def initialize( src )
@source = src # Array or String built from packed Array
@data = nil # String
@vaiorabbit
vaiorabbit / debug_output.rb
Created February 14, 2014 12:22
opengl-bindings : glDebugMessageCallback のコールバック関数としてrubyのブロックを渡す例。Fiddle::Closure::BlockCaller を使うと手短に書けました。
require 'fiddle'
=begin
# https://www.opengl.org/sdk/docs/man4/html/glDebugMessageCallback.xhtml
typedef void (APIENTRY *DEBUGPROC)(GLenum source,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
const GLchar *message,
@vaiorabbit
vaiorabbit / Building latest ruby.exe for Windows using RubyInstaller.md
Last active August 29, 2015 14:01
ローカルで最新のWindows版 ruby をつくる (RubyInstaller を使って)

[2014-05-17] Windows 7 で Ruby 2.1.2 がビルドできることを確認。

>ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [i386-mingw32]

ビルド環境

RubyIntaller のリポジトリを取得

@vaiorabbit
vaiorabbit / countdown_timer.html
Last active August 29, 2015 14:04
Countdown timer using Countdown.js (http://countdownjs.org).
<!--
Countdown timer using Countdown.js (http://countdownjs.org).
- Put https://bitbucket.org/mckamey/countdown.js/raw/tip/countdown.js here.
- Open this file in your browser.
-->
<html>
<head>
<meta charset="UTF-8">
<title>Countdown Timer</title>
</head>
@vaiorabbit
vaiorabbit / PODContainer.h
Created November 18, 2014 14:49
std::vector-like interface for array of plain old data structure.
template <typename POD>
struct PODContainer
{
POD* buf;
size_t cap, cnt;
typedef POD* iterator;
PODContainer(size_t capacity) : cnt(0), cap(capacity) { buf = (POD*)malloc(cap * sizeof(POD)); }
~PODContainer() { free(buf); }
@vaiorabbit
vaiorabbit / gist:c7a071de82d5afc59c9c
Created November 24, 2014 06:21
Installing nokogiri gem for OS X 10.10 / Homebrew [2014-11-24]

Installing nokogiri gem for OS X 10.10 / Homebrew [2014-11-24]

I found some strings like

@@HOMEBREW_CELLAR@@/xz/5.0.7/lib

in libxml2's configuration log and Makefile. So I have to set these path strings explicitly via LZMA_* environment variables.

$ which ruby
/Users/foo/.rvm/rubies/ruby-2.1.5/bin/ruby
class Node
attr_accessor :id, :edges
def initialize(node_id)
@id = node_id
@edges = []
end
def edge(other_node)
@edges.each do |edge|
return edge if edge.has_node?(other_node)
# Ref.:
# http://www.redblobgames.com/grids/hexagons/
# http://www.redblobgames.com/grids/hexagons/implementation.html
class Hex
attr_accessor :q, :r, :s
def initialize(q, r, s = -q - r)
@q = q