Skip to content

Instantly share code, notes, and snippets.

@tompng
tompng / 2021.rb
Last active Jan 5, 2021
丑年2021 Quine
View 2021.rb
;" s=
s.s pli
t(f= 35.c
hr)[0 ]+f;z
='gIa ".tap{$s=_1};s=$s+"AgI CAg4C
";c='s=s.split*""';s<<%"AgPCAgICAnICAh
8CAgIC ";p=->{eval(eval(c))};s<<"D4ICAvoCAgIC+g ICB+P/
";at_exit(&p);s<<"//8fggICP//////6Ah/H///////j+/////////////
//////////P//////////CB////////gICP+J///I/4gID/nP//zr/AgIP55
//88/iAgJ/g///wv8CAgf///////ICAj///////4ICAv//////8gICD/
View christmas.ts
type DeleteSpace<T extends string> =
T extends `${infer A} ${infer B}` ? `${DeleteSpace<A>}${DeleteSpace<B>}` :
T extends `${infer A} ${infer B} ${infer C} ${infer D} ${infer E} ${infer F} ${infer G} ${infer H} ${infer I} ${infer J} ${infer K} ${infer L} ${infer M} ${infer N} ${infer O} ${infer P} ${infer Q}`
? `${A}${B}${C}${D}${E}${F}${G}${H}${I}${J}${K}${L}${M}${N}${O}${P}${DeleteSpace<Q>}` :
T extends `${infer A} ${infer B} ${infer C} ${infer D}`
? `${A}${B}${C}${DeleteSpace<D>}` :
T extends `${infer A} ${infer B}` ? `${A}${DeleteSpace<B>}` : T
type DeleteLB<T extends string> = T extends `${infer A}\n${infer B}\n${infer C}\n${infer D}`
@tompng
tompng / Gemfile
Last active Dec 17, 2020
fiber batch loader
View Gemfile
source 'https://rubygems.org'
gem 'graphql'
gem 'graphql-batch'
@tompng
tompng / SelectableState.tsx
Last active Dec 2, 2020
SelectableStateとselectorが使えるContextみたいなやつ
View SelectableState.tsx
type SelectorFunction<T, U = any> = (data: T) => U
type SubscribeCallback<T = any> = (value: T) => void
type CompareFunction = (a: any, b: any) => boolean
export class SelectableState<T> {
constructor(public data: T) {}
selectorsInfo = new Map<SelectorFunction<T>, { value: any, comparators: Map<CompareFunction, Set<SubscribeCallback>> }>()
subscribe<U>(selector: SelectorFunction<T, U>, comparator: CompareFunction, callback: SubscribeCallback<U>) {
let info = this.selectorsInfo.get(selector)
if (!info) this.selectorsInfo.set(selector, info = { value: selector(this.data), comparators: new Map() })
let callbacks = info.comparators.get(comparator)
View array_map_syntax_sugar.ts
type MapProxyValue<T> = T extends (...args: infer U) => infer V
? (...args: U) => V[]
: T[]
type MapProxy<T> = {
[key in Exclude<keyof T, '_avoid_ts_something'>]: MapProxyValue<T[key]>
}
class Array2<T> extends Array<T> {
map2<U>(f: (v: T) => U): U[]
map2(): MapProxy<T>
View index.html
<body>
<style>
svg{box-shadow:0 0 1px black}
svg.print{
position: absolute;
left: 0;
top: 0;
transform: scale(2.22222222);
transform-origin: 0 0;
box-shadow: none;
@tompng
tompng / curve.html
Last active Oct 28, 2020
css nazca cat
View curve.html
<style>
body{
background-image: url(nazca.png);
background-size: 1024px;
background-repeat: no-repeat;
}
</style>
<script src='curve.js'></script>
<script>
@tompng
tompng / stm.rb
Last active Sep 29, 2020
Ractorで作ったSTMみたいなもの?
View stm.rb
module STM
class Pipe < Ractor
def self.create() = new { loop { Ractor.yield Ractor.recv } }
end
class OpRead < Pipe; end
class OpReqLock < Pipe; end
class OpReadVersion < Pipe; end
ReadPool = Pipe.create
ReqLockPool = Pipe.create
ReadVersionPool = Pipe.create
View in_main_ractor.rb
module InMainRactor
def self.pipe() = Ractor.new { loop { Ractor.yield Ractor.recv } }
REQUEST = pipe
LOCK = pipe
LOCK << :lock
RESPONSE = pipe
MAIN_RACTOR = Ractor.current
class Delegator < BasicObject
def initialize(receiver)
@receiver = receiver
@tompng
tompng / clipboard.js
Created Sep 1, 2020
clipboard api 色々チェック用スクリプト
View clipboard.js
function createCanvas() {
const canvas=document.createElement('canvas')
canvas.width=canvas.height=100
const ctx = canvas.getContext('2d')
ctx.textAlign='center'
ctx.textBaseline='center'
for(let i=0;i<100;i++){ctx.fillText(String.fromCharCode(16384*Math.random()),100*Math.random(),100*Math.random())}
return canvas
}