Skip to content

Instantly share code, notes, and snippets.


Takuto Wada twada

View GitHub Profile
View wikipedia_ja.rb
# -*- coding: utf-8 -*-
# Find japanese entry for each link in TARGET_URL (quick & dirty hack)
# USAGE: ruby wikipedia_ja.rb TARGET_URL
require 'rubygems'
require 'nokogiri'
require 'open-uri'
def ja_url_for(url)
link_ja = Nokogiri::HTML(open(url)).css('li.interlanguage-link.interwiki-ja a').first
twada / empower.js
Created Mar 30, 2014
empower.js that throws new AssertionError, not throwing (coping with browserify-ed code under PhantomJS)
View empower.js
* empower.js - Power Assert feature enhancer for assert function/object.
* Copyright (c) 2013-2014 Takuto Wada
* Licensed under the MIT license.
* A part of extend function is:
twada / empowerZombieBrowser.js
Last active Aug 29, 2015
zombie.js の browser.assert を power-assert 化する試み(試してはいない)
View empowerZombieBrowser.js
var empower = require('empower');
var formatter = require('power-assert-formatter');
module.exports = function empowerZombie (browser) {
empower(browser.assert, formatter(), {
destructive: true,
modifyMessageOnRethrow: true,
saveContextOnRethrow: true,
patterns: [
twada /
Last active Aug 29, 2015
power-assert 多段 SourceMap 対応の方針

power-assert 多段 SourceMap 対応の方針

試験は twada/battlefield-sourcemaps で行っている

power-assert 出力行の補正

  • SourceMap 対応が入った espower 0.9.0 を使う
  • espower(ast, options) の第二引数 options に sourceMap というキーで上流の SourceMap オブジェクトを入れる
View gist:10564
# usage: ruby this_script.rb | git am --3way
require 'net/imap'
require 'rubygems'
require 'activesupport'
id = ''
pass = ''
View gist:30410
;;;;;;;;;; functions
(defun funcall-replace-region (start end func)
"replace region with funcall result. region content(between start/end) is passed to func as string"
(let ((orig (buffer-substring start end)))
(narrow-to-region start end)
(delete-region start end)
(insert-string (funcall func orig))))))
View gist:37864
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'amazon/aws/search'
require 'erb'
hatena_template = <<-EOT
*** <%= book.item_attributes.title %>
ASIN:<%= book.asin %>:detail
View gist:65020
# -*- coding: utf-8 -*-
require 'net/telnet'
module Filetter
class MozRepl
telnet ="Port" => 4242) {|c| print c}
View gist:186565
require 'yaml'
require 'active_record'
class ActiveRecord::Migrator
class << self
TARGET_METHODS = %w[up down]
TARGET_METHODS.each do |name|
define_method("#{name}_with_database_dump") do |*args|
View js18_reduce_for_prototype.js
* (c) 2009 Takuto Wada; MIT License
* JavaScript 1.8 compliant Array#reduce that also works with old prototype.js
* usage: load this AFTER prototype.js
(function () {
// prototype.js's Array#reduce is removed since 1.6.1_rc2
// see:
if (typeof Prototype !== 'undefined' && /^1\.(?:[0-5]\.\S+|6\.(?:0(?:\.\d)?|1_rc1))$/.test(Prototype.Version)) {