Skip to content

Instantly share code, notes, and snippets.

Esa-Matti Suuronen epeli

Block or report user

Report or block epeli

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View dataloader.js
const wait = t => new Promise(resolve => setTimeout(resolve, t));
class Dataloader {
constructor() {
this.pending = {};
}
async load(id) {
return new Promise(resolve => {
this.pending[id] = resolve;
@epeli
epeli / uniq-meta-values.php
Last active May 15, 2019
Get unique meta values for a given post type in WordPress WPGraphQL
View uniq-meta-values.php
<?php
/**
* Add graphql root query for getting unique meta values for a given post type
*/
class UniqMetaValues {
function init() {
add_action( 'graphql_register_types', [ $this, 'register_types' ], 10, 0 );
}
@epeli
epeli / classnamed.tsx
Created Apr 3, 2019
Class Named Components
View classnamed.tsx
import React from "react";
type ClassNamePrimitive = string | false | undefined | null;
interface ClassNamesFunction<Props> {
(props: Props): ClassNamePrimitive | ClassNamePrimitive[];
}
interface ClassNamesDict<Props> {
[className: string]: boolean | ((props: Props) => boolean);
View AvgCalculator.ts
type BuildMeasures<T extends string> = {
[K in T]: {count: number; duration: number}
};
export class AvgCalculator<T extends string> {
private measures: BuildMeasures<T>;
constructor(keys: T[]) {
const measures = {} as BuildMeasures<T>;
@epeli
epeli / scroll-search.ts
Created Jan 23, 2019
Use async iteration to iterate over large search results in Elasticsearch
View scroll-search.ts
import {Client, SearchParams} from "elasticsearch";
/**
* Iterate all search results one by one with async iteration without reading
* it all to memory
*/
async function* scrollSearch<Document>(esClient: Client, params: SearchParams) {
let res = await esClient.search<Document>(params);
while (true) {
View followLocationWithHead.ts
async function followLocationWithHead(
url: string,
count = 0,
): Promise<AxiosResponse> {
console.log("follow", url);
if (count > 5) {
throw new Error("Too many redirects");
}
View gulp.completion.bash
gulp() {
"$(_get_gulp_bin)" $@
}
_get_gulp_bin() {
if [ -x "./node_modules/.bin/gulp" ]; then
echo "$PWD/node_modules/.bin/gulp"
else
which gulp
fi
@epeli
epeli / utils.tsx
Created Sep 17, 2018
Typescript DeepRequired
View utils.tsx
type NotNill<T> = T extends null | undefined ? never : T;
type Primitive = undefined | null | boolean | string | number | Function;
type DeepRequired<T> = T extends Primitive
? NotNill<T>
: {
[P in keyof T]-?: T[P] extends Array<infer U>
? Array<DeepRequired<U>>
: T[P] extends ReadonlyArray<infer U2>
View 0001-Fix-react-native-push-notification-for-android.patch
From d6eece6c19c8779b87725f84b28d6cd4649edae7 Mon Sep 17 00:00:00 2001
From: Esa-Matti Suuronen <esa-matti@suuronen.org>
Date: Wed, 12 Sep 2018 12:40:33 +0300
Subject: [PATCH] Fix react-native-push-notification for android
---
android/app/build.gradle | 12 ++++++------
android/build.gradle | 7 +++++++
2 files changed, 13 insertions(+), 6 deletions(-)
@epeli
epeli / react-native-maps+0.21.0.patch
Created Sep 4, 2018
react-native-maps patch for gradle 2
View react-native-maps+0.21.0.patch
patch-package
--- a/node_modules/react-native-maps/lib/android/build.gradle
+++ b/node_modules/react-native-maps/lib/android/build.gradle
@@ -43,8 +43,8 @@ dependencies {
def googlePlayServicesVersion = rootProject.hasProperty('googlePlayServicesVersion') ? rootProject.googlePlayServicesVersion : DEFAULT_GOOGLE_PLAY_SERVICES_VERSION
def androidMapsUtilsVersion = rootProject.hasProperty('androidMapsUtilsVersion') ? rootProject.androidMapsUtilsVersion : DEFAULT_ANDROID_MAPS_UTILS_VERSION
- compileOnly "com.facebook.react:react-native:+"
- implementation "com.google.android.gms:play-services-base:$googlePlayServicesVersion"
- implementation "com.google.android.gms:play-services-maps:$googlePlayServicesVersion"
You can’t perform that action at this time.