Skip to content

Instantly share code, notes, and snippets.

View fujimura's full-sized avatar

Daisuke Fujimura fujimura

View GitHub Profile
module Match
def self.define_matchers!(m)
m.constants.each {|c|
eval "class #{c} < StandardError; end"
}
end
def self.match! obj
raise self.const_get(obj.class.to_s).new(obj)
end
// @flow
import React from 'react';
const splitTimeComponent = (t: Date): number[] => {
return [
t.getFullYear(),
t.getMonth(),
t.getDate(),
t.getHours(),
t.getMinutes()
#! /bin/bash
npm --version
npm install
$(npm bin)/eslint --version
$(npm bin)/eslint --fix $(git ls-files | grep -v vendor | grep "js[x]*$") || true
git diff --exit-code && exit 0
git add .
timestamp=`date +'%Y%m%d%H%M'`
commit_comment="eslint --fix $timestamp"
git commit -m "$commit_comment"
@fujimura
fujimura / z-index.css.scss
Last active November 22, 2016 07:36
z-index.css.scss
@mixin stack-classes ($classes) {
$i: 10;
@each $class in $classes {
.#{$class} {
z-index: $i;
$i: $i + 10;
}
}
}
@fujimura
fujimura / pre-push.sh
Created November 21, 2016 05:54
pre-push hook to prevent push to master branch
#!/bin/bash
# Taken from http://thinca.hatenablog.com/entry/20150306/1425639218
while read local_ref local_sha1 remote_ref remote_sha1
do
if [[ "${remote_ref##refs/heads/}" = "master" ]]; then
echo "Do not push to master branch!!!"
exit 1
fi
done
@fujimura
fujimura / rubocop_pr.sh
Created October 3, 2016 04:53
Script to make a pull request with the result from rubocop --auto-correct
bundle exec rubocop --auto-correct $(git ls-files | grep -E -v "^(db|bin)" | grep "\.rb$") || true
git diff --exit-code && exit 0
git add .
timestamp=`date +'%Y%m%d%H%M'`
commit_comment="rubocop --auto-correct $timestamp"
git commit -m "$commit_comment"
git checkout -b rubocop-auto-correct-$timestamp
branch_name=`git name-rev --name-only HEAD`
git push -u origin $branch_name
hub pull-request -m "$commit_comment" -h proper-inc:$branch_name
Running Wild - Death or Glory
Mobb Deep - The Infamous
Basic Channel - s/t
Carnage - Dark Recollections
Buffalo Springfield - Again
Os Mutantes - s/t
Bulldoze - The Final Beatdown
Archimedes Badkar - s/t
クラムボン - まちわび まちさび
Lip Cream - s/t
@fujimura
fujimura / resize.js
Created April 14, 2016 07:24
Resize image in browser
const fileToDataUrl = (file) => {
return new Promise((resolve, reject) => {
const reader = new FileReader
reader.onload = (e) => {
resolve(e.target.result)
};
reader.readAsDataURL(file);
});
}
import System.Posix.Signals
import Control.Concurrent
main :: IO ()
main = do
m <- newEmptyMVar
installHandler sigKILL (Catch (putMVar m "Hi")) Nothing
installHandler keyboardSignal (Catch (putMVar m "Hi")) Nothing
takeMVar m >>= print
@fujimura
fujimura / sum.hs
Created May 28, 2014 09:00
Code change frequency per file
-- How to run
-- $ git log --numstat --pretty="%0" |grep -v "%0" | runhaskell sum.hs
import Control.Applicative
import Data.Map (Map)
import qualified Data.Map as Map
import System.IO
import Text.Read
import Data.List