Skip to content

Instantly share code, notes, and snippets.

Description and reproduction

Running the script axlsx_print_area.rb (provided at end of issue) will produce an Excel workbook that, when unzipped, contains the workbook.xml contents; also provided below. It can be observed that the name attributes of the <definedName> nodes have been altered from their original form. This has a couple of undesirable side-effects.

  1. It breaks behavior specified in the examples (repeating headers). Repeating headers are not actually produced.

  2. Tangentially, it prevents one from using any of the built-in names specified in the source of Axlsx::DefinedName.

  3. It mangles valid defined names, leading to confusion. For example, if the defined name "Example_Range" is specified, it will be converted to "ExampleRange".

require 'axlsx'
require 'pry'
p = Axlsx::Package.new
wb = p.workbook
# Build up a matrix of data
cols = ("A".."L").to_a
rows = (1..100).map do |i|
cols.zip(cols.dup.fill(i.to_s)).map(&:join)
─ lib
├── fosl_ext
│   └── parser.rb
└── fosl_ext.rb
# Allows access to deep hashes by passing an array of keys, which will be used
# in a serial chain of hash key lookups. For example, the array:
# [:one, :two, :three]
# Would translate to the key structure:
# hash[:one][:two][:three]
# Usage:
require 'benchmark/ips'
TEST_STRING = "FooBar" * 10
Benchmark.ips do |x|
x.report("count") do
TEST_STRING.count('[A-Z]')
end
x.report("gsub") do
require 'benchmark'
alias e puts
N = "\n"
N_TIMES = 550_000 # Run it n times.
TEST_STRING = ('abc,def,ghi,jkl,'+N) * 80
Benchmark.bm(24) { |x|
x.report("Testing: split(',')") {
/* ghosttest.c: GHOST vulnerability tester */
/* Credit: http://www.openwall.com/lists/oss-security/2015/01/27/9 */
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define CANARY "in_the_coal_mine"
class ByteBuffer
attr_reader :bytes
# A ByteBuffer accepts encoded string buffers and unpacks them to an
# internal array of bytes stored using fixnum so that binary operations can
# be easily performed.
def initialize(buffer, mode)
case mode
when 'a' # arbitrary string; converts to ascii char code (this is faster than String#ord)
@bytes = buffer.unpack('C*')
@bradland
bradland / script_base.rb
Last active May 20, 2025 14:58
Base Ruby shell scripting template. Uses std-lib only; parses options; traps common signals.
#!/usr/bin/env ruby
# frozen_string_literal: true
require "ostruct"
require "optparse"
require "bigdecimal"
require "csv"
require "pry"
## Embedded ScriptUtils library; because, scripting!
#!/usr/bin/env ruby
require 'benchmark/ips'
require 'time'
if defined?(JRUBY_VERSION)
JODA_FMT = org.joda.time.format::DateTimeFormat.for_pattern("Y-M-d H:m:s Z")
end
def joda_time(time)