jsPDF is a low-level library for building PDF files in JavaScript.
It does not support multiline text.
It does, text accept array, just split with splitTextToSize
Based on: https://gist.github.com/AnalyzePlatypus/c54d520e9bd5b5f662aeb0276e3f01a4
ARGF.each_line { |line| puts line.chomp.upcase.gsub(//, " ").gsub(/[^A-Z0-9:;=+_"$@ -]/, "-").gsub(/[A-Z0-9:;=+_"$@-]/, Hash[*%w(A .- B -... C -.-. D -.. E . F ..-. G --. H .... I .. J .--- K -.- L .-.. M -- N -. O --- P .--. Q --.- R .-. S ... T - U ..- V ...- W .-- X -..- Y -.-- Z --.. . .-.-.- , --..-- ? ..--.. / -..-. @ .--.-. 1 .---- 2 ..--- 3 ...-- 4 ....- 5 ..... 6 -.... 7 --... 8 ---.. 9 ----. 0 ----- : ---... ; -.-.-. = -...- + .-.-. - -....- _ ..--.- " .-..-. $ ...-..- @ .--.-.)]).strip } |
require 'thread' # for Mutex: Ruby doesn't provide out of the box thread-safe arrays | |
class ThreadPool | |
def initialize(max_threads = 10) | |
@pool = SizedQueue.new(max_threads) | |
max_threads.times{ @pool << 1 } | |
@mutex = Mutex.new | |
@running_threads = [] | |
end |
jsPDF is a low-level library for building PDF files in JavaScript.
It does not support multiline text.
It does, text accept array, just split with splitTextToSize
Based on: https://gist.github.com/AnalyzePlatypus/c54d520e9bd5b5f662aeb0276e3f01a4
function byteLength(str) { | |
// returns the byte length of an utf8 string | |
var s = str.length; | |
for (var i=str.length-1; i>=0; i--) { | |
var code = str.charCodeAt(i); | |
if (code > 0x7f && code <= 0x7ff) s++; | |
else if (code > 0x7ff && code <= 0xffff) s+=2; | |
if (code >= 0xDC00 && code <= 0xDFFF) i--; //trail surrogate | |
} | |
return s; |
// usage: {{ file.size | prettyBytes }} | |
Vue.filter('prettyBytes', function (num) { | |
// jacked from: https://github.com/sindresorhus/pretty-bytes | |
if (typeof num !== 'number' || isNaN(num)) { | |
throw new TypeError('Expected a number'); | |
} | |
var exponent; | |
var unit; | |
var neg = num < 0; |
# config/initializers/redis.rb | |
require 'redis' | |
# Disables the `flushdb` and `flushall` commands. | |
class Redis | |
module DangerousCommands | |
def flushdb | |
raise 'This is EXTREMELY DANGEROUS! If you really want to EMPTY THE ENTIRE DATABASE, do it from `redis-cli`.' | |
# You could call `super` here if you want to allow access in some circumstances. | |
end |
if ENV['REDIS_ACCESS_MODE'] == 'readonly' | |
class Redis | |
class Client | |
WRITE_COMMANDS = ::Rails.cache.data.command.map { |a| a[0] if a[2].include?('write') }.compact.to_set.freeze | |
def process(commands) | |
if commands.flatten.any? { |c| WRITE_COMMANDS.include?(c.to_s) } | |
raise NotImplementedError, "REDIS_ACCESS_MODE is set to 'readonly', disallowing writes" | |
end |
# Add to `spec/support/database_state_loader.rb` | |
class DatabaseStateLoader | |
class EnvironmentError < RuntimeError; end | |
def self.load(path) | |
new(path).load | |
end | |
def initialize(path) |
#!/usr/bin/env bash | |
BUCKET=$1 | |
CWD=$(pwd) | |
if [[ -n $1 ]]; then | |
aws s3 sync s3://$BUCKET/cf-logs . | |
cat *.gz > combined.log.gz | |
find $CWD ! -name 'combined.log.gz' -name '*.gz' -type f -exec rm -f {} + | |
gzip -d combined.log.gz |