Skip to content

Instantly share code, notes, and snippets.

#
# Ubuntu 20.04 requires at least `gcc-mingw-w64-x86-64` package as a
# cross compiler.
#
MRuby::CrossBuild.new("cross-mingw") do |conf|
conf.toolchain :gcc
conf.host_target = "x86_64-w64-mingw32"
conf.cc.command = "#{conf.host_target}-gcc-posix"
conf.linker.command = conf.cc.command

An iv_tbl is not shared when a class includes or prepends an empty module

Example

If a class includes or prepends an anonymous and empty module and then a constant or class variable is added to the module, they cannot be referenced from the class.

m = Module.new
#M = m = Module.new
C = Class.new{include m}
@shuujii
shuujii / hash-rehash-does-not-reindex-completely.md
Last active November 13, 2020 05:03
mruby Hash bugs (everything has been fixed in mruby master)

Hash#rehash does not reindex completely

Example

def new_modified_key_hash
  k = [:a]
  h = {k=>1, [:b]=>2}
  k[0] = :b
 h #=> {[:b]=>1, [:b]=>2}
diff --git a/bin/diff-highlight b/bin/diff-highlight
index c4404d4..b568c9f 100755
--- a/bin/diff-highlight
+++ b/bin/diff-highlight
@@ -2,6 +2,7 @@
use warnings FATAL => 'all';
use strict;
+use Encode qw(decode_utf8 encode_utf8);
@shuujii
shuujii / chrome-ext-ctrl
Created July 5, 2013 04:12
Chrome extension control command on Mac
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'optparse'
EXTENSION_URL = '"chrome://extensions-frame/"'
options = {enablements: []}
optparser = OptionParser.new(nil, 17, " ") do |o|
o.banner = "Usage: #{File.basename $0} [OPTIONS] EXTENSION-NAME"
@shuujii
shuujii / mac-suspend
Created July 26, 2012 00:30
Deep sleep and restore default hibernatemode on Mac
#!/bin/bash
PLIST=~/Library/LaunchAgents/my.resume.plist
RESUME=$(cd $(dirname $0); pwd)/mac-resume
machine_suspend() {
cat <<EOF > $PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@shuujii
shuujii / fix-limited-ime-input-crash-for-inline-patch.patch
Created May 3, 2012 05:54
Limited fix crash ime inptting in Cocoa Emacs 23.4 on Mac + emacs-inline-patch
--- a/src/nsterm.m 2012-04-22 20:31:20.000000000 +0900
+++ b/src/nsterm.m 2012-05-03 13:57:40.000000000 +0900
@@ -284,6 +284,8 @@
int x_use_underline_position_properties, x_underline_at_descent_line;
/* FIXME: figure out what to do with underline_minimum_offset. */
+EXFUN (Fbuffer_local_value, 2);
+EXFUN (Fcurrent_buffer, 0);
/* ==========================================================================
@shuujii
shuujii / gist:2582702
Created May 3, 2012 02:59
Install Cocoa Emacs 23.4 on Mac (Lion)
@shuujii
shuujii / .pryrc
Created April 30, 2012 12:49
Scrollable output via less in Pry
module Kernel
def less(obj)
s = obj.kind_of?(String) ? obj :
defined?(AwesomePrint) ? obj.ai :
defined?(PrettyPrint) ? obj.pretty_inspect :
obj.inspect
Pry::Helpers::BaseHelpers.lesspipe(s, always: true, wrap: true)
end
end
@shuujii
shuujii / sqlite3_adapter_with_foreign_key.rb
Created April 30, 2012 06:39
ActiveRecord SQLite3 adapter with foreign key
module ActiveRecord
class Base
class << self
def sqlite3_connection_with_foreign_key(config)
sqlite3_connection_without_foreign_key(config).tap do |db|
db.execute("PRAGMA foreign_keys = ON") if config[:foreign_key]
end
end
alias_method_chain :sqlite3_connection, :foreign_key
end