Skip to content

Instantly share code, notes, and snippets.

View takumifukasawa's full-sized avatar

takumifukasawa takumifukasawa

View GitHub Profile
@takumifukasawa
takumifukasawa / camelcase.js
Last active September 14, 2020 15:04
javascript: kebab case to camel case
export default (str) => str.split("-").map((text, i) => i === 0 ? text : text.substr(0, 1).toUpperCase() + text.substr(1)).join("");
@takumifukasawa
takumifukasawa / webpack-eslnt-loader-config-files.js
Last active August 8, 2020 03:39
example of specifing eslintrc and eslintignore file in webpack eslint-loader.
module.exports = {
module: {
rules: [{
test: /\.ts?$/,
exclude: [/node_modules/],
enforce: "pre",
use: {
loader: "eslint-loader",
options: {
fix: true,
@takumifukasawa
takumifukasawa / youtubeLiveConcurrentViewers.js
Created July 25, 2020 12:23
check youtube live concurrent viewers
const VIDEO_ID = "video_id";
const API_KEY = "your_api_key";
async function getVideoData() {
const url = `https://www.googleapis.com/youtube/v3/videos?part=liveStreamingDetails&id=${VIDEO_ID}&key=${API_KEY}`;
try {
const response = await fetch(url, {
method: 'GET',
});
const result = await response.json();
@takumifukasawa
takumifukasawa / webworker-blob.js
Last active June 25, 2020 12:34
WebWorker worked on Blob
const workerCode = `
onmessage = function(e) {
console.log('worker thread: onmessage');
console.log(e)
}
`;
const workerScript = URL.createObjectURL(
new window.Blob([workerCode], { type: "application/javascript" })
);
@takumifukasawa
takumifukasawa / createAnimatedSprite.js
Last active June 15, 2020 05:42
ES6: create PIXI.js animated sprite
import { map } from "lodash"
export default ({ frames, container }) => {
const sprite = new PIXI.AnimatedSprite(
map(frames, frame => {
const texture = PIXI.Texture.from(frame)
return texture
})
)
@takumifukasawa
takumifukasawa / parallelTweens.js
Created June 10, 2020 11:01
ES6: manually run GSAP tweens in parallel
/*
* # usage
* const tweenSequence = thisFunc([tween1, tween2, ... more tweens]);
* tweenSquence.update(time);
*/
import { forEach, every } from "lodash"
export default (...tweens) => {
return {
@takumifukasawa
takumifukasawa / randomPickFromCache.js
Created June 10, 2020 10:57
ES6: Prepare the cache so that the same elements are not extracted
/*
* # usage
* const pool = randomSampleInCache(array, 5);
* const elem = pool.pick();
*
* TODO: clamp cacheNum in [0 ... list.length]
*/
import { difference, sample, range } from "lodash"
@takumifukasawa
takumifukasawa / webFontLoader.js
Created June 10, 2020 10:49
ES6: custom webfont loader promise
// families: array
// urls: array
export async function customWebFontLoader({ families, urls }) {
return new Promise((resolve, reject) => {
WebFont.load({
custom: {
families,
urls,
},
active: () => {
@takumifukasawa
takumifukasawa / easingFunctions.js
Created June 10, 2020 10:17
ES6: exports for eacheach easing functions
/*
* original is skylerspark's easing functions.
* ref: https://gist.github.com/gre/1650294#gistcomment-3141432
*/
// no easing, no acceleration
export const linear = t => {
return t
}
// accelerating from zero velocity
@takumifukasawa
takumifukasawa / timeline.js
Created June 10, 2020 10:13
経過時間ごとに関数を発火させるタイムライン関数
// # arg
// sequence: array
// [
// { time: number, exec: function },
// { time: number, exec: function },
// ...
// ]
//
// # usage
// const sampleTimeline = timeline(sequence);