This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setup() { | |
createCanvas(500, 500) | |
background('lightgray') | |
} | |
function draw() { | |
let side = 300 | |
let third = side / 3 | |
noStroke() | |
translate(100, 100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
require 'open-uri' | |
base = 'https://ncode.syosetu.com' | |
ncode = 'x0000xx' | |
seen = i = 777 | |
# start from #(seen + 1) chapter | |
p out = `date -Im`.strip | |
`mkdir #{out}` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io/fs" | |
"log" | |
"net/http" | |
"strings" | |
) | |
func isVideoFile(name string) bool { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface DisjointSets { | |
fun connect(p: Int, q: Int) | |
fun isConnected(p: Int, q: Int): Boolean | |
} | |
class DisjointSetsByArray(val elements: Int) : DisjointSets { | |
private val map = IntArray(elements) { -1 } | |
private fun top(id: Int): Int { | |
if (id !in map.indices) return -1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = 1000 | |
# s = N.times.each_with_object([1, 1]) { |_, a| a << 2*a[-2] + a[-1] } | |
# p [s, s.size] | |
# # https://www.crondose.com/2017/02/fibonacci-sequence-generator-ruby/ | |
# s = N.times.reduce([1, 1]) { |a| a << 2*a[-2] + a[-1] } | |
# # https://docs.ruby-lang.org/ja/master/class/Enumerator.html#S_NEW | |
# enum = Enumerator.new { |y| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class trace: | |
lv = 0 | |
# https://docs.python.org/3/reference/datamodel.html#object.__new__ | |
def __new__(cls, fn): | |
def wrapper(x): | |
indent = 4 * cls.lv * ' ' | |
cls.lv += 1 | |
print(indent + f'f({x})') | |
res = fn(x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class T: | |
... | |
def _m(my): print('m', my) | |
T.m = _m | |
@classmethod | |
def _cm(cls): print('cm', cls) | |
T.cm = _cm | |
## ...OR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dis | |
import rich # not in std | |
class Foo: | |
@staticmethod | |
def bar(co): | |
rich.inspect(co) | |
for c in co.co_consts: | |
if hasattr(c, 'co_code'): | |
Foo.bar(c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dis, json, sys, inspect, base64 | |
bs = b'this is bytes' | |
plex = 1+2j | |
def code2dict(co): | |
d = {} | |
for k, v in inspect.getmembers(co): | |
# isbuildtin(x) -> Is x a built-in FUNCTION or METHOD? | |
if k.startswith('co_') and not inspect.isbuiltin(v): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, itertools | |
for _, it in itertools.groupby(sorted(sys.stdlib_module_names), lambda s: s[0]): | |
for x in sorted(it): print(x) | |
print() |
OlderNewer