Skip to content

Instantly share code, notes, and snippets.

View aiya000's full-sized avatar
🐶
Inu

aiya000 aiya000

🐶
Inu
View GitHub Profile
/**
* The type 'true' means a proof is satisfied.
* The type 'never' means a proof is not satisfied.
*/
// Basic of this idea.
type AWrongProof = { x: number } extends { x: string } ? true : never
// Compile NG
@aiya000
aiya000 / types.ts
Created February 20, 2021 15:08
TypeScriptは`interface Foo { ... }`と`type Foo = { ... }`を区別するっぽい!?
/**
* Proves that A and B is the same types.
*/
export type Equal<A, B> = A extends B ? (B extends A ? true : never) : never
/**
* Makes all fields of A to `<its-type> | null`.
*/
export type Nullable<A extends Record<string, unknown>> = { [K in keyof A]: A[K] | null }
@aiya000
aiya000 / Nullable.ts
Created February 20, 2021 14:55
証明できてる?
/**
* Proves that A and B is the same types.
*/
export type Equal<A, B> = A extends B ? (B extends A ? true : never) : never
/**
* Makes all fields of A to `<its-type> | null`.
*/
export type Nullable<A extends Record<string, unknown>> = { [K in keyof A]: A[K] | null }
@aiya000
aiya000 / auth-user.ts
Last active February 19, 2021 12:40
Getting an access token of VRChat API. and then getting friend list using it. VRChat APIでアクセストークンを使って、フレンドを取得するやつ。
import axios from 'axios'
function isThatArray<T>(x: unknown, p: (a: unknown) => a is T): x is Array<T> {
return Array.isArray(x) && x.every(p)
}
function isString(x: unknown): x is string {
return typeof x === 'string'
}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}
newtype Fix f = Fix
{ unFix :: f (Fix f)
}
cata :: Functor f => (f a -> a) -> Fix f -> a
cata f (Fix x) = f $ fmap (cata f) x
(Hask)

                f
    Maybe Int ---> Int
       |            |
fmap a |            | a
       v        g   v
    Maybe Bool --> Bool
 | |
(Hask)

                f
    Maybe Int ---> Int
       |            |
fmap a |            | a
       v        g   v
    Maybe Bool --> Bool
 | |
(Hask)

                f
    Maybe Int ---> Int
       |            |
fmap a |            | a
       v        g   v
    Maybe Bool --> Bool
 | |
#!/bin/bash
# もし現在のgitブランチ(ここでfooとします。)がpushされていれば、{remote_name}/fooを返します。
# そうでなければこのブランチのルートとなるブランチ(分岐元)を取得し、それを返します。
#
# このプログラムはまず、リモート名を取得します。
# remoteが複数登録されている場合の適切な処理は未定義です。
# 現在は1番目のリモートを使用するようになっています。
# Returns tags and branches names of the root revision of current.
#!/bin/bash
# もし現在のgitブランチ(ここでfooとします。)がpushされていれば、{remote_name}/fooを返します。
# そうでなければこのブランチのルートとなるブランチ(分岐元)を取得し、それを返します。
#
# このプログラムはまず、リモート名を取得します。
# remoteが複数登録されている場合の適切な処理は未定義です。
# 現在は1番目のリモートを使用するようになっています。
# Returns tags and branches names of the root revision of current.