Skip to content

Instantly share code, notes, and snippets.

@shuuuuun
shuuuuun / 0_reuse_code.js
Created December 18, 2015 00:25
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@shuuuuun
shuuuuun / formatNumber.js
Last active February 11, 2016 03:39
小数をdecimalLengthで切り捨てor四捨五入して、数値をカンマ区切りにするformatNumber関数
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;
}
@shuuuuun
shuuuuun / setInputWatcher.jquery.js
Last active January 14, 2016 13:03
inputを監視するやつ。 demo: http://jsdo.it/shuuuuun/oLhy
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();
@shuuuuun
shuuuuun / Util.js
Created August 19, 2017 03:34
よく使ってたUtil.jsのめも(最近使ってない)
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",
const toObj = (array) => {
// ex. ['str'] -> { str: 'str' }
const obj = {};
array.forEach(v => obj[v] = v);
return obj;
};
export default toObj([
// SAMPLE
'SAMPLE_MUTATION_INCREMENT',
Time.now.strftime('%Y%m%d_%H%M%S')
@shuuuuun
shuuuuun / puma-kill
Last active December 8, 2021 15:41
[pumactl.sh]
#!/bin/bash
ROOT_PATH=`cd "$(dirname $0)/../" && pwd`
pid=`cat $ROOT_PATH/tmp/pids/puma.pid`
kill $pid && echo "killed $pid"
#!/bin/bash
bundle exec sidekiq -C config/sidekiq.yml -L log/sidekiq.log -P tmp/pids/sidekiq.pid -d -c 10
#!/bin/bash
ROOT_PATH=`cd "$(dirname $0)/../" && pwd`
pid=`cat $ROOT_PATH/tmp/pids/sidekiq.pid`
kill $pid && echo "killed $pid"
@shuuuuun
shuuuuun / fetch-memo.js
Last active September 7, 2022 13:37
corsとか確認する用
// 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)