Skip to content

Instantly share code, notes, and snippets.

View martinemde's full-sized avatar
🥰

Martin Emde martinemde

🥰
View GitHub Profile
require "zlib"
File.open("test/fixtures/ruby-progressbar-1.13.0.gem.data.tar.gz", "rb") do |file|
Zlib::GzipReader.wrap(file) do |gzio|
loop do
break if gzio.eof?
puts gzio.readpartial(16_384).size
puts "not eof" unless gzio.eof?
end
end
@martinemde
martinemde / nameerror.patch
Last active March 16, 2023 21:19
Patch to a basic rails app to make zeitwerk fail when the constant is loaded just fine but class ancestry changed between setup and load.
commit e123c71f6b614b694c6efb1c07c3ba86e974a510
Author: Martin Emde <martin.emde@gmail.com>
Date: Thu Mar 16 14:01:43 2023 -0700
Trigger the bug
diff --git a/Gemfile b/Gemfile
index 4f9b666..e7f485d 100644
--- a/Gemfile
+++ b/Gemfile
@martinemde
martinemde / rake-13.0.6.sha256
Created March 15, 2023 15:51
Example output of a .sha256 file for rake 13.0.6
104aa09a6f450996c4a25b11d214d9060b9c5b18 History.rdoc
c95ae329fc7b2e1ddae43c9a690f5dcc21e8d5a5 MIT-LICENSE
50f9b5771ab55600bd4c7f00ffa9936b797be596 README.rdoc
19b6b9b33031d4fd1567fb334d162c4fd3c82a32 doc/command_line_usage.rdoc
5acb0fc9d5fa34ca1ad149a1ff2eed5be85e1864 doc/example/Rakefile1
aaf916075123108234a2d4ef40cb77db93ae92fe doc/example/Rakefile2
46456e92c15ef4c3d2bd2ad190404fc4988642f5 doc/example/a.c
d2906ce3ae7db5229af52c84ef84736f56128d18 doc/example/b.c
7a042fdfeeb7316feca1cf5fd020fed7bd4c0aec doc/example/main.c
d81309b30330f1d227256d202d403ab786d85a57 doc/glossary.rdoc
def process_abuser_flags(user, params)
user_flags = user.abuser_flags
AbuserFlag.abuse_types.keys.each do |abuse_type|
strikes = params[abuse_type + "_strikes"].to_i
next unless strikes != 0
current_flag = user_flags.find { |flag| flag.abuse_type == abuse_type }
if current_flag.nil? && strikes != 0
# encoding:ascii-8bit
require 'bacon/colored_output'
require 'rack/utf8_sanitizer'
require 'memory_profiler'
report = MemoryProfiler.report(allow_files: "lib/rack/utf8_sanitizer") do
describe Rack::UTF8Sanitizer do
# ... SNIP ...
@martinemde
martinemde / bench.rb
Last active March 7, 2016 16:34
Compare s.hex.chr vs [s.hex].pack('C') vs [s.hex].pack(C)
require 'benchmark/ips'
require 'securerandom'
Benchmark.ips do |x|
C = 'C'.freeze
DATA = (1..1_000_000).map { SecureRandom.hex(1) }
x.report("hex.chr") do |times|
i = 0
while i < times
@martinemde
martinemde / tests-master.txt
Last active March 7, 2016 00:49
rack-utf8_sanitizer memory_profiler
Rack::UTF8Sanitizer
with invalid UTF-8 input
- sanitizes plaintext entity (HTTP_USER_AGENT)
- sanitizes URI-like entity (REQUEST_PATH)
with invalid, incorrectly percent-encoded UTF-8 URI input
- sanitizes URI-like entity (REQUEST_PATH)
with invalid ASCII-8BIT input
- sanitizes plaintext entity (HTTP_USER_AGENT)
- sanitizes URI-like entity (REQUEST_PATH)
with invalid, incorrectly percent-encoded ASCII-8BIT URI input
~: rvm install 1.9.3
Installing Ruby from source to: /Users/martinemde/.rvm/rubies/ruby-1.9.3-p0, this may take a while depending on your cpu(s)...
ruby-1.9.3-p0 - #fetching
ruby-1.9.3-p0 - #downloading ruby-1.9.3-p0, this may take a while depending on your connection...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 9330k 100 9330k 0 0 1337k 0 0:00:06 0:00:06 --:--:-- 1869k
ruby-1.9.3-p0 - #extracting ruby-1.9.3-p0 to /Users/martinemde/.rvm/src/ruby-1.9.3-p0
ruby-1.9.3-p0 - #extracted to /Users/martinemde/.rvm/src/ruby-1.9.3-p0
@martinemde
martinemde / cipher_error.rb
Created December 28, 2011 22:59
The following script will raise a CipherError in ruby 1.9 unless the force_encoding('binary') line is uncommented.
#!/usr/bin/env ruby
# encoding: UTF-8
require 'net/ssh'
# This example script should output: ☃
#
#
hostname = 'ec2-184-73-243-165.compute-1.amazonaws.com'
username = 'deploy'
command = "echo ' ☃ '"
@martinemde
martinemde / gist:1522731
Created December 27, 2011 04:32
This might also work (not working code, just an idea)
class Object
def self.required_attr_accessor(meth, default)
class_eval <<-END
def #{meth}=(var)
raise NilError unless var
@#{meth} = var
end
def #{meth}
@#{meth} || #{meth}_default
end