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 / diff_ruby-1.9.3.p0_st.c_to_rbx_st.h.patch
Created November 17, 2011 13:44
Differences between st.h in rbx and st.c in mri-1.9.3 regarding to https://github.com/rubinius/rubinius/pull/1383
--- /home/lars/.rvm/src/ruby-1.9.3-p0/st.c 2011-01-27 15:30:00.000000000 +0100
+++ vm/capi/19/include/ruby/st.h 2011-10-28 23:17:41.741629969 +0200
@@ -1,18 +1,89 @@
/* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */
-/* static char sccsid[] = "@(#) st.c 5.1 89/12/14 Crucible"; */
+/* @(#) st.h 5.1 89/12/14 */
+
+#ifndef RUBY_ST_H
+#define RUBY_ST_H 1
@larskanis
larskanis / per_database_connection_not_established.rb
Created November 23, 2011 13:59
Test associations with per class database connection
require 'active_record'
ActiveRecord::Base.configurations['my_connect'] = {:adapter=>'sqlite3', :database=>'fixture_database.sqlite3'}
class Car < ActiveRecord::Base
establish_connection 'my_connect'
has_many :tyres
end
class Tyre < ActiveRecord::Base
#encoding: utf-8
require 'fox16'
include Fox
class HelloWindow < FXMainWindow
def initialize(app)
ventana = super(app, "Hello, World!", width: 600, height: 400)
MiFXText.new(ventana)
@larskanis
larskanis / gist:7186885
Created October 27, 2013 19:34
Failing test for nokogiri-1.6.0 on Windows
$ rake test
Run options: --seed 55946
# Running tests:
*********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************S**********S****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************FFEF**************************************************************
#include <ruby.h>
#include <ruby/io.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
extern void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1,
rb_unblock_function_t *ubf, void *data2);
extern void *rb_thread_call_with_gvl(void *(*func)(void *), void *data1);
@larskanis
larskanis / gist:5ebb2c96a50ed0821cf1
Created October 24, 2014 04:17
pg-0.18.0.pre20141017160319-x86-mingw32 load error
diff --git a/lib/pg.rb b/lib/pg.rb
index 3d96b75..b9b8b65 100644
--- a/lib/pg.rb
+++ b/lib/pg.rb
@@ -10,7 +10,7 @@ rescue LoadError
# Set the PATH environment variable, so that libpq.dll can be found.
old_path = ENV['PATH']
- ENV['PATH'] = "#{old_path};#{File.expand_path("../#{RUBY_PLATFORM}", __FILE__)}"
+ ENV['PATH'] = "#{File.expand_path("../#{RUBY_PLATFORM}", __FILE__)};#{old_path}"
require 'active_support'
require 'active_record'
require 'benchmark/ips'
p ActiveRecord::VERSION::STRING
# ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
ActiveRecord::Base.establish_connection adapter: 'postgresql'
ActiveRecord::Base.connection.instance_eval do
create_table(:people, force: true) do |t|
gem 'activerecord', '4.2.0.beta4'
# gem 'activerecord', '4.1.8'
# gem 'activerecord', '4.0.12'
gem 'pg', '0.18.0.pre20141117110243'
# gem 'pg', '0.17.1'
require 'active_record'
require 'minitest/autorun'
require 'logger'
@larskanis
larskanis / pg_log_unable_to_send.rb
Last active June 20, 2022 13:36
Monkey patch PG::Connection to get more a descriptive error message
require 'pg'
class PG::Connection
def self.wrap_send_method(meth)
alias_method "#{meth}_wo_wrap", meth
define_method(meth) do |*args|
begin
send("#{meth}_wo_wrap", *args)
rescue PG::UnableToSend => e
@larskanis
larskanis / pg.rb
Last active January 19, 2017 19:43
#!/usr/bin/env ruby
begin
require 'pg_ext'
rescue LoadError
# If it's a Windows binary gem, try the <major>.<minor> subdirectory
if RUBY_PLATFORM =~/(mswin|mingw)/i
major_minor = RUBY_VERSION[ /^(\d+\.\d+)/ ] or
raise "Oops, can't extract the major/minor version from #{RUBY_VERSION.dump}"