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 / fnv32a.js
Last active February 4, 2024 19:49
FNV-1a Hash (http://isthe.com/chongo/tech/comp/fnv/) in JavaScript.
// 32 bit FNV-1a hash
// Ref.: http://isthe.com/chongo/tech/comp/fnv/
function fnv32a( str )
{
var FNV1_32A_INIT = 0x811c9dc5;
var hval = FNV1_32A_INIT;
for ( var i = 0; i < str.length; ++i )
{
hval ^= str.charCodeAt(i);
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
@vaiorabbit
vaiorabbit / test.rb
Created January 4, 2024 17:01
Testing Ruby bindings for Blend2D ( https://blend2d.com )
require_relative '../lib/blend2d.rb'
require_relative 'util'
include Blend2D
if __FILE__ == $PROGRAM_NAME
load_blend2d_lib()
img = BLImageCore.new
r = blImageInitAs(img.pointer, 480, 480, BL_FORMAT_PRGB32)
require 'raylib'
include Raylib
####################################################################################################
class Game
attr_reader :high_score, :config, :current_score, :state_timer
STATES = [:Ready, :Playing, :GameOver]
/*
[Usage]
$ clang -I`brew --prefix mruby`/include -Iraylib/include raylib_mrb.c `brew --prefix mruby`/lib/libmruby.a raylib/lib/libraylib.a -lm -framework IOKit -framework Cocoa -framework OpenGL -o raylib_mrb
$ ./raylib_mrb
*/
#include <mruby.h>
#include <mruby/class.h>
#include <mruby/compile.h>
#include <mruby/data.h>
#include <mruby/string.h>
@vaiorabbit
vaiorabbit / fnv32a.el
Last active October 8, 2023 03:50
FNV-1a Hash (http://isthe.com/chongo/tech/comp/fnv/) in Emacs Lisp.
(defun fnv32a (s)
"Calculates FNV-1a 32-bit hash of given string s."
(let (hval)
(setq hval 2166136261) ; hval = FNV1_32A_INIT
(loop for c across s do
(setq hval (logxor hval c)) ; hval ^= c
(setq hval (* 16777619 hval)) ; hval *= FNV_32_PRIME
(setq hval (mod hval 4294967296))) ; hval %= UINT32_MAX
hval))
require 'uri'
google_link = ARGV[0]
encoded_url = /.+url=(.+)&.+/.match(google_link)[1]
decoded_url = URI.decode_www_form(encoded_url)
puts decoded_url
require 'ffi'
module UI
extend FFI::Library
class InitOptions < FFI::Struct
layout(
:Size, :size_t
)
end
@vaiorabbit
vaiorabbit / Building libglfw.dylib on macOS (Apple Silicon)
Last active September 8, 2022 13:10
Building libglfw.dylib on macOS (Apple Silicon)
$ 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*
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
/* -*- encoding: utf-8; -*- */
/* nuklear - v1.17 - public domain */
/* Unicode character test based on:
* https://github.com/vurtun/nuklear/blob/master/demo/glfw_opengl3/main.c */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>