Skip to content

Instantly share code, notes, and snippets.

View larskanis's full-sized avatar

Lars Kanis larskanis

  • Comcard
  • Europe/Germany
View GitHub Profile
@larskanis
larskanis / install.sh
Created April 10, 2024 08:45
install ruby-3.4.0-dev (master on 2024-04-10) with ASAN support
CC=clang-17 CFLAGS="-fsanitize=address -fno-omit-frame-pointer -DUSE_MN_THREADS=0" rvm install ruby-head
# This compiles ruby and all later gems with ASAN support enabled.
@larskanis
larskanis / bug-gssapi-caller.c
Last active November 22, 2023 20:03
postgresql-bug #18210 reproducer
/*
* Run this program in a Kerberos capable environment and it should fail like so:
* $ gcc -I /usr/include/postgresql bug-gssapi-caller.c -o bug-gssapi-caller -l pq
* $ ./bug-gssapi-caller
* PQputCopyData text2 command failed: GSSAPI caller failed to retransmit all data needing to be retried
*/
#ifdef WIN32
#include <windows.h>
#endif
@larskanis
larskanis / test-error-hash.rb
Created November 11, 2020 12:53
Trigger error on hash collision in jsonapi-resources
# run this some hundred times per:
# while ruby test-error-hash.rb ; do echo; done
#
begin
require 'bundler/inline'
require 'bundler'
rescue LoadError => e
STDERR.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
#include <stdio.h>
#include <ruby.h>
static VALUE alloc(VALUE self)
{
return rb_str_new_cstr("abcdef");
}
static struct st_table* string_table;
@larskanis
larskanis / string_alloc_test.rb
Last active February 6, 2020 13:09
string_alloc_test
require "mkmf"
create_makefile("string_alloc_test")
raise "Unable to compile" unless system("make")
require_relative "string_alloc_test.so"
require "benchmark/ips"
include StringAllocTest
def r_alloc
@larskanis
larskanis / desc.md
Last active February 3, 2020 14:05
utf8-default-enc

Set default for Encoding.default_external to UTF-8 on Windows

This issue is related to https://bugs.ruby-lang.org/issues/13488 where we already discussed the topic an postponed the change for ruby-3. Patch is here:

Currently Encoding.default_external is initialized to the local console encoding of the Windows installation unless changed per option -E. This is e.g. cp850 for Western Europe. It should be changed to UTF-8.

RubyInstaller provided a checkbox for RUBYOPT=-Eutf-8 since version 2.4. This checkbox was disabled per default, but I noticed from bug reports, that many people enabled it. With RubyInstaller-2.7.0 this checkbox is enabled per default. So we already have a steady migration towards UTF-8 on Windows.

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ruby.exe]
"GlobalFlag"=dword:00000002
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\miniruby.exe]
"GlobalFlag"=dword:00000002
@larskanis
larskanis / pg-native-timestamps.rb
Created January 26, 2019 18:52
Benchmark for native timestamp conversion on PostgreSQL adapter
# frozen_string_literal: true
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'pg', '~> 1.1'
gem 'activerecord', path: '../activerecord'
gem 'benchmark-ips'
end
/home/lars/comcard/nokogiri # rake test
/usr/bin/ruby -w -Ilib:bin:test:. -e 'require "rubygems"; require "helper"; require "minitest/autorun"; require "test/test_css_cache.rb"; require "test/test_convert_xpath.rb"; require "test/css/test_tokenizer.rb"; require "test/css/test_xpath_visitor.rb"; require "test/css/test_parser.rb"; require "test/css/test_nthiness.rb"; require "test/xml/test_syntax_error.rb"; require "test/xml/node/test_subclass.rb"; require "test/xml/node/test_save_options.rb"; require "test/xml/test_document.rb"; require "test/xml/test_node_attributes.rb"; require "test/xml/test_entity_reference.rb"; require "test/xml/test_node_encoding.rb"; require "test/xml/test_node_set.rb"; require "test/xml/test_element_content.rb"; require "test/xml/test_comment.rb"; require "test/xml/test_schema.rb"; require "test/xml/test_unparented_node.rb"; require "test/xml/test_reader_encoding.rb"; require "test/xml/test_document_encoding.rb"; require "test/xml/test_document_fragment.rb"; require "test/xml/test_dtd.
# frozen_string_literal: true
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem "pg", "~> 1.1"
gem 'activesupport', path: '../activesupport'
gem 'activerecord', path: '../activerecord'
gem 'activemodel', path: '../activemodel'