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 / README.md
Created January 31, 2016 09:42
Demonstrates how to get a list of favorites via Twitter API using Ruby.
  1. $ gem install oauth
  2. Go Twitter Application Management ( https://apps.twitter.com ) to get Consumer Key and Consumer Secret for your app.
  3. Fill 'TwitterApp_Consumer_Envvar.sh' with these values.
  4. $ source TwitterApp_Consumer_Envvar.sh
  5. Use 'TwitterApp_Authorize.rb' to get Access Token and Access Toke Secret.
  6. Fill 'TwitterApp_AccessToken_Envvar.sh' with these values .
  7. $ source TwitterApp_AccessToken_Envvar.sh
  8. See 'TwitterApp_GetFavs.rb' as an usage of 'TWITTER_XXXX' environment variables.
@vaiorabbit
vaiorabbit / finalizer_test.rb
Created January 31, 2016 06:51
ObjectSpace.define_finalizer and ObjectSpace.undefine_finalizer
# define_finalizer and undefine_finalizer
class Hoge
attr_accessor :name, :val
# Ref.:
# http://ruby-doc.org/core-2.3.0/ObjectSpace.html
# http://docs.ruby-lang.org/ja/2.3.0/method/ObjectSpace/m/define_finalizer.html
def initialize(n, v)
@vaiorabbit
vaiorabbit / 20-vaiotypep.conf
Created January 2, 2016 10:07
Wheel emulation settings for VAIO Type P (Linux Mint 17.3). Put this file at /usr/share/X11/xorg.conf.d/.
Section "InputClass"
Identifier "Trackpoint Wheel Emulation"
MatchIsPointer "true"
MatchProduct "TrackPoint|DualPoint Stick|PS/2 Generic Mouse"
MatchDevicePath "/dev/input/event*"
Option "Emulate3Buttons" "true"
Option "EmulateWheel" "true"
Option "EmulateWheelButton" "2"
Option "XAxisMapping" "6 7"
Option "YAxisMapping" "4 5"
@vaiorabbit
vaiorabbit / comparison.md
Created December 13, 2015 09:11
Compression time/ratio comparison between LZ4/GZip/XZ.
@vaiorabbit
vaiorabbit / aligned_ptr.rb
Created November 7, 2015 10:30
Making Fiddle::Pointer manage aligned memory
# aligned_ptr.rb
require 'fiddle'
ALLOCSIZE = 777
ALIGNMENT = 128
mem_r = Fiddle::Pointer.malloc(ALLOCSIZE + ALIGNMENT)
addr_r = mem_r.to_i
addr_a = (addr_r + ALIGNMENT - 1) & ~(ALIGNMENT - 1)
mem_a = Fiddle::Pointer.new(addr_a, ALLOCSIZE)
@vaiorabbit
vaiorabbit / hello.cl
Last active October 25, 2015 10:02
Hello, world (Ruby OpenCL) See https://github.com/vaiorabbit/ruby-opencl
#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable
/* Ref.: http://www.fixstars.com/en/opencl/book/sample/ */
__kernel void hello(__global char* string)
{
string[0] = 'H';
string[1] = 'e';
string[2] = 'l';
string[3] = 'l';
string[4] = 'o';
string[5] = ',';
require_relative 'opencl'
OpenCL.load_lib('/System/Library/Frameworks/OpenCL.framework/OpenCL')
cl_platforms_buf = ' ' * 4
# Platform
OpenCL.clGetPlatformIDs(1, cl_platforms_buf, nil)
cl_platform = cl_platforms_buf.unpack("L")[0]
# Devices
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl3.h>
#include <stdio.h>
int main(int argc, char **argv)
{
CGLContextObj ctx;
CGLPixelFormatObj pix;
GLint npix;
int attribs[] = {
@vaiorabbit
vaiorabbit / report_env.rb
Created August 16, 2015 10:15
GLFW on Mac mini (Late 2014) : We need to pass some window hints to enable OpenGL 4.1 context; otherwise we'll get old OpenGL 2.1 context.
# coding: utf-8
#
# opengl-bindings
# * http://rubygems.org/gems/opengl-bindings
# * http://github.com/vaiorabbit/ruby-opengl
#
require 'opengl'
require 'glfw'
OpenGL.load_lib()
# 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