Skip to content

Instantly share code, notes, and snippets.

View gribnoysup's full-sized avatar

Sergey Petushkov gribnoysup

View GitHub Profile
/**
* All credit goes to Rich Harris
* https://github.com/Rich-Harris/yootils/blob/master/scripts/check-treeshaking.js
*/
const { rollup } = require('rollup');
async function check() {
const bundle = await rollup({
input: 'scripts/check-treeshaking-entry.js',
onwarn: (warning, handle) => {
export const debounce = (fn, delay = 0, context = null) => {
let timeout = null;
const debounced = (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => fn.apply(context, args), delay);
};
debounced.cancel = () => clearTimeout(timeout);
import React from 'react'
const { func, bool } = React.PropTypes
export default class AsyncComponent extends React.Component {
static propTypes = {
resolve: func.isRequired,
showProcess: bool
}
@gribnoysup
gribnoysup / html-additional-chunks-plugin.js
Created February 9, 2017 10:21
Add additional (child) chunks to HtmlWebpackPlugin
class HtmlAdditionalChunksPlugin {
constructor(chunks = []) {
this.chunks = chunks
this.onBeforeGeneration = 'html-webpack-plugin-before-html-generation'
}
findChunk(chunk, chunkName) {
return Array.isArray(chunk.names) && chunk.names[0] === chunkName
}
import React from 'react'
const {oneOf, node, func, oneOfType} = React.PropTypes
const isMobile = /Mobi/.test(window.navigator.userAgent || '')
const device = {
mobile: isMobile,
desktop: !isMobile
}
import React, {Component} from 'react'
export default class ResizeListener extends Component {
static defaultProps = {
onResize: Function.prototype,
getDOMNode: Function.prototype
}
constructor(...args) {
super(...args)
import React from 'react';
import { Motion, spring, presets } from 'react-motion';
import Swipeable from './Swipeable';
import styled from 'styled-components'
const ReseteUl = styled.ul`
margin: 0;
padding: 0;
@gribnoysup
gribnoysup / trigger.md
Last active April 9, 2021 02:10
Trigger transition on dynamically appended DOM element

HTML

<p>
  <button class="show">show</button>&nbsp;<button class="hide">hide</button>
</p>
<p class="animation-container"></p>

CSS

@gribnoysup
gribnoysup / binarySearchTree.js
Created August 30, 2015 10:07
Binary Search Tree (BST)
function BinarySearchTree (rootData) {
this.root = null;
this.nodes = 0;
this.add(rootData);
}
BinarySearchTree.prototype = {
constructor : BinarySearchTree,
add : function add (data) {
if (this.root === null) {
@gribnoysup
gribnoysup / binarySearch.js
Last active August 29, 2015 08:09
Binary search, binary search with recursion, rotation count, circular array search
// first = true - find first occurance
// first = false - find last occurance
// first = undefined - first found
function binarySearch(array, x, first) {
var start = 0, end = array.length - 1, mid = 0, result = -1;
while (start <= end) {
mid = Math.floor((start + end) / 2);
if (array[mid] == x) {
result = mid;