Skip to content

Instantly share code, notes, and snippets.

View Kimtaro's full-sized avatar

Kim Ahlström Kimtaro

View GitHub Profile
$ gem build oauth-plugin.gemspec
$ gem install oauth-plugin-0.4.0.pre4.gem
@Kimtaro
Kimtaro / gist:968246
Created May 12, 2011 09:33
Ruby 1.9 regex \w Unicode
# Encoding: UTF-8
#
# Problem: \w in regular expressions should match Unicode characters
# when in Unicode mode*.
# Solution: Use the corresponding Unicode properties directly.
#
# *http://www.geocities.co.jp/kosako3/oniguruma/doc/RE.txt
r = %r{ [\p{Letter}\p{Mark}\p{Number}\p{Connector_Punctuation}]+ }x
@Kimtaro
Kimtaro / gist:1437129
Created December 6, 2011 07:01
Some helpful SQL
SELECT * FROM table PROCEDURE ANALYSE(0,0)\G
-- "ANALYSE() examines the result from a query and returns an analysis of the results that suggests optimal data types for each column that may help reduce table sizes."
SELECT COUNT(DISTINCT(SUBSTR(column, 1, 22))) / COUNT(DISTINCT(column)) * 100 FROM table;
-- Figures out index coverage with the given index length (22 here).
@Kimtaro
Kimtaro / gist:1779371
Created February 9, 2012 11:18
Installing the wordnet gem on OSX, as of February 9 2012

Getting the wordnet gem, version 0.0.5, working is a little tricky at the moment. It's being rewritten but isn't released yet and the dbd gem is in a similar state.

These steps got it working for me on OS X Lion and MRI 1.8.7. On 1.9.2 convertdb.rb segfaults.

WordNet

Download WordNet from http://wordnet.princeton.edu/wordnet/download/current-version/

$ ./configure
@Kimtaro
Kimtaro / gist:2419024
Created April 19, 2012 06:07
Nifty git commands
# List all branches in order of last commit time
git for-each-ref --sort=-committerdate refs/heads/
# List all commits that changed test/test_helper.rb
git log -p --all test/test_helper.rb
@Kimtaro
Kimtaro / kanji_to_number.rb
Created June 15, 2012 13:30
Convert Kanji numerical to roman numerical
# Encoding: UTF-8
module KanjiToNumber
POS_FOR_DEN = {'十' => 1, '百' => 2, '千' => 3, '万' => 4}
NUM_FOR_NUM = {'壱' => '1', '一' => '1', '1' => '1',
'弐' => '2', '二' => '2', '2' => '2',
'参' => '3', '三' => '3', '3' => '3',
'四' => '4', '4' => '4',
'五' => '5', '5' => '5',
'六' => '6', '6' => '6',
module DelayedCallbacks
def self.included(base)
methods = base.instance_methods(false) + base.private_instance_methods(false)
[:save, :update, :create].each do |time|
if methods.include?("after_#{time}_job".to_sym)
klass = Object.const_get("GenericAfter#{time.capitalize}Worker")
performer = -> { klass.perform_async(self.id, self.class) }
base.send(:define_method, "delay_after_#{time}".to_sym, performer)
base.send("after_#{time}".to_sym, "delay_after_#{time}".to_sym)
@Kimtaro
Kimtaro / webmock.rb
Created August 22, 2013 01:19
Moneky patch to force Webmock to always puts when it disallows a request. This works around overly eager rescue statements hiding the Webmock NetConnectNotAllowedError.
# Encoding: UTF-8
module WebMock
class NetConnectNotAllowedError
def initialize_with_puts(request_signature)
begin
raise initialize_without_puts(request_signature)
rescue => e
puts "< ===== WEBMOCK WEBMOCK WEBMOCK WEBMOCK WEBMOCK ===== >", e.inspect
e
@Kimtaro
Kimtaro / keybase.md
Created February 25, 2014 01:13
keybase.md

Keybase proof

I hereby claim:

  • I am kimtaro on github.
  • I am kimtaro (https://keybase.io/kimtaro) on keybase.
  • I have a public key whose fingerprint is 6A97 1676 C83A 5C3C 0DEB 2C1A 73FF AC4F D496 2F38

To claim this, I am signing this object:

@Kimtaro
Kimtaro / .ruby-version
Last active August 29, 2015 14:04
Wlass
2.1.0