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 / 01_terminal.md
Last active August 29, 2015 14:05
Hello, Ruby!

ターミナル入門

ディレクトリ構造

# ルートディレクトリ
/

# ホームディレクトリ
/Users/shuhei
@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 / 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 / app.js
Last active August 29, 2015 14:07
AngularJS: Sync service's data with controller
'use strict';
angular.module('sync', [])
.controller('HomeController', function(Model, sync) {
this.toggleName = function() {
Model.toggleName();
};
sync(Model, 'getName', this, 'name');
sync(Model, 'theOther', this, 'other');
@shuhei
shuhei / gist:b31c3a080127640082e4
Created October 31, 2014 03:47
rubocop with Syntastic
#!/bin/bash
~/.rbenv/versions/2.1.2/bin/rubocop $@
@shuhei
shuhei / index.html
Created November 11, 2014 08:39
画面上下にくっついたヘッダとフッタの間をぴったり埋めるスクロールエリア
<!DOCTYPE html>
<html>
<head>
<style>
div {
position: absolute;
width: 200px;
}
#wrapper {
background-color: #f00;
@shuhei
shuhei / how-protractor-works.md
Last active August 29, 2015 14:11
How protoractor works
  • The methods like element(), element.all() and element().fisrt() return element finders instead of elements. At this time, element finding is not performed yet. So the element finders are reusable even when the page state changes.
  • The action methods like element().click(), element().getText() and element.count() return promises. At this time, element finding and action are not performed yet. They register actions to a queue in order.
  • The actions in the queue are executed one by one. When executed, element finding and the action are performed. Between actions, protractor waits for Angular to finish $digest loop and $http requests.
@shuhei
shuhei / README.md
Last active August 29, 2015 14:11
possible bug of watchify
npm install
npm start

and save a.js.

Files are bundled twice.

This is because a.js is watched twice as a relative path and an absoulete path. The former comes from 'file' event of browserify that comes from module-deps' 'file' event. The latter comes from 'dep' event of browserify. If we use absolute paths for browserify, this problem doesn't happen. But why does watchify check 'file' and 'dep'?

@shuhei
shuhei / after.js
Last active August 29, 2015 14:13
AngularJS: Bind injected arguments to instance
// @ngInject
class AwesomeController {
constructor(a, b, c, d, e, f, g, h) {
bindArguments(this, arguments);
}
foo() {
this.a.doSomething();
this.b.doAnotherThing();
// ...
@shuhei
shuhei / public_api.rb
Created February 18, 2015 05:08
Configuration builder with meta programming
module Api
class PublicApi
PANEL_KEYS = [
:priority,
:template_type,
:title,
link: [
:id,
:title,
:url,