Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / inverse.js
Created May 26, 2013 10:58
finding the inverse matrix in JavaScript (port from C++)
function inverse(_A) {
var temp,
N = _A.length,
E = [];
for (var i = 0; i < N; i++)
E[i] = [];
for (i = 0; i < N; i++)
for (var j = 0; j < N; j++) {
@husa
husa / pre-commit.sh
Created September 8, 2015 14:39
Git pre-commit hook to run JS Unit Test before every commit
#!/bin/sh
red="\033[0;31m"
yellow="\033[1;33m"
green="\033[1;32m"
reset="\033[0m"
read -a changed_files <<< $(git diff --cached --name-only --raw)
# check if there're any JS related files in commit
runTests=false
@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 / SassMeister-input.scss
Created November 23, 2015 15:11
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
// from http://www.sitepoint.com/extra-map-functions-sass/
/// jQuery-style extend function
/// About `map-merge()`:
/// * only takes 2 arguments
/// * is not recursive
/// @param {Map} $map - first map
@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'),
@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))
}