This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import re | |
def fnv32a( str ): | |
hval = 0x811c9dc5 | |
fnv_32_prime = 0x01000193 | |
uint32_max = 2 ** 32 | |
for s in str: | |
hval = hval ^ ord(s) | |
hval = (hval * fnv_32_prime) % uint32_max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $ cat words.txt | perl Hashcode.pl words.txt > result_perl.txt | |
use strict; | |
main() unless caller; | |
sub fnv32a { | |
my $str = $_[0]; | |
my $FNV1_32_PRIME = 0x01000193; | |
my $UINT32_MAX = 4294967296; # 2 ** 32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# usage : $ ruby bin2c.rb loremipsum.txt.bin | |
# generates 'loremipsum_txt_bin.c' : | |
# | |
# char loremipsum_txt_bin_array[/*15716*/] = { | |
# 0x5a,0x50,0x46,0x4c,0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00, | |
# ... | |
# | |
if __FILE__ == $0 | |
begin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ffi' | |
module RMath3D | |
extend FFI::Library | |
# FFI | |
case FFI::Platform::OS | |
when "darwin" | |
# $ clang -dynamiclib RMtx3.c RMtx4.c RVec3.c RVec4.c RQuat.c -o libRMath3D.dylib | |
ffi_lib "libRMath3D.dylib" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -L https://github.com/glfw/glfw/releases/download/3.3.2/glfw-3.3.2.zip > glfw-3.3.2.zip | |
$ unzip glfw-3.3.2.zip | |
$ cd glfw-3.3.2/ | |
$ mkdir build | |
$ cd build | |
$ export MACOSX_DEPLOYMENT_TARGET=10.14 | |
$ cmake -D CMAKE_BUILD_TYPE=Release -D GLFW_NATIVE_API=1 -D CMAKE_OSX_ARCHITECTURES="x86_64;arm64" -D BUILD_SHARED_LIBS=ON -D CMAKE_C_COMPILER=clang ../ | |
$ make | |
$ ls -l src/libglfw* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ref.: http://doc.ruby-lang.org/ja/2.0.0/library/fiddle=2fimport.html | |
require 'fiddle' | |
require 'fiddle/import' | |
module RMath3D | |
extend Fiddle::Importer | |
dlload Fiddle.dlopen( 'libRMath3D.dylib' ) | |
RVec4 = struct ['double x', 'double y', 'double z', 'double w'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require 'fiddle' | |
module GL | |
GL_COLOR_BUFFER_BIT = 0x00004000 | |
GL_PROJECTION = 0x1701 | |
GL_MODELVIEW = 0x1700 | |
GL_TRIANGLES = 0x0004 | |
GL_FUNCTIONS_MAP = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (Execution example) | |
# $ ruby generate_enum.rb > glenum.rb [RETURN] | |
# $ head glenum.rb [RETURN] | |
# module OpenGL | |
# GL_DEPTH_BUFFER_BIT = 0x00000100 | |
# GL_STENCIL_BUFFER_BIT = 0x00000400 | |
# GL_COLOR_BUFFER_BIT = 0x00004000 | |
# GL_FALSE = 0 | |
# GL_TRUE = 1 | |
# GL_POINTS = 0x0000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $ ruby extract_type.rb | |
# GLenum => unsigned int | |
# GLboolean => unsigned char | |
# GLbitfield => unsigned int | |
# GLvoid => void | |
# GLbyte => signed char | |
# GLshort => short | |
# GLint => int | |
# GLclampx => int | |
# GLubyte => unsigned char |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [NOTICE] Automatically generated file | |
module OpenGL | |
GL_FUNCTIONS_ARGS_MAP[:glCullFace] = [Fiddle::TYPE_INT] | |
GL_FUNCTIONS_RETVAL_MAP[:glCullFace] = Fiddle::TYPE_VOID | |
def glCullFace(_mode_) | |
f = OpenGL::get_command(:glCullFace) | |
f.call(_mode_) | |
end | |
GL_FUNCTIONS_ARGS_MAP[:glFrontFace] = [Fiddle::TYPE_INT] |