Skip to content

Instantly share code, notes, and snippets.

View nyawach's full-sized avatar
🍜
一双

himeno-yusuke nyawach

🍜
一双
View GitHub Profile
@nyawach
nyawach / setupFixedBg.js
Created July 23, 2017 03:00
背景固定(RAF/onScroll両方)
function setupFixedBg() {
const $fixed = $('.js-fixed-bg');
const $wrapper = isSP() ? $(window) : $('.wrapper');
let _tmpTop = $wrapper.scrollTop();
(function _update() {
const top = $wrapper.scrollTop();
if(top !== _tmpTop) {
$fixed.css('transform', `translateY(${top}px)`);
}
_tmpTop = top;
@nyawach
nyawach / getRandomString.js
Created April 18, 2017 09:46
[a-zA-Z0-9]のランダムな文字列を出力する
getRandomString(length = 8) {
// 生成する文字列に含める文字セット
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
let r = "";
for(let i = 0, charsLength = chars.length; i < charsLength; i++){
r += chars[Math.floor(Math.random()*cl)];
}
return r;
}
@nyawach
nyawach / getRandomFlattenNum.js
Created April 14, 2017 07:23
divideで割り切れる[min, max]のランダムな数を取得
function getRandomFlattenNum(min, max, divide) {
let n = Math.random() * (max - min) + min;
n = flattenNum(n, divide);
return n;
}
function flattenNum(n, d) {
return n = n - (n % d);
}
@nyawach
nyawach / _condensed.sass
Created April 12, 2017 00:57
長体フォント用mixin
// letter-spacingは span + span にmargin-leftを指定することでいい感じにできる
=condensed($size, $scale: 0.7)
display: flex
overflow: visible
font-size: #{$size}px
& > span
display: flex
justify-content: center
align-items: center
transform: scaleX($scale)
@nyawach
nyawach / ashura.js
Created January 26, 2017 05:27
阿修羅がフェードインしてくるだけのブックマークレット
javascript:var img=new Image(); img.src="https://images-na.ssl-images-amazon.com/images/I/41kEvP4RfXL._SX342_.jpg"; img.style.position="absolute"; img.style.opacity=0.01; img.style.bottom=0; img.style.right=0; var op = 0; var val = 0.01; img.onload = function() { var tid = setInterval(function(){ img.style.opacity = op; op += val; if(img.style.opacity >= 0.5) clearInterval(tid); }, 80); document.body.appendChild(img); }
@nyawach
nyawach / factorial.js
Created January 13, 2017 11:27
階乗
function factrical(n) {
if(typeof n !== "number") return "Not Number";
return n === 1 ? 1 : n * factrical(n-1);
}
@nyawach
nyawach / wp_setup_dev.sh
Last active February 8, 2018 04:53
WordPress開発環境作るコマンド
#!/bin/sh
# 設定 ############
# DB構築に必要な設定
DB_NAME=""
DB_USER="root"
DB_PASS=""
DB_HOST="127.0.0.1"
DB_PREFIX="wp_"
@nyawach
nyawach / openNewShareWindow.js
Created November 1, 2016 06:23
シェアボタン表示する時に別窓で開かせるやつ
window.open(this.getAttribute('href'),'','width='+600+',height='+450+',left='+(window.screenX+(window.innerWidth-600)/2|0)+',top='+(window.screenY+(window.innerHeight-450)/2|0)); return false;
@nyawach
nyawach / fisher_yates.js
Last active April 12, 2018 06:14
Fisher-Yates法
// http://qiita.com/nyawach/items/108c8e2551c26674f57b
function combination(n, m) {
var list = [];
m = (m == null) ? n : m;
for(var i=n-1; i--;) list.push(i);
for(var i=list.length,j;--i;){
j = Math.random()*(i+1) | 0;
@nyawach
nyawach / combination.js
Created June 24, 2016 02:46
[0, n)の数字からm個の値を抽出
function combination(n, m) {
var arr = [];
var num;
var i = 0;
while(i < m) {
num = Math.floor(Math.random() * n);
if(~arr.indexOf(num)) continue;
arr.push(num);
i++;
}