Skip to content

Instantly share code, notes, and snippets.

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

Shuhei Kagawa shuhei

🐢
...
View GitHub Profile
@shuhei
shuhei / README.md
Last active August 29, 2015 14:16
String assignment to date attribute taking account of timezone

Sometimes we want to handle date as Date in JavaScript and JavaScript's JSON.parse converts Date to an string in UTC ISO 8601 format.

JSON.stringify({ date: new Date(2015, 2, 14) })
// "{"date":"2015-03-13T15:00:00.000Z"}"

ActiveRecord's date attribute doesn't take timezone into account when it converts string to date.

@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,
@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 / 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 / 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 / index.html
Created November 11, 2014 08:39
画面上下にくっついたヘッダとフッタの間をぴったり埋めるスクロールエリア
<!DOCTYPE html>
<html>
<head>
<style>
div {
position: absolute;
width: 200px;
}
#wrapper {
background-color: #f00;
@shuhei
shuhei / gist:b31c3a080127640082e4
Created October 31, 2014 03:47
rubocop with Syntastic
#!/bin/bash
~/.rbenv/versions/2.1.2/bin/rubocop $@
@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 / .gitattributes
Last active April 8, 2017 10:55
git diff pptx
*.pptx diff=pptx
@shuhei
shuhei / angular.md
Last active June 8, 2016 01:42
Angular Resouces