Skip to content

Instantly share code, notes, and snippets.

@iamvanja
iamvanja / bookmarklet.html
Created February 1, 2017 02:16
Bookmarklet for form pre-filling with customizable email address and ability to add random part
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
var genBtn = document.getElementsByName("gen")[0];
var emailLink = document.getElementById("email-link");
genBtn.addEventListener("click", function() {
@iamvanja
iamvanja / index.js
Created February 21, 2017 03:23
Flatten array
var flatten = function(arr) {
return arr.reduce(function (flat, toFlatten) {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}
flatten([[1,2,[3]],4]); // [1,2,3,4]
@iamvanja
iamvanja / index.css
Created April 2, 2017 05:38
Animated background
background: linear-gradient(180deg, #b60f61, #f2702d, #2db5a7, #be3df4, #008000, #f2c23a);
background-size: 8000% 8000%;
animation: animate-bg 10s linear infinite;
@keyframes animate-bg {
0% {background-position:50% 0%}
50% {background-position:50% 100%}
100% {background-position:50% 0%}
}
@iamvanja
iamvanja / component.js
Created April 17, 2017 04:58
Promise setState
function setStatePromise(that, newState) {
return new Promise((resolve) => {
that.setState(newState, () => {
resolve();
});
});
}
@iamvanja
iamvanja / utils.js
Created May 16, 2017 23:29
Deep object merge
export function isObject(item) {
return (item && typeof item === 'object' && !Array.isArray(item) && item !== null);
}
export default function mergeDeep(target, source) {
let output = Object.assign({}, target);
if (isObject(target) && isObject(source)) {
Object.keys(source).forEach(key => {
if (isObject(source[key])) {
if (!(key in target)) {
@iamvanja
iamvanja / mysql-json.md
Created May 30, 2017 18:24
JSON type in MySQL

JSON type in MySQL

MySQL 5.7 comes with a native JSON data type and a set of built-in functions to manipulate values of the JSON type. This document demonstrates the usage.

INSERT

-- raw json
INSERT INTO json_test 
  (name, attributes)
VALUES (
/* eslint-disable no-console */
import { } from 'config/env'
import { APP_ROLE_PUBLISHER } from 'config/constants'
import idManager from 'services/idManager'
import get from 'lodash/get'
import eachLimit from 'async/eachLimit'
/**
* Migrate publishers from momentum.roles to skpn.roles.
* The script can be used for any type of migration, with adjusted parameters.
@iamvanja
iamvanja / Child.js
Last active June 15, 2020 18:17
Access child method from a parent in React
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
class Child extends PureComponent {
componentDidMount() {
const { getMethod } = this.props;
// Pass child method to the parent by calling parent getter
// This could be something more general (`getMethods` where array/object of methods is passed)
getMethod(this.handleChildMethod);