Skip to content

Instantly share code, notes, and snippets.

View elct9620's full-sized avatar
💦
Level up!!!

蒼時弦や elct9620

💦
Level up!!!
View GitHub Profile
Puma caught this error: stack level too deep (SystemStackError)
/Users/elct9620/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/core_ext/object/json.rb:174:in `each'
/Users/elct9620/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/core_ext/object/json.rb:174:in `as_json'
/Users/elct9620/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/core_ext/object/json.rb:58:in `as_json'
/Users/elct9620/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/core_ext/object/json.rb:175:in `block in as_json'
/Users/elct9620/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/core_ext/object/json.rb:174:in `each'
/Users/elct9620/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/core_ext/object/json.rb:174:in `as_json'
/Users/elct9620/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-6.1.1/lib/active_suppor
@elct9620
elct9620 / app-tinygo.js
Last active November 12, 2023 18:42
Define JavaScript class inside Golang (WebAssembly)
import 'vendor/tinygo'
const go = new Go();
go.importObject.env['main.defineClass'] = function(namePtr, nameLen, cPtr, cGcPtr, pPtr/*, pGcPtr*/) {
const mem = new DataView(go._inst.exports.memory.buffer)
const decoder = new TextDecoder("utf-8");
const name = decoder.decode(new DataView(go._inst.exports.memory.buffer, namePtr, nameLen));
const constructorID = mem.getUint32(cPtr, true)
@elct9620
elct9620 / benchrmark.rb
Created April 14, 2020 06:07
Ruby's Struct and Class benchmark (bemchmark-ips)
# frozen_string_literal: true
require 'bundler/inline'
require 'ostruct'
gemfile do
gem 'benchmark-ips'
end
GeoStruct = Struct.new(:latitude, :longitude) do
@elct9620
elct9620 / worker_amount_1.log
Last active March 20, 2020 16:06
Tide + Phoneix wrk2 benchmark
[elct9620] test % wrk2 -t4 -c1000 -d30s -R1000 http://localhost:4000/
Running 30s test @ http://localhost:4000/
4 threads and 1000 connections
Thread calibration: mean lat.: 1425.090ms, rate sampling interval: 8970ms
Thread calibration: mean lat.: 1495.687ms, rate sampling interval: 9191ms
Thread calibration: mean lat.: 1444.798ms, rate sampling interval: 8970ms
Thread calibration: mean lat.: 1389.795ms, rate sampling interval: 8962ms
Thread Stats Avg Stdev Max +/- Stdev
Latency 977.94ms 1.51s 9.22s 91.81%
Req/Sec 258.62 7.07 277.00 87.50%
@elct9620
elct9620 / settings.rb
Created March 12, 2020 05:15
Simple settings model for Rails
# frozen_string_literal: true
require "singleton"
class Settings
include Singleton
class << self
delegate_missing_to :instance
end
@elct9620
elct9620 / school.exs
Last active March 10, 2020 12:27
Functional Class Homework
school = [
%{
name: "1A",
teacher: %{
age: 28,
first_name: "Tricia",
last_name: "Garrett"
},
assistants: %{
age: 38,
require 'csv'
require 'json'
require 'open-uri'
class Downloader
SCRIPT_URL = 'SCRIPT_URL'
attr_reader :uri
def initialize
@elct9620
elct9620 / twnic_frozen.rb
Created November 26, 2019 04:51
TWNIC 凍結域名偵測
# frozen_string_literal: true
require 'net/http'
require 'date'
require 'optparse'
require 'json'
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
@elct9620
elct9620 / v2.rb
Last active April 26, 2020 16:40
Thread Pool 實作的簡易 Worker
# frozen_string_literal: true
module Task
# The task executor
#
# @api private
class Worker
# @param manager [Task::Manager] the work belongs to
# @param tasks [Queue] the tasks to execute
#
@elct9620
elct9620 / README.md
Last active January 28, 2022 17:48
CloudFlare Workers Status API

CloudFlare Workers as Status API

In most case, the CloudFlare SLA is greater than our server. So, we can use it as a simple uptime checker.

Usage

  1. Deploy index.js to your CloudFlare Workers, and bind KV which you save the status.
  2. Add updater.rb to your server, and setup cron job to run it
  3. Get node status on any static page with https://your-worker.workers.dev/?node[]=name to fetch node status