Skip to content

Instantly share code, notes, and snippets.

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(',')") {
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
# 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:
─ lib
├── fosl_ext
│   └── parser.rb
└── fosl_ext.rb
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)

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".

#!/bin/bash
#
# Install nginx on Debian.
#
# Author : Scott Barr
# Date : 7 Jan 2010
#
VERSION=0.8.53
@bradland
bradland / vpnroutes.sh
Created January 17, 2011 05:35
Script for enabling/disabling custom IP routes
#!/bin/bash
# Enables and disables static routes required to access COMPANY resources
# over the VPN. These routes are required because the resources are hosted
# on public IP addresses, but restricted to access coming from specific
# networks.
enableroutes() {
route -nv add -net 4.2.2.1 -interface ppp0
@bradland
bradland / local_ip.rb
Created January 19, 2011 20:55
Return array of local IP addresses
require 'socket'
# Base on answer from http://stackoverflow.com/questions/42566/getting-the-hostname-or-ip-in-ruby-on-rails
# return an array of local IP addresses
def local_ip
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily
UDPSocket.open do |s|
s.connect '4.2.2.1', 1 # as this is UDP, no connection will actually be made
@bradland
bradland / Welcome5by5WebIRC.scpt
Created January 20, 2011 21:03
Colloquy script for welcoming 5by5 web IRC client users.
# modified from http://colloquy.info/extras/details.php?file=8
property prefs : missing value
property prefsPath : missing value
script prefsTemplate
property knownNames : {}
property allowedRooms : {}
end script