Skip to content

Instantly share code, notes, and snippets.

View daniellizik's full-sized avatar

Daniel Lizik daniellizik

  • Tablecheck
  • Tokyo, JP
View GitHub Profile
@daniellizik
daniellizik / machine.js
Created September 7, 2022 04:15
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'payments',
initial: 'init',
context: {
retries: 0
},
states: {
init: {
const lib = {
findUser: () => new Promise((resolve, reject) => {
setTimeout(() => {
resolve({name: 'ricky', content: 'z-z'})
}, 1)
}),
getUsers: (users = []) => new Promise((resolve, reject) => {
setTimeout(() => {
resolve([
...users,
@daniellizik
daniellizik / textcontent.js
Created July 13, 2017 15:32
.textContent but with parse5
import { parseFragment } from 'parse5'
const walk = (node = {}) => {
return (node.value || '') + (node.childNodes || []).reduce((child) => {
return walk(child)
})
}
export default (htmlStr) => [parseFragment(htmlStr)].reduce(walk)
@daniellizik
daniellizik / palindrome.js
Created June 29, 2017 13:38
js functional palindrome
const pal = (s) => s
.split('')
.reduce((acc, c, head, arr) => Object.assign({}, acc, {
tail: acc.tail - 1,
result: (acc.result === false || arr[head] !== arr[acc.tail]) ? false : true
}), {result: null, tail: s.length - 1})
.result
const webpack = require('webpack')
module.exports = {
devtool: 'inline-source-map',
entry: `${__dirname}/../src/index.js`,
output: {
publicPath: '/',
@daniellizik
daniellizik / scraper.js
Created November 4, 2016 19:54
scraper
'use strict';
const request = require('request-promise');
const cheerio = require('cheerio');
class Scraper {
constructor(opts) {
this.params = opts.params;
this.action = opts.action;
@daniellizik
daniellizik / webpack.config.js
Last active August 5, 2016 16:19
webpack config with dynamic multiple entry
// for HMR, don't add webpack/hot/devserver or whatever to config, just use --hot --inline in cli args
// https://github.com/webpack/webpack/issues/1151
'use strict';
const prod = /prod|production/i.test(process.env.NODE_ENV);
const webpack = require('webpack');
const env = process.env.NODE_ENV;
const dev = /dev|development/i.test(env);
const prod = /prod|production/i.test(env);
@daniellizik
daniellizik / publicpaths.js
Last active June 10, 2016 19:10
exposed public directory
'use strict';
const fs = require('fs');
const path = require('path');
const walkSync = (dir, filelist) => {
const files = fs.readdirSync(dir);
filelist = filelist || [];
files.forEach(function(file) {
if (fs.statSync(dir + '/' + file).isDirectory()) {
@daniellizik
daniellizik / Server.js
Created June 2, 2016 19:56
basic express/socketio setup
'use strict';
const path = require('path');
const express = require('express');
const http = require('http');
const io = require('socket.io');
class Server {
constructor(config) {
@daniellizik
daniellizik / path-generator.js
Last active May 18, 2022 03:03
Generate browser query selector string from a given dom element
'use strict';
(() => {
class QuerySelector {
constructor(origin) {
/**
* :nth-of-type is only ie9+ https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-of-type