Skip to content

Instantly share code, notes, and snippets.

@razdvapoka
razdvapoka / slice that ignores array boundaries
Created March 24, 2017 17:12
slice that ignores array boundaries
const slice = (array, from, to) => {
let realFrom = from < 0 ? array.length + from : from
let realTo = to > array.length ? to - array.length : to
return (realFrom <= realTo
? array.slice(realFrom, realTo)
: array.slice(realFrom, array.length).concat(array.slice(0, realTo))
)
}
@razdvapoka
razdvapoka / withFullState.js
Created April 7, 2017 09:48
withFullState (multiple Recompose.withState composed together)
const capitalize = string =>
`${string.charAt(0).toUpperCase()}${string.slice(1)}`
const withFullState = stateSpec =>
compose(
...Object
.keys(stateSpec)
.map(stateKey =>
withState(
stateKey,
import './assets/emoji-picker.css'
import React, { Component } from 'react'
import { chatsApi, infoApi } from './api'
import AppAside from './AppAside'
import {
preloadDataSuccess as chatsPreloadDataSuccess
import axiosCreator from '../axios'
import { getToken } from '../../cookies/server'
import httpStatus from 'http-status-codes'
import { preload as preloadData } from 'redux-router-preload/lib/server'
import { removeToken } from '../../cookies/server'
const preload = (req, res, next) => {
const axios = axiosCreator(getToken(req))
preloadData(req.store, {axios})
@razdvapoka
razdvapoka / ansible-bootstrap-ubuntu-16.04.yml
Created August 25, 2017 16:37 — forked from gwillem/ansible-bootstrap-ubuntu-16.04.yml
Get Ansible to work on bare Ubuntu 16.04 without python 2.7
# Add this snippet to the top of your playbook.
# It will install python2 if missing (but checks first so no expensive repeated apt updates)
# gwillem@gmail.com
- hosts: all
gather_facts: False
tasks:
- name: install python 2
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
// copy and execute in devtools console
// to stop execute stop()
// to launch again execute go()
let handler;
const getRandomSign = () => Math.random() > 0.5 ? 1 : -1;
const roundRandomNumber = (max, min = 0) => min + Math.floor(Math.random() * max);
const fuckShitUp =
@razdvapoka
razdvapoka / gist:2dfdde2ad061110c53052cf2686a02f1
Created January 16, 2019 13:36
draw image with node-canvas
const {
createCanvas,
registerFont,
loadImage
} = require('canvas')
// подгружаем шрифт
registerFont('./static/fonts/d-m.woff', { family: 'D-M' })
@razdvapoka
razdvapoka / atan-example
Created September 17, 2020 09:00
update-sinewave-pointer
updatePointer = (pointer, { x, index, shift }) => {
const { pointerWidth, pointerHeight } = this.props
const { origin, freq, amplitude } = this.state
const baseY = Math.sin(freq * x + shift) * amplitude + origin.y
pointer.setAttribute('points', `
${x}, ${baseY}
${x + pointerWidth}, ${Math.sin(freq * x + shift) * amplitude + origin.y - pointerHeight / 2}
${x}, ${Math.sin(freq * x + shift) * amplitude + origin.y - pointerHeight}
`)
@razdvapoka
razdvapoka / liquid-distortion-material.js
Created November 2, 2020 21:36
Slightly updated liquid distortion material for blotter.js
;(function (Blotter) {
Blotter.LiquidDistortMaterial = function () {
Blotter.Material.apply(this, arguments)
}
Blotter.LiquidDistortMaterial.prototype = Object.create(
Blotter.Material.prototype
)
Blotter._extendWithGettersSetters(
@razdvapoka
razdvapoka / point-coords.js
Created June 1, 2021 18:18
scene point's screen coords
const screenPosition = point.position.clone();
screenPosition.project(camera);
const translateX = screenPosition.x * canvas.width * 0.5;
const translateY = -screenPosition.y * canvas.height * 0.5;
element.style.transform = `translate(${translateX}px, ${translateY}px)`;