Skip to content

Instantly share code, notes, and snippets.

View Kimtaro's full-sized avatar

Kim Ahlström Kimtaro

View GitHub Profile
# ========================
# = Specific to Japanese =
# ========================
if ( $c->stash->{query}->{form}->{jap} ) {
$query->{'jap.jap'} = {'like' => $c->stash->{query}->{sql}->{jap_tokens}};
my $q_jap = $c->model('DJDB')->storage->dbh->quote($jap);
$options = {
join => [qw/jap/],
order_by => qq{
@Kimtaro
Kimtaro / gist:267318
Created January 2, 2010 00:25 — forked from pat/gist:246154
# So, with some help (and perhaps some faulty testing on my part initially) here
# is a solution I'm happy with.
def sphinx_version
# STDERR redirection for Unix
stderr = $stderr.dup
read, write = IO.pipe
$stderr.reopen(write)
`indexer`[/^Sphinx (\d\.\d\.\d)/, 1]
rescue # This catches errors for Windows
module ToHTML
def self.included(base)
base.send(:include, InstanceMethods)
end
module InstanceMethods
# Recursively builds simple HTML for an arbitrary data structure
# Suited for use with data from ActiveSupport::JSON.decode
def from_json_to_html(context = '')
output = ''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- ATSUI-compatible preferred fallback -->
<dict>
<!-- default ordered fallback list - fallback entity has to be PostScript name -->
<key>default</key>
<array>
<string>LucidaGrande</string> <!-- MAKE sure this matches the kCTFontSystemFontType in CTFontDescriptorCreateForUIType() & TDescriptorSourceImp::CreateDefaultDescriptor()! -->
<string>AppleSymbolsFB</string>
$ 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',