Skip to content

Instantly share code, notes, and snippets.

@pinzolo
pinzolo / comment_should_be_of_the_term.go
Last active June 1, 2016 13:08
Goが出すドキュメントのためのコメントへの警告
package main
// 設定情報を格納する ← メッセージ出しやがる
type Config struct {}
// ConfigError は設定情報に不備があった場合のエラー情報を格納する ← 推奨しているらしい
type ConfigError struct {}
// Fooを返す ← メッセージ出しやがる
func GetFoo() string {
@pinzolo
pinzolo / get_rune_at.go
Last active May 31, 2016 04:17
Get rune from string.
package main
import (
"fmt"
)
func main() {
s := "日本語"
fmt.Println(string(s[0])) // => æ
fmt.Println(string(getRuneAt(s, 0))) // => 日
@pinzolo
pinzolo / git-version-up-to-281-from-200.sh
Last active April 6, 2016 03:02
git のバージョンアップ(Ubuntu14.04)
git --version
# git version 2.0.0
cd /opt/src
wget https://www.kernel.org/pub/software/scm/git/git-2.8.1.tar.gz
tar xf git-2.8.1.tar.gz
cd git-2.8.1
./configure --prefix=/opt/git/git-2.8.1 --with-openssl --with-curl
make
make install
/opt/git/git-2.8.1/bin/git --version
@pinzolo
pinzolo / angular-directive.js
Last active April 3, 2016 06:08
特定の距離をスクロールされるとトップで要素を固定する
(function() {
'use strict';
angular.module('app').directive('fixedOnTop', function($window) {
return {
restrict: 'A',
link: function($scope, element, attrs) {
angular.element($window).on('scroll', function() {
var baseTop = element.get(0).offsetTop;
if (angular.element(this).scrollTop() >= baseTop) {
@pinzolo
pinzolo / get_mac_space.sh
Last active March 8, 2016 07:41
容量確保のために走らせたコマンド
# parallels のログ削除
$ sudo rm /Library/Logs/parallels.*
# homebrew の不要ファイル削除
$ brew cleanup
# キャッシュの削除
$ sudo rm -dfR /System/Library/Caches/* /Library/Caches/* ~/Library/Caches/*
@pinzolo
pinzolo / user_factory.rb
Created February 2, 2016 15:15
Macで桁落ちを発生させるFactoryGirlの定義
FactoryGirl.define do
factory :user do
email 'user@example.com'
password 'newSecurePassw0rd'
confirmation_token 'xxxxxxxxxxxxxxxx'
confirmation_sent_at '2016-02-02 12:34:56.1234567'
end
end
@pinzolo
pinzolo / confirmations_controller_test.rb
Last active February 2, 2016 15:34
Devise の confirmations_controller にて期間丁度に確認した場合、Mac, Linux での挙動が異なることの検証(修正コード)
require 'test_helper'
class ConfirmationsControllerTest < ActionController::TestCase
setup do
@request.env['devise.mapping'] = Devise.mappings[:user]
end
test '登録して10日以内なら確認可' do
user = create(:user).reload
@pinzolo
pinzolo / devise_confirmable.rb
Last active February 2, 2016 15:35
Devise の confirmations_controller にて期間丁度に確認した場合、Mac, Linux での挙動が異なることの検証(デバッグコード)
module Devise
module Models
module Confirmable
# some code
protected
# some code
@pinzolo
pinzolo / confirmations_controller_test.rb
Last active February 3, 2016 01:42
Devise の confirmations_controller にて期間丁度に確認した場合、Mac, Linux での挙動が異なることの検証
require 'test_helper'
class ConfirmationsControllerTest < ActionController::TestCase
setup do
@request.env['devise.mapping'] = Devise.mappings[:user]
end
test '登録して10日以内なら確認可' do
user = create(:user)
@pinzolo
pinzolo / devise.rb
Last active January 15, 2017 14:14
Devise.setup do |config|
# 複数モデルを可能にする
config.scoped_views = true
# スコープごとのサインアウトを可能にする
# デフォルトの状態ではコメントアウトされているので、コメントアウトを外して false を設定する
config.sign_out_all_scopes = false
end