Skip to content

Instantly share code, notes, and snippets.

@husa
husa / README.md
Last active June 24, 2022 12:18
Increase version number based on tags

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
"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 August 1, 2018 12:07
nginx config for serving static site(browser history) + reverse proxy + redirect http to https
# 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 July 17, 2018 11:26
Formik validation
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 August 31, 2016 09:29
fetch content with timeout
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 January 18, 2024 10:34
XML to React Component
const xml = `
<XMLText class="yeah-attributes">
regular text
<XMLBold>
bold text
</XMLBold>
another text
</XMLText>
`;
@husa
husa / .babelrc
Last active March 11, 2016 10:16
ES7 decorators
{
"presets": ["es2015"],
"plugins": ["transform-decorators-legacy"]
}
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 December 25, 2015 10:57
ES2015 observable model
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 December 25, 2015 10:42
FAST grunt + livereload + browserify + babelify
module.exports = grunt => {
const LIVERELOAD_PORT = 35729;
require('load-grunt-tasks')(grunt, {});
require('time-grunt')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),