Skip to content

Instantly share code, notes, and snippets.

Avatar
🍵

Shuhei Kagawa shuhei

🍵
View GitHub Profile
@shuhei
shuhei / phonetic.rb
Created Apr 17, 2011
Converts phonetic names from Japanese Kana into Roman characters in OSX Address Book. Requires rb-appscript and romankana gems. Make sure to backup your address book before running this.
View phonetic.rb
#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-
require 'romankana'
require 'appscript'
include Appscript
kana_pattern = /^[あ-んア-ヴ]+$/u
class String
@shuhei
shuhei / gist:1362207
Created Nov 13, 2011
Rock, Paper, Scissors with Arduino, tact switch and LCD Shield
View gist:1362207
#include <LiquidCrystal.h>
int buttonPin = 7;
boolean pressedBefore = false;
boolean standby = true;
// Pin numbers connected to LCD's RS, E, DB4, DB5, DB6 and DB7
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
@shuhei
shuhei / pre-commit
Created Dec 22, 2011
Pre-commit hook for RSpec
View pre-commit
#!/usr/bin/env ruby
def bash_source(file)
`bash -c "source #{file}"`
end
# Make sure to use RVM
user_rvm = "#{ENV['HOME']}/.rvm/scripts/rvm"
system_rvm = "/usr/local/rvm/scripts/rvm"
@shuhei
shuhei / bookmarklet
Last active Sep 29, 2015
Show military time instead of pretty date
View bookmarklet
javascript:(function() { function pad(num) { return ("0" + num.toString()).slice(-2); } $('time').each(function() { var $this = $(this), d = new Date($this.attr('datetime')), str = pad(d.getMonth() + 1) + "/" + pad(d.getDate()) + " " + pad(d.getHours()) + ":" + pad(d.getMinutes()); $this.text(str); }); })();
@shuhei
shuhei / gist:1523353
Created Dec 27, 2011
Get access to the Sinatra application instance that runs the current test and mock it
View gist:1523353
require 'something/to/be/required'
class Sinatra::Base
@@prepared = nil
def self.onion_core
onion = prototype
loop do
onion = onion.instance_variable_get('@app')
return onion if onion.class == self || onion.nil?
@shuhei
shuhei / _config.yml.diff
Created Apr 3, 2012
Add a category index to Octopress
View _config.yml.diff
diff --git a/_config.yml b/_config.yml
index 5c7d335..7ad03bb 100644
--- a/_config.yml
+++ b/_config.yml
@@ -45,7 +45,7 @@ titlecase: true # Converts page and post titles to titlecase
# list each of the sidebar modules you want to include, in the order you want them to appear.
# To add custom asides, create files in /source/_includes/custom/asides/ and add them to the list like 'custom/asides/custom_aside_name.html'
-default_asides: [asides/recent_posts.html, asides/github.html, asides/twitter.html, asides/delicious.html, asides/pinboard.html, asides/googleplus.html]
+default_asides: [asides/recent_posts.html, custom/asides/categories.html, asides/github.html, asides/twitter.html, asides/delicious.html, asides/pinboard.
@shuhei
shuhei / coffee_compass.watchr
Created Apr 7, 2012
Compile CoffeeScript and SCSS
View coffee_compass.watchr
watch('(.*)\.coffee') { |md| system "coffee -o js -c #{md[0]}" }
watch('sass\/(.*)\.s[ac]ss') { |md| system "compass compile #{md[0]}" }
@shuhei
shuhei / functions.php
Created Aug 24, 2012
Add 'cat' query to `wp_get_archives()`
View functions.php
//
// Example:
// $cat_ID = 12;
// wp_get_cat_archives('type=monthly', $cat_ID);
//
// Borrowed a lot from the following links.
//
// - http://wordpress.org/support/topic/wp_get_archives-and-conditional-tags
// - http://www.stemlegal.com/greenhouse/2012/setting-up-month-archives-to-only-display-custom-taxonomy-wordpress/
//
@shuhei
shuhei / gist:3631200
Created Sep 5, 2012
Periodically check file count in `foo` dir
View gist:3631200
while [ true ]; do ls -1 foo | wc -l; sleep 1; done
@shuhei
shuhei / jquery.headbutt.js
Created Oct 26, 2012
Make elements follow the scroll when they head-butt the top of the window
View jquery.headbutt.js
$.fn.headbutt = function (offset) {
if (offset == null) {
offset = 0;
}
this.each(function () {
var $elem = $(this)
, initialTop = $elem.offset().top
, initialPosition = $elem.css('position')
;
$window = $(window).on('scroll', function () {
You can’t perform that action at this time.