Skip to content

Instantly share code, notes, and snippets.

@husa
husa / README.md
Last active Jun 24, 2022
Increase version number based on tags
View README.md

Version Bump Script

Script finds latest ancestor tag in git tree and outputs to stdout next increased tag.

Defaults

Prop Default Possible Values Description Example
part "major" "major" | "minor" Which part of version to increase --major, --minor
prefix "v" String prefix of the tag(before version numbers) --prefix=v, --prefix=pod5-v
View stateMachine.js
"use strict";
// Actually state-less machine
class TransitionForbiddenError extends Error {
constructor() {
super("Transition Forbidden");
this.name = "TransitionForbiddenError";
}
}
class StateMachine {
static get ForbiddenError() {
@husa
husa / app.conf
Last active Aug 1, 2018
nginx config for serving static site(browser history) + reverse proxy + redirect http to https
View app.conf
# TODO
# 1. MAJOR: create 404.html and 5xx.html error pages and bundle them with the app
# 2. MINOR: remove trailing slash (app will handle it okay)
server {
listen 80;
server_name localhost;
root /usr/src/app;
index index.html;
@husa
husa / usage.js
Last active Jul 17, 2018
Formik validation
View usage.js
withFormik({
// ...
validate: createValidator({
title: ['required', rules.minLength(3), rules.maxLength(400), 'commonText'],
price: ['required', 'price', price => price === 1000 ? 'Price can not be 1000' : null]
}),
// ...
})
@husa
husa / fetch.js
Last active Aug 31, 2016
fetch content with timeout
View fetch.js
const MIN_LOADING_TIME = 4000;
function fetchContent (url, options) {
// fetch from remote or get from cache
return fetch(url, options).then(response => response.json())
}
function wait(time) {
return new Promise(resolve => setTimeout(resolve, time))
}
@husa
husa / xml2react.js
Last active May 27, 2021
XML to React Component
View xml2react.js
const xml = `
<XMLText class="yeah-attributes">
regular text
<XMLBold>
bold text
</XMLBold>
another text
</XMLText>
`;
@husa
husa / .babelrc
Last active Mar 11, 2016
ES7 decorators
View .babelrc
{
"presets": ["es2015"],
"plugins": ["transform-decorators-legacy"]
}
View store.js
const _state = Symbol('previous_state');
const _listeners = Symbol('listeners');
class Store {
constructor(state = {}) {
this[_state] = {};
this[_listeners] = [];
this.setState(state);
}
@husa
husa / events.js
Created Dec 25, 2015
ES2015 observable model
View events.js
class Events {
constructor () {
this._events = {};
}
on (name, listener, context) {
// support multiple event names
this._events[name] = this._events[name] || [];
// check if already present
this._events[name].push({listener, context});
@husa
husa / Gruntfile.js
Created Dec 25, 2015
FAST grunt + livereload + browserify + babelify
View Gruntfile.js
module.exports = grunt => {
const LIVERELOAD_PORT = 35729;
require('load-grunt-tasks')(grunt, {});
require('time-grunt')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),