Skip to content

Instantly share code, notes, and snippets.

@tompng
tompng / stickynote_shadow.html
Created September 12, 2024 08:32
stickynote shadow
<canvas>
<script>
ctx = document.querySelector('canvas').getContext('2d')
ctx.clearRect(0, 0, 1000, 1000)
const blur = 12
ctx.shadowBlur = blur
ctx.shadowColor = 'black'
ctx.shadowOffsetX = blur
ctx.shadowOffsetY = blur
const x = 20
@tompng
tompng / tree.rb
Last active September 11, 2024 10:44
Tree rendering
require 'chunky_png'
case ARGV[0]
when 'red'
FLOOR_COLOR = [0xff, 0x80, 0x80]
LEAF_COLOR = 0xff0044
TRUNK_COLOR = 0xff8888
RAY_COLOR = [2, 1, 1]
LIGHT_THETA = 0.1
when 'green'
@tompng
tompng / measure_width.rb
Created August 20, 2024 16:44
terminal emulator measure result
codepoints = File.read('EastAsianWidth.txt').scan(/^[0-9A-F]{4,6}/).map { _1.to_i(16) }
widths = codepoints.map do |cp|
c = cp.chr('utf-8') rescue (next nil)
print "\e[H\e[K#{c}\e[6n"
STDOUT.flush
/\e\[\d+;(\d+)R/ =~ STDIN.raw { STDIN.readpartial(1000) }
$1.to_i - 1
end
codepoints.zip(widths).reject {
!_2 || Reline::Unicode.get_mbchar_width(''<<_1) == _2 || ('a'<<_1).grapheme_clusters.size == 1
<body>
<script>
const width = 1600
const height = 900
function f(x) {
return 0.48+(-Math.cos(12*x+3*Math.sin(6*x-4)/4-1)*(1.1-x)+(3*x-(2*x-1)**2)*0.5)/20
}
function g(x, a) {
return (
Math.sin(12.4*x-a)+Math.sin(14.3*x+a)+
require 'io/console'
require 'pty'
command = ARGV.join(' ')
if command.empty?
puts 'Error: Command not specified.'
puts "Usage: `ruby #{File.basename __FILE__} options -- command`"
exit
end
srand 0
6.times do |index|
bg = "##{3.times.map{"%02x" % rand(0..128)}.join}"
fg = "##{3.times.map{"%02x" % rand(128..255)}.join}"
face = :"face#{index}"
Reline::Face.config(face) do
_1.define(:default, foreground: fg, background: bg)
end
pointClass = Data.define :x, :y
Reline.add_dialog_proc :"dialog#{index}", ->{
@tompng
tompng / reline_editor.rb
Created August 5, 2024 09:35
Text editor using reline
require 'irb'
require 'reline'
$status = nil
Reline::Face.config(:editor_status) do |face|
face.define :default, foreground: :white, background: :blue
end
Reline.add_dialog_proc :editor_status, ->(*) do
if (message = $status)
$status = nil
# compile.c:L3057
# if (lab->unremovable) {
# rb_gv_set("$FOO", Qtrue); // Add this to run this script
# break; // maybe bug
# }
require 'prism'
class StringVisitor < Prism::Visitor
attr_reader :strings
def initialize; @strings = [] end
require 'ripper'
$VERBOSE = nil
tokens = <<'S'.split
def if true false nil + - = a A :: '' "#{
class module ? : . ( [ { -> | & * , / % ! @ $ ; < <<
S
loop do
code = (tokens.sample(9) + [' ']*5).shuffle.join
# code = tokens.sample(9).join(' ')
# RDOC_USE_PRISM_PARSER=1 bundle exec rdoc --op foo/bar
path_a = 'prism'
path_b = 'legacy'
files_a = Dir.chdir(path_a){Dir.glob('**/*.html')}
files_b = Dir.chdir(path_b){Dir.glob('**/*.html')}
def red(s) = "\e[31m#{s}\e[m"
def green(s) = "\e[32m#{s}\e[m"