Skip to content

Instantly share code, notes, and snippets.

@fenrir-naru
fenrir-naru / ractor_35.rb
Last active August 10, 2025 23:41
Retrofit of Ractor in Ruby 3.5 to work like one in Ruby <= 3.4 having yield/take
Ractor = Class::new(Ractor){
def self.new(*args, &b)
out_port = Ractor::Port::new
res = super(out_port, *args, &(proc{|_port, *_args|
Ractor[:out_port] = _port
_args
} >> b))
res.monitor(out_port)
res.define_singleton_method(:out_port){out_port}
res
@fenrir-naru
fenrir-naru / access_ractor_selector.rb
Created July 13, 2025 15:58
Access Ractor::Selector by calling C API without Ruby build
if true then
# Fiddle version
require 'fiddle'
module Fiddle
Function.new(dlopen(nil).sym('rb_init_ractor_selector'), [], TYPE_VOID).call
end
else
# FFI version
require 'ffi'
Module::new{
@fenrir-naru
fenrir-naru / landisk-shutdown.rb
Last active July 23, 2024 15:19
HDL-AAX shutdown script
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
# 設定内容
url = "http://192.168.1.XXX" # TODO
password = "password" # TODO
module Kernel # required for version below 2.6
def then
return to_enum(__method__) { 1 } unless block_given?
@fenrir-naru
fenrir-naru / dow_spec.rb
Last active July 4, 2024 16:21
weekday C function for 8bit MCU
require 'rspec'
require 'inline'
require 'date'
module Date_C
inline{|builder|
builder.add_type_converter('unsigned char', 'NUM2CHR', 'CHR2FIX')
builder.include("<time.h>") #builder.prefix("#include <time.h>")
builder.c_singleton(open(File::join(File::dirname(__FILE__), 'dow_time_h.c')).read)
builder.c_singleton(open(File::join(File::dirname(__FILE__), 'dow_u8.c')).read)

How to use this program to estimate relative position between two near GNSS antennas

  1. Install Ruby
    • For Windows users, RubyInstaller is convinient, and please select "WITH DEVKIT" version because of native compilation required by a dependent gem.
  2. Install gps_pvt gem: gem install gps_pvt
  3. Download est_proximity.rb
  4. Type the following on the directory in which est_proximity.rb and observation files are stored: ./est_proximity.rb base_obs_file aux_obs_file1 [aux_obs_file2] ... [options] ...
    • The supported formats of the observation files are u-blox(UBX), RINEX OBS(v2/v3). COM port and Ntrip stream can be used. The details are described in gps_pvt readme.
  • --onl
@fenrir-naru
fenrir-naru / ambiguity_test.rb
Last active October 25, 2022 02:14
Attitude estimation code 2022/10/25
#!/usr/bin/ruby
require 'gps_pvt'
LAMBDA = GPS_PVT::GPS::SpaceNode.L1_WaveLength
Mat = GPS_PVT::SylphideMath::MatrixD
candidates = [-1, 0, 1]
run = proc{
prop = {}
@fenrir-naru
fenrir-naru / Outlook.vbs
Last active May 13, 2021 23:54
Outlook desktop to Google calendar
Public WithEvents myOlFolder As Outlook.Folder
Public WithEvents myOlItems As Outlook.Items
Public Sub Application_Startup()
Set myOlFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar)
Set myOlItems = myOlFolder.Items
End Sub
Private Sub sendREST(ByVal Item As Object, ByVal Mode As String)
Dim params As Object
@fenrir-naru
fenrir-naru / BoostDistributions.i
Last active September 17, 2020 00:00
SWIG for boost::math::distributions
/**
* @file SWIG interface file for boost::math::distributions
*
*/
%module BoostDistributions
%include exception.i
%exception {
try {
@fenrir-naru
fenrir-naru / EFS%nv%item_files%mcfg%mcfg_sel_db.xml
Last active March 13, 2020 00:38
Mi 9 SE with AU(KDDI) CDMA
<?xml version="1.0" encoding="UTF-8"?>
<policy mcfg_db_ver="1.2.3" name="generic">
<initial>
<tristate_define name="iin" value="undef" />
<tristate_define name="3gpp_imsi" value="undef" />
<tristate_define name="3gpp2_imsi" value="undef" />
</initial>
<if>
<any_of evaluate_all="true">
<tristate_reset_all return="false" />
@fenrir-naru
fenrir-naru / R_bootstrap.rb
Last active April 1, 2019 05:08
Windows R deployment script without system wide modification, a.k.a., "portable"
#!/usr/bin/ruby
class R_Bootstrap
class <<self
def registry_check(ver = nil)
[:HKLM, :HKCU].collect{|head|
`reg query "#{head}\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall" /f "R for Windows*is1" 2>nul`.scrub.lines
}.flatten.collect{|line|
next unless line.strip =~ /^\s*(.*#{ver}_is1)/
$1