Skip to content

Instantly share code, notes, and snippets.

View shuhei's full-sized avatar
🐶
This is fine

Shuhei Kagawa shuhei

🐶
This is fine
View GitHub Profile
@shuhei
shuhei / phonetic.rb
Created April 17, 2011 02:02
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.
#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-
require 'romankana'
require 'appscript'
include Appscript
kana_pattern = /^[あ-んア-ヴ]+$/u
class String
@shuhei
shuhei / gist:1362207
Created November 13, 2011 15:13
Rock, Paper, Scissors with Arduino, tact switch and LCD Shield
#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 December 22, 2011 05:20
Pre-commit hook for RSpec
#!/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 September 29, 2015 00:37
Show military time instead of pretty date
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 December 27, 2011 11:25
Get access to the Sinatra application instance that runs the current test and mock it
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 April 3, 2012 00:12
Add a category index to Octopress
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 April 7, 2012 04:29
Compile CoffeeScript and SCSS
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 August 24, 2012 10:05
Add 'cat' query to `wp_get_archives()`
//
// 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 September 5, 2012 05:45
Periodically check file count in `foo` dir
while [ true ]; do ls -1 foo | wc -l; sleep 1; done
@shuhei
shuhei / jquery.headbutt.js
Created October 26, 2012 07:50
Make elements follow the scroll when they head-butt the top of the window
$.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 () {