Skip to content

Instantly share code, notes, and snippets.

View shuhei's full-sized avatar
🐢
...

Shuhei Kagawa shuhei

🐢
...
View GitHub Profile
@shuhei
shuhei / collect_middlewares.rb
Created September 1, 2014 02:57
Collect Rails middlewares
# Paste this to Rails console.
def get_inner(app, middlewares)
middlewares << app.to_s
if inner = app.instance_variable_get(:@app)
get_inner(inner, middlewares)
end
end
def collect_middlewares(app)
@shuhei
shuhei / qiita_org_ranking.rb
Last active August 29, 2015 14:05
Qiita Organization Ranking
require 'mechanize'
require 'date'
def nap
sleep(3 + rand(10) / 10)
end
def org_list_item(org, i)
"#{i + 1}. [#{org[:name]}](#{org[:link]}): #{org[:posts]} posts, #{org[:stocks]} stocks"
end
@shuhei
shuhei / 01_terminal.md
Last active August 29, 2015 14:05
Hello, Ruby!

ターミナル入門

ディレクトリ構造

# ルートディレクトリ
/

# ホームディレクトリ
/Users/shuhei
@shuhei
shuhei / transform.js
Created July 29, 2014 00:49
CSV to something
var data = [
['Prefecture', 'A', 'B', 'C'],
['Tokyo', '1', '2', '3'],
['Kanagawa', '4', '5', '6']
];
var labels = data[0];
var dataSet = data.slice(1).reduce(function(acc, row) {
var item = {};
item[labels[0]] = row[0];
@shuhei
shuhei / palette.js
Created July 24, 2014 00:59
Extract color palette of Google's Material Design. Run on http://www.google.com/design/spec/style/color.html
// Create an Array from an Array-like Object such as NodeList.
function toArray(arrayLike) {
return Array.prototype.slice.call(arrayLike);
}
// Create an Object from an Array of objects.
function toObject(objects, keyName, valueName) {
return objects.reduce(function(acc, obj) {
acc[obj[keyName]] = obj[valueName];
return acc;
@shuhei
shuhei / colike.js
Created July 2, 2014 14:55
Super simple implementation of something like co
function colike(genFunc) {
var gen = genFunc();
var thunk = gen.next().value;
function done() {
// We don't know the number of arguments.
var err = arguments[0];
var values = Array.prototype.slice.call(arguments, 1);
if (err) {
@shuhei
shuhei / gulp-error-handling.md
Last active August 29, 2015 14:02
Gulp error handling

Gulp error handling

Orchestrator ignores stream errors

gulp uses orchestrator to run tasks. orchestrator ignores error events of stream that task function returns. robrich/orchestrator#46

The author says that it is because the inconsistent implementations of gulp plugin streams. Some streams emit error event and emits end event later.

How it affects your task

EC2 Windows Instance のクローン

事前に元のインスタンスに設定が必要。 EC2Config の設定ファイルを編集する方法と、GUI から設定する方法がある。 今回は、設定ファイルで。/Program Files/Amazon/EC2Config/settings/config.xml を開く。 EC2SetPassword を Disabled -> Enabled にする。 このとき、GUI でシャットダウンせずに、普通にシャットダウンする。 GUI でやる場合は、GUI 上でパスワードの再設定するよう設定する。試してないが。

パスワードの再設定。

JS Modules

  • RequireJS
  • CommonJS
  • ES6 Modules

Why modules?

  • Divide et impera
  • Avoid global variables
@shuhei
shuhei / where.md
Created May 16, 2014 05:03
Where to put models in Angular?