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 / build_libcurl_ios.sh
Created November 1, 2012 05:37
Build libcurl for iOS 6.0. Modified Bob's script on Stackoverflow for iOS 6.0.
#!/bin/sh
export SDK=6.0
buildit()
{
target=$1
platform=$2
export CC=/Applications/Xcode.app/Contents/Developer/Platforms/${platform}.platform/Developer/usr/bin/gcc
export CFLAGS="-arch ${target} -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/${platform}.platform/Developer/SDKs/${platform}${SDK}.sdk"
@shuhei
shuhei / camelcase.js
Created December 2, 2012 04:51
Hyphenated lower case to camel case
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.substring(1);
}
function toCamelCase(hyphenated, isLower) {
var components = hyphenated.split('-');
for (var i = 0; i < components.length; i++) {
if (!(isLower && i === 0)) {
components[i] = capitalize(components[i]);
}
}
@shuhei
shuhei / httpProxy.js
Created December 9, 2012 10:06
Super simple HTTP proxy with Node.js
var http = require('http');
var red = '\u001b[31m';
var reset = '\u001b[0m';
var proxyServer = function (request, response) {
var components = request.headers['host'].split(':');
var options = {
hostname: components[0],
port: parseInt(components[1] || 80),
@shuhei
shuhei / client_server.js
Last active December 10, 2015 23:19
Node.js の http で OutgoingMessage がどういうタイミングで送られるかの検証です。
var http = require('http');
var logger = require('./logger');
var PORT = 1337;
//
// Methods of task execution
//
function takeItEasy(duration) {
return function () {
var callee = arguments.callee;
@shuhei
shuhei / growlnotify.rb
Last active December 18, 2015 15:09 — forked from ttscoff/growlnotify.rb
Seamless drop-in to turn existing growlnotify calls into Mountain Lion Notifications. Forked from https://gist.github.com/ttscoff/3225914, now read message from STDIN if -m is not provided and use the first argument as title if -t is not provided.
#!/usr/bin/env ruby
# encoding: utf-8
# == Synopsis
# Requires the terminal-notifier gem ([sudo] gem install terminal-notifier)
# growlnotify wrapper to turn Growl alerts into Mountain Lion notifications
# Uses growlnotify option syntax to keep your old scripts working with the new shiny.
#
# If you use Growl via growlnotify in your shell scripting, this script
# will replace Growl's alerts with Mountain Lion notifications.
@shuhei
shuhei / hash18to19.sh
Created July 5, 2013 06:18
Replace Ruby 1.8 style hashes with 1.9 style on Mac.
find . \( -name '*.haml' -o -name '*.rb' \) -exec sed -i '' "s/ :\([^ ']*\) => / \1: /g" {} \;
@shuhei
shuhei / association_inconsistency.rb
Last active December 20, 2015 01:39
Inconsistency of ActiveRecord Association. Need to reload before `exists?` but not for `size`.
@foo = @parent.foos.build(name: 'Foo')
@foo.bars.build(greeting: 'hello')
@foo.save
@foo.bars.exists? # -> nil
@foo.bars.size > 0 #-> true
module DestroyableReadonly
extend ActiveSupport::Concern
included do
before_update :raise_readonly
end
private
def raise_readonly
@shuhei
shuhei / remaining.user.js
Last active December 20, 2015 08:49
Show remaining hours for each team member on Kanban page of Redmine Backlogs plugin. Works as a Chrome user script.
(function () {
if (location.href.indexOf('taskboards') === -1) return;
showResult(accumulateHours());
hookTaskRefreshed();
function hookTaskRefreshed() {
window.addEventListener('message', function (e) {
if (e.data.type === 'task:refreshed') showResult(accumulateHours());
});
@shuhei
shuhei / sort_non_ascii_strings.js
Created July 30, 2013 01:57
An example that shows Array.prototype.sort sorts strings in unicode order.
var sorted = ["山田", "佐藤", "鈴木", "石田"].sort().map(function (name) {
var code = name.split('').map(function (letter) {
return letter.charCodeAt(0);
}).join(' ');
return name + ' -> ' + code;
});
console.log(sorted);