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 / 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 / create-patch-branch.sh
Last active August 29, 2015 14:17
Create a patch branch from a branch that is so messed up that you cannot rebase/squash.
git checkout -b working $PARENT_COMMIT_OF_YOUR_FEATURE_BRANCH
git diff working your-feature-branch | git apply
git add .
git commit
git branch -M your-feature-branch your-feature-branch-org
git branch -M working your-feature-branch
git push --force origin your-feature-branch
@shuhei
shuhei / change_column_null.md
Created March 18, 2015 00:30
change_column_null

You can set not null constraint with change_column_null. You can also set default value, which is not SQL one.

@shuhei
shuhei / 1_before.js
Last active August 29, 2015 14:17
Angular 2 annotation with babel (babel --experimental with experimental branch)
import {Component as _Component, Template as _Template} from 'angular2/src/core/annotations/annotations';
function makeDecorator(annotationClass) {
return (options) => {
return (klass) => {
klass.annotations = klass.annotations || [];
klass.annotations.push(new annotationClass(options));
return klass;
};
};
@shuhei
shuhei / 1_before.js
Created March 26, 2015 16:21
Angular 2 type annotation with babel (babel --experimental with experimental branch)
class HelloComponent {
constructor(foo: Foo, bar: Bar) { }
}
@shuhei
shuhei / README.md
Last active August 29, 2015 14:17
Requiring 'active_support/dependencies' changes how constant is resolved

Requiring 'active_support/dependencies' changes how constant is resolved

Without 'active_support/dependencies'

$ ruby constant_resolution.rb
inner - Hello
[Outer::Inner, Outer]
constant_resolution.rb:14:in `const_missing': uninitialized constant Outer::Inner::Hello (NameError)
	from constant_resolution.rb:19:in `'
@shuhei
shuhei / app.js
Created April 13, 2015 16:41
Browserify + Angular: separate vendor and app js
var angular = require('angular');
angular.module('myapp', [])
.controller('AppController', function ($scope) {
$scope.name = 'Browserify Angular App';
});
@shuhei
shuhei / seven_seg.go
Last active August 29, 2015 14:22
7 segment LED
package main
import (
"github.com/stianeikeland/go-rpio"
"log"
"time"
)
func main() {
// TODO: Fix IO pins. Convert physical to gpio num.
@shuhei
shuhei / wiretap.js
Created July 30, 2015 12:58
Wiretap TCP connection
var net = require('net');
var stream = require('stream');
var util = require('util');
// ANSI colors.
var green = '\u001b[32m';
var yellow = '\u001b[33m';
var reset = '\u001b[0m';
// CLI args.
@shuhei
shuhei / input-ie.md
Last active August 29, 2015 14:27
Directly manipulate input value and notify it to Angular