Skip to content

Instantly share code, notes, and snippets.

View Eric-Guo's full-sized avatar

Eric Guo Eric-Guo

View GitHub Profile
@Eric-Guo
Eric-Guo / DOM3D.js
Created March 27, 2024 14:23 — forked from OrionReed/dom3d.js
3D DOM viewer, copy-paste this into your console to visualise the DOM topographically.
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks.
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/)
(() => {
const SHOW_SIDES = false; // color sides of DOM nodes?
const COLOR_SURFACE = true; // color tops of DOM nodes?
const COLOR_RANDOM = false; // randomise color?
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com)
const MAX_ROTATION = 180; // set to 360 to rotate all the way round
const THICKNESS = 20; // thickness of layers
const DISTANCE = 10000; // ¯\\_(ツ)_/¯
@Eric-Guo
Eric-Guo / qrgen.rb
Created March 13, 2017 09:55
QR Code (二维码)个人名片产生器
#!/usr/bin/ruby
#Developed by proxhotdog on 15 June 2012
#Ruby 1.8.7
#Mac OSX 10.7 Lion
#QR code generator written in ruby
require 'rubygems'
require 'rqrcode_png'
firstname = "Chan" #姓
lastname = "Tai Man" #名
@Eric-Guo
Eric-Guo / json.rb
Created June 15, 2022 05:03 — forked from kddnewton/json.rb
JSON parser with pattern matching
require "json"
struct = { "a" => 1, "b" => 2, "c" => [1, 2, 3], "d" => [{ "e" => 3 }, nil, false, true, [], {}] }
source = JSON.dump(struct)
tokens = []
index = 0
until source.empty?
tokens <<
@Eric-Guo
Eric-Guo / main.rb
Created February 4, 2022 06:08 — forked from amirrajan/main.rb
DragonRuby Game Toolkit - Shadows (https://amirrajan.itch.io/shadows)
class Game
attr_gtk
def tick
defaults
input
calc
render
end
{
inputs:
[params[:authenticity_token], request.x_csrf_token].map do |token|
Base64.urlsafe_decode64(token)
end.map do |token|
xor_byte_strings(
token[0...AUTHENTICITY_TOKEN_LENGTH],
token[AUTHENTICITY_TOKEN_LENGTH..-1]
)
end,
@Eric-Guo
Eric-Guo / gist:2011069
Created March 10, 2012 10:20
Sublime Text 2 - Useful Shortcuts (Windows 7 CHS)

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands used most towards the top. Sublime also offer full documentation.

Editing

Ctrl+⇧+K delete line
Ctrl+↩ insert line after
Ctrl+⇧+↩ insert line before
Ctrl+⇧+↑ move line (or selection) up
# self editor
$gtk.reset
$mapfile = '/app/main.rb'
$file_source = $gtk.read_file($mapfile).each_line.to_a
$reload_tick = 0
def tick(args)
if args.state.tick_count == 0
args.state.cursor.row = 0
args.state.cursor.col = 0
@Eric-Guo
Eric-Guo / main.rb
Created November 12, 2021 02:56 — forked from amirrajan/main.rb
DragonRuby Game Toolkit VR - Let There Be Light
# https://www.youtube.com/watch?v=S-baJwEjUsk&ab_channel=AmirRajan
class Game
attr_gtk
def tick
grid.origin_center!
defaults
calc
render
@Eric-Guo
Eric-Guo / render_text.rb
Created July 28, 2021 05:18 — forked from cbilski/render_text.rb
A lazy way to wrap strings in dragonruby.
# This breaks when the characters no longer fit on the line. A smarter version would iterate using word/line boundaries
# Sample Usage:
# rect = args.layout.rect(row: 3, col: 12, w: 6, h: 7, dx: 0, dy: 0) # OBJECTIVE
# text = "OBJECTIVE:\n\nMECHs are threatening\nour CITIZENS:\n+ Bring the CITIZENS home.\n+ Destroy the MECHs."
# render_text(args, args.outputs.primitives, rect, text, 1, "/fonts/PixeloidSans.ttf")
#
def render_text(args, pipeline, rect, text, font_size, font)
work = ""
len = text.length
font_h = args.gtk.calcstringbox(text, font_size, font).y
{
"go.useLanguageServer": true,
"editor.formatOnSave": true,
"window.nativeTabs": true,
"editor.glyphMargin": false,
"editor.renderLineHighlight": "none",
"workbench.editor.tabCloseButton": "left",
"workbench.startupEditor": "newUntitledFile",
"window.autoDetectColorScheme": true,
"window.openFilesInNewWindow": "on",