Skip to content

Instantly share code, notes, and snippets.

@piglovesyou
piglovesyou / README.md
Created April 4, 2020 10:09
How examples/api-routes-apollo-server-and-client/apollo/client.js works

How examples/api-routes-apollo-server-and-client/apollo/client.js works

#!/usr/bin/env node
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
fs.writeFileSync(
'package.json',
JSON.stringify(
{
...pkg,
@piglovesyou
piglovesyou / useForAwait.js
Created October 28, 2019 00:04
Use pipeline-pipe for shorter execution time
const { Readable } = require('stream');
const { pipe, pipeline } = require('pipeline-pipe');
const Listr = require('listr');
const { Observable } = require('rxjs');
const ss = [];
const os = Array.from(Array(50)).map((_, i) => [
i, new Observable(s => {
ss[i] = s;
})
@piglovesyou
piglovesyou / apply-shortcut.sh
Created September 22, 2019 01:29
Apply Shortcut to a new macOS account
#!/usr/bin/env bash
escapeUnicode() {
str="$1";
escaped=$(node -e 'console.log(escape(process.argv[1]).toLowerCase().replace(/%u/g, "\\U"))' $str);
echo $escaped
}
# Fixing problem where IME steals Ctrl+Shift+r
defaults write -g NSUserKeyEquivalents -dict-add "$(escapeUnicode '再変換')" -string "@~^$r";
@piglovesyou
piglovesyou / eijiro-deploy.sh
Last active June 25, 2024 12:59
英辞郎 Ver.158 for macOS Dictionary.app でダウンロードした .zip と .rar を ~/Library/Dictionaries に展開して Dictionary.app で使えるようにするスクリプト
#!/usr/bin/env bash
#title eijiro-setup.sh
#description This script deploys downloaded zip/rar files of "英辞郎 Ver.158 for macOS Dictionary.app" into your ~/Library/Dictionaries
#author soichi
#date 2019-08-06
#version 1.0.0
#usage bash eijiro-setup.sh
#notes Befor run
# 1. go https://www.tecorin.com/osx/index.html and buy it (expect Ver.158)
# 2. download all six files you bought and leave them in your ~/Downloads
Index: src/components/Footer/Footer.tsx
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/components/Footer/Footer.tsx (date 1557115556000)
+++ src/components/Footer/Footer.tsx (date 1557542501000)
@@ -8,32 +8,70 @@
*/
@piglovesyou
piglovesyou / a.js
Created February 23, 2019 01:19
Even though all of options match, function intersection in $Call<F> returns the first match.
// @flow
declare type A = {a: string};
declare type AB = A | {b: string};
declare type ABC = AB | {b: string};
type v = $Call<
& (ABC => 3)
@piglovesyou
piglovesyou / a.js
Created February 21, 2019 23:15
Method overloading where one fulfills another
// @flow
declare class Hole<T> {
constructor(T): Hole<T>;
pipe<U>(fn: T => Promise<U>): Hole<U>;
pipe<U>(fn: T => U): Hole<U>;
}
new Hole(42)
@piglovesyou
piglovesyou / main.js
Last active February 5, 2019 23:32
Why my exported type goes wrong in conditional typing, while the exact same type in local works fine
// @flow
import type {ExportedType} from './types';
type LocalType = number;
function useExported(e): Promise<ExportedType> {
return (1: any)
}
function useLocal(e): Promise<LocalType> {
return (1: any)
@piglovesyou
piglovesyou / a.js
Created March 4, 2018 02:22
Node Stream behavior
console.time('speed?');
const r = createReadable(40);
const t = new Transform({
objectMode: true,
transform(data, enc, callback) {
setTimeout(() => {
console.log(`-- t ${data}, ${this.writableLength}`);
callback(null, data);
}, 400);
}