Skip to content

Instantly share code, notes, and snippets.

View brand-it's full-sized avatar

Brandt Lareau brand-it

View GitHub Profile
temp = Tempfile.new(['document_content', '.html'])
temp.write(options[:document_content])
temp.close
prince_cmd = "docker run --network host -v /var/folders:/var/folders -v #{logfile}:#{logfile} --rm conga/prince prince -v --javascript --log=#{logfile} --baseurl=http://host.docker.internal:3000 #{option_str} #{temp.path} - -o #{outfile.path}"
class << self
protected
def gsub_text_nodes_only!(html:, placeholder_name:, placeholder_value:)
fragment = Nokogiri::HTML.fragment(html)
fragment.traverse do |node|
next unless node.text?
# Can't use normal gsub! because it makes a copy of the content memory that is not attached
# to the node. Have to use the setter provided by nokogiri to update the node
class Config
attr_accessor :total_threads, :files_per_second, :logger
class << self
def info
@info ||= Config.new
end
end
@brand-it
brand-it / create_ssl.sh
Last active June 9, 2022 16:05
This build tinderbox ssl certs for local development. Can be used for other things but. Also designed to add it to Mac credentials
#!/usr/bin/env ruby
require 'fileutils'
require 'tempfile'
# cn = '*.tb.local.vhost'
# server_name = 'dev.tb.local.vhost'
# admin_server_name = 'admin.tb.local.vhost'
@brand-it
brand-it / index.html
Last active October 5, 2018 16:19
here is some code or testing.
<table style="width: 100%; height: 304px;">
<tbody>
<tr style="height: 21px;">
<th style="width: 50%; height: 21px;">Token Name</th>
<th style="width: 50%; height: 21px;">Value</th>
</tr>
<tr style="height: 21px;">
<td style="width: 50%; height: 21px;">Proposal Title</td>
<td style="width: 50%; height: 21px;"><span allowstyling="true" data-name="proposal_title" data-type="string"
data-variable-content="inline" data-source="" data-raw-value="Cy Kosis" class="inline-variable mceNonEditable"
@brand-it
brand-it / gem_installer.rb
Created October 1, 2018 15:21
I have had it come up some times where I need a isolated gem installer using ruby. Found this is a nice way to handle that problem. Used it in https://github.com/newdark/faker-alfred-workflow
require 'fileutils'
require 'rubygems'
require 'rubygems/gem_runner'
require 'rubygems/exceptions'
require File.expand_path('./logger', __dir__).to_s
ENV['GEM_HOME'] = File.expand_path('gems', __dir__).to_s
FileUtils.mkdir_p(ENV['GEM_HOME'])
ENV['GEM_PATH'] = "#{ENV['GEM_HOME']}:/var/lib/ruby/gems/1.8"
Gem.clear_paths
s3 = S3Util.new
s3.bucket.objects.each do |object|
if s3.bucket.object(object.key).server_side_encryption
puts "Skipping #{object.key}"
next
end
puts "Encrypting #{object.key}"
s3.turn_on_encryption(object.key)
end
@brand-it
brand-it / loopers_script.rb
Last active August 24, 2018 20:34
This is a converter for Paperclip to from old url Patters to a new one. This can be helpful if you have to change maybe the bucket name or just change the path in which they are stored.
require 'paperclip_pattern_processor'
processor = PaperclipPatternProcessor.new
Page.find_each do |page|
urls = page.body.scan(/"(https?:\/\/[\S]+s3.amazonaws.com[\S]+?)"/).flatten.uniq
urls.each do |url|
page.body.gsub!(url, processor.upgrade_url(url))
end
page.save!
end
@brand-it
brand-it / ugh certs suck
Last active June 26, 2018 22:19
This is a fix for chrome as it turns out that chrome decided to be different
openssl req -newkey rsa:2048 -x509 -nodes -keyout localhost.key -new -out localhost.crt -subj /CN=\*.tb.local.vhost -reqexts SAN -extensions SAN -days 3650 -config <(cat /System/Library/OpenSSL/openssl.cnf <(printf '[SAN]\nsubjectAltName=DNS:*.tb.local.vhost'))
class TestsController < ApplicationController
before_action :set_test, only: [:show, :edit, :update, :destroy]
# GET /tests
# GET /tests.json
def index
@tests = Test.all
end
# GET /tests/1