Skip to content

Instantly share code, notes, and snippets.

View Kimtaro's full-sized avatar

Kim Ahlström Kimtaro

View GitHub Profile
1: 日
2: 一
3: 国
4: 会
5: 人
6: 年
7: 大
8: 十
9: 二
10: 本
@Kimtaro
Kimtaro / [TextMate] Split Windows.scpt
Created March 9, 2016 09:25
Split windows in TextMate
set dock_position to do shell script "defaults read com.apple.dock orientation"
tell application "System Events" to tell process "Dock"
set dock_dimensions to size in list 1
set dock_width to item 1 of dock_dimensions
set dock_height to item 2 of dock_dimensions
end tell
tell application "Finder"
set the_bounds to bounds of window of desktop
@Kimtaro
Kimtaro / gist:ab137870ad4a385b2d79
Created December 26, 2014 12:06
Add to mecab dictionary
# Put new words in a CSV with this format
# 表層形,左文脈ID,右文脈ID,コスト,品詞,品詞細分類1,品詞細分類2,品詞細分類3,活用形,活用型,原形,読み,発音
# surface_form,left_context_id,right_context_id,cost,part_of_speech,pos_division_1,pos_division_2,pos_division_3,inflection_type,inflection_style,lemma,reading,pronunciation
$ echo "fasihsignal,-1,-1,100,名詞,一般,*,*,*,*,fasihsignal,ファシシグナル,ファシシグナル" > a.csv
# Then use mecab-dict-index to compile the csv into a .dic file, based on an existing mecab dictionary file
$ /usr/local/Cellar/mecab/0.996/libexec/mecab/mecab-dict-index -d/usr/local/Cellar/mecab/0.996/lib/mecab/dic/ipadic/ -u a.dic -f utf8 -t utf8 a.csv
# The use it
$ mecab -ua.dic
const HIRAGANA = "ぁあぃいぅうぇえぉおかがきぎくぐけげこごさざしじすずせぜそぞただちぢっつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむめもゃやゅゆょよらりるれろゎわゐゑをんゔゕゖ";
const KATAKANA = "ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶ";
function transliterateHiraganaToKatakana(text) {
var newText = "";
for(let character of text) {
const codepoint = character.codePointAt(0);
if(codepoint >= 12353 && codepoint <= 12438) {
#!/usr/bin/perl
## Depending on which Perl version you're running you'll get different Unicode semantics
# Perl 5.18 (OSX default) - Unicode 6.2
# Perl 5.24 (Latest, available through homebrew) - Unicode 8.0
# Perl 5.25 (Bleeding edge, available through perlbrew) - Unicode 9.0
## perlbrew allows you to easily install bleeding edge Perl:
# sudo /usr/bin/cpan App::perlbrew
# perlbrew install 5.25.9; perlbrew use 5.25.9
@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
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 / 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',
@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 / 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