Skip to content

Instantly share code, notes, and snippets.

View alexaivars's full-sized avatar

Alexander Aivars alexaivars

  • Aivars AB
  • Sweden
View GitHub Profile
import React from 'react';
import { useHistory as originalUseHistory } from 'react-router-dom';
import { parse, stringify } from 'lib/normalizingQs';
export function useHistory({ keepQuery } = {} ) {
const history = originalUseHistory();
if(!keepQuery) {
return history;
}
const cachedHistory = React.useMemo( () => {
import React, { useRef, useState, useEffect } from 'react';
import styled, {css} from 'styled-components';
const Landing = () => (
<div>
<Uploader width={640} height={480} />
</div>
);
const Form = styled.form`
const error = require('debug')('server:error');
const store = require('./data');
const Koa = require('koa');
const Router = require('koa-router');
const omit = require('./utils/omit');
const app = new Koa();
const api = new Router();
const cors = require('./middleware/cors');
const mount = require('koa-mount')
const bodyParser = require('koa-bodyparser')();
const React = require('react');
module.exports = function List({ children, ...other }) {
return (
<ul {...other}>
{ React.Children.toArray(children).map((child) => <li key={child.key}>{child}</li> ) };
</ul>
);
}
@alexaivars
alexaivars / getin.js
Created February 16, 2017 09:54
// safly get values from nested object trees 1 // using similar interface as immutable.js
module.exports = (target, path, defaultValue) => path.reduce(
(obj, key) => obj && obj.hasOwnProperty(key) ? obj[key] : null
, target
) || defaultValue;
module.exports = (obj, ...keys ) => keys.reduce((result, key) => Object.assign(result, { [key]: obj[key] }), {});
const maxfps = 60/1000;
const tween = TweenComponent => {
return class Tween extends Component {
constructor(props) {
super(props);
this.state = {
request: 0,
duration: Math.floor(5000 * maxfps),
start: 0,
from: props.from || 0,
@alexaivars
alexaivars / composeReducers.js
Created October 31, 2016 18:46
compose redux reducers
export default function composeReducers(...reducers) {
return (state, action) => reducers.reduce((result, fn)=>fn(result, action), state);
}
var canvas = document.getElementById('canvas1');
var img = new Image;
var mst = new Image;
var mstSrc = "http://i.ytimg.com/vi/zNeaXKF0Eik/maxresdefault.jpg";
var imgSrc = "http://www.goodwp.com/images/201303/goodwp.com_27776.jpg";
const drawBackground = (canvas) => {
const ctx = canvas.getContext('2d');
ctx.globalCompositeOperation = "source-over";
ctx.globalAlpha = 1;
@alexaivars
alexaivars / Sticky.js
Created June 4, 2015 21:57
sticky wrapper
'use strict';
var React = require('react');
var util = {
// findPos() by quirksmode.org
// Finds the absolute position of an element on a page
findPos: function (obj) {
/*jshint -W084 */
var curleft = 0,