This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatNumber(number, decimalLength) { | |
// 小数をdecimalLengthで切り捨てて、数値をカンマ区切りにする | |
decimalLength = decimalLength || 0; | |
var str = number.toString().split("."); | |
var base = str[0].replace(/(?!^)(?=(\d{3})+$)/g,","); | |
var decimal = (str[1]) ? str[1].slice(0, decimalLength) : Array(decimalLength + 1).join("0"); | |
var result = (!decimalLength) ? base : base + "." + decimal; | |
return result; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setInputWatcher($target, interval, execFn){ | |
var timer; | |
$target.on("focus", onFocusFn); | |
$target.on("blur", onBlurFn); | |
function onFocusFn(){ | |
clearInterval(timer); | |
var prevVal = $target.val(); | |
timer = setInterval(function(){ | |
var newVal = $target.val(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import $ from 'jquery'; | |
const $win = $(window); | |
// prefix: | |
window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || window.oRequestAnimationFrame || function(callback){ var id = window.setTimeout(callback,1000/60); return id; }; | |
window.cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.msCancelAnimationFrame || window.oCancelAnimationFrame || function(id){ window.clearTimeout(id); }; | |
const Util = { | |
TRANSITIONEND: "transitionend webkitTransitionEnd mozTransitionEnd msTransitionEnd oTransitionEnd", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const toObj = (array) => { | |
// ex. ['str'] -> { str: 'str' } | |
const obj = {}; | |
array.forEach(v => obj[v] = v); | |
return obj; | |
}; | |
export default toObj([ | |
// SAMPLE | |
'SAMPLE_MUTATION_INCREMENT', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Time.now.strftime('%Y%m%d_%H%M%S') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ROOT_PATH=`cd "$(dirname $0)/../" && pwd` | |
pid=`cat $ROOT_PATH/tmp/pids/puma.pid` | |
kill $pid && echo "killed $pid" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
bundle exec sidekiq -C config/sidekiq.yml -L log/sidekiq.log -P tmp/pids/sidekiq.pid -d -c 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ROOT_PATH=`cd "$(dirname $0)/../" && pwd` | |
pid=`cat $ROOT_PATH/tmp/pids/sidekiq.pid` | |
kill $pid && echo "killed $pid" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GET | |
fetch('https://example.com/api/count.json', {method: 'GET', mode: 'cors'}).then(d => d.json()).then(console.log).catch(console.error) | |
// POST | |
const headers = new Headers() | |
headers.append('Content-Type', 'application/json') | |
const body = JSON.stringify({ hoge: 'fuga' }) | |
fetch('https://example.com/api/count.json', {method: 'POST', mode: 'cors', credentials: 'include', body, headers}).then(d => d.json()).then(console.log).catch(console.error) |
OlderNewer