Skip to content

Instantly share code, notes, and snippets.

import React, { FC, useLayoutEffect, CSSProperties, useEffect, useRef, useMemo, useCallback, useState } from 'react';
import { createPopper, VirtualElement, Options, Instance } from '@popperjs/core';
/**
* Helper hooks
*/
function usePrevious<T>(value: T): T | undefined {
const ref = useRef<T>();
useEffect(() => {
import { ApolloClient, QueryOptions, MutationOptions } from 'apollo-client';
import { DocumentNode } from 'graphql';
import { getSdk, Requester } from '.generated/schema-typedefs';
import { ApolloRequestError } from './ApolloRequestError';
export type ApolloRequesterOptions<V, R> =
| Omit<QueryOptions<V>, 'variables' | 'query'>
| Omit<MutationOptions<R, V>, 'variables' | 'mutation'>;
@akozhemiakin
akozhemiakin / normalizeElectronPath.ts
Last active October 21, 2019 11:11
Asar-aware path functions
import * as fs from 'fs';
import * as _path from 'path';
export const normalizeElectronPath = (s: string): string => {
const alp = s.replace(/app\.asar(?!\.unpacked)/g, 'app.asar.unpacked');
let inAsarUnpacked = false;
if (fs.existsSync(alp)) {
inAsarUnpacked = true;
import monix.execution.Ack.{Continue, Stop}
import monix.execution.{Ack, Scheduler}
import monix.reactive.Observable.Operator
import monix.reactive.observers.Subscriber
import scala.concurrent.{Future, Promise}
class ElasticBufferOperator[A](size: Int) extends Operator[A, A] {
override def apply(out: Subscriber[A]): Subscriber[A] = new Subscriber[A] {
private[this] var buffer: List[A] = Nil
@akozhemiakin
akozhemiakin / moving_frame.scala
Last active January 18, 2017 20:08
Moving frame
import scala.collection.mutable.ArrayBuffer
import scala.util.Try
class FrameReader[A](
before: Int,
after: Int,
onNextFrame: (MovingFrame[A], Boolean) => Unit
) {
private val b: ArrayBuffer[A] = ArrayBuffer()
private var cf: Option[MovingFrame[A]] = None
@akozhemiakin
akozhemiakin / typefull_map.scala
Created January 17, 2017 16:54
Typeclass for Scala map that allows to get values and ensure their type
import scala.collection.Map
import scala.reflect.ClassTag
final case class TypefullMapOps[K, V, M <: Map[_, _]](m: M)(implicit ev: M <:< Map[K, V]) {
def getT[A <: V : ClassTag](k: K): Option[A] = m.get(k) match {
case Some(x) => x match {
case v: A => Some(v)
case _ => throw new RuntimeException
}
case _ => None
import shapeless.labelled._
import shapeless.ops.hlist
import shapeless.{HList, HNil, LabelledGeneric}
trait Updater[A, B] {
def apply(a: A, b: B): A
}
object Updater {
def apply[A, B](implicit updater: Updater[A, B]): Updater[A, B] = updater
@akozhemiakin
akozhemiakin / kleisli_question.scala
Last active February 24, 2017 19:05
Question about organizing dependency tree with Kleisli
// I have no experience with Scalaz, but I believe that Scalaz's Kleisli and the one of Cats are quite similar
import cats.Id
import cats.data.Kleisli
import cats.implicits._
case class User(id: Int, name: String, active: Boolean)
trait UserService {
type DeactivateConfigT