Skip to content

Instantly share code, notes, and snippets.

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

蒼時弦也 elct9620

💦
Level up!!!
View GitHub Profile
@elct9620
elct9620 / bad.rb
Created November 4, 2021 09:15
Ruby Block-based Refactor
class BadObject
def initialize
@internal = 'Coupling'
end
def perform
puts 'Start'
100.times do |i|
puts "Long Code ... #{i} #{@internal}"
end
@elct9620
elct9620 / method.c
Created August 14, 2021 12:43
RubyKaigi 2021 Takeout - mruby VM demo
#include <stdint.h>
#include <stdio.h>
#include <string.h>
static inline uint32_t
bin_to_uint32(const uint8_t *bin)
{
return (uint32_t)bin[0] << 24 |
(uint32_t)bin[1] << 16 |
(uint32_t)bin[2] << 8 |
@elct9620
elct9620 / add.c
Created August 14, 2021 09:12
RubyKaigi 2021 Takeout - mruby VM demo
#include <stdint.h>
#include <stdio.h>
static inline uint32_t
bin_to_uint32(const uint8_t *bin)
{
return (uint32_t)bin[0] << 24 |
(uint32_t)bin[1] << 16 |
(uint32_t)bin[2] << 8 |
(uint32_t)bin[3];
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 3, 2024 14:41
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