Skip to content

Instantly share code, notes, and snippets.

@tompng
tompng / spiral.html
Last active Mar 26, 2021
対数螺旋&長方形
View spiral.html
<body></body>
<script>
const a = 1.5388620467909049 // Math.log(a)*a*a*a = Math.PI/2
// const a = (1+5**0.5)/2
console.log(a*a*a*Math.log(a)*2)
const cx = 1 / (a * a + 1) / a
const cy = 1 / (a * a + 1)
const th0 = Math.PI + Math.atan(1 / a / a / a)
View strong_zero.rb
module Parser
TOKENS = {}
TOKEN_INFO = {
_: '_',
a: 'a',
# TODO: an undecillion, an octillion, an octodecillion
and: 'and',
minus: 'minus',
zero: 'zero',
one_nine: [nil] + %w[one two three four five six seven eight nine],
View pq.rb
class PQ
def initialize
clear
end
def clear
@heap = [nil]
end
def enq(value)
@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>