Skip to content

Instantly share code, notes, and snippets.

View Kimtaro's full-sized avatar

Kim Ahlström Kimtaro

View GitHub Profile
@Kimtaro
Kimtaro / phones.rb
Created February 5, 2009 01:54 — forked from mattt/phones.rb
# 'r' after open-mid central unrounded?
module Keats
module Phones
IPA_CONSONANTS = {
"B" => "b", # b - Lower-case B <be> voiced bilabial plosive
"CH" => "t\312\203", # tʃ - T-Esh ligature <cheese> voiceless postalveolar affricate
"D" => "d", # d - Lower-case D <dee> voiced dental or alveolar plosive
"DH" => "\303\260", # ð - Eth <thee> voiced dental fricative
"F" => "f", # f - Lower-case F <fee> voiceless labiodental fricative
require 'test/unit'
require 'test/unit/ui/console/testrunner'
module Kaku
FULLWIDTH_ROMAJI = '!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ '
HALFWIDTH_ROMAJI = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ '
def fullwidth_to_halfwidth(text)
text.gsub(/\xEF[\xBC\xBD]./) do |m|
m[1] == 188 ?
#!/usr/bin/env ruby
# TextMate command for very simple pretty-printing of SQL
print $stdin.readlines.join("\n").gsub(/
(
SELECT (\s+ DISTINCT)? |
FROM |
(LEFT (\s+ OUTER)? | INNER)? \s* JOIN |
UNION |
WHERE |
# Run like so: perl api_functional.pl api.smart.fm YOUR_API_KEY
use strict;
use warnings;
use utf8;
use Test::More qw(no_plan);
use LWP::UserAgent;
use JSON;
use XML::Simple;
use Data::Dumper;
# -*- encoding: utf-8 -*-
require 'benchmark'
require 'rubygems'
require 'active_support'
require 'oniguruma'
include Oniguruma
SKIP_INVALID_UTF8 = Iconv.new('UTF-8//IGNORE', 'UTF-8')
SIZE_R = ORegexp.new('.', '', 'utf8')
use strict;
use warnings;
use utf8;
use LWP::UserAgent;
use JSON;
use XML::Simple;
use Data::Dumper;
use Time::HiRes qw(gettimeofday tv_interval);
use URI::Escape qw(uri_escape_utf8);
# ========================
# = 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>