Skip to content

Instantly share code, notes, and snippets.

@amw
amw / binary-encoding.rb
Created July 11, 2015 19:52
BSON::Binary error when data is non-utf8 compatible string
require "bson"
require "digest/sha2"
d = Digest::SHA256.new
d << "test"
string = d.digest
puts string.encoding
binary = BSON::Binary.new string
puts binary.to_bson
@amw
amw / assets.rake
Last active August 29, 2015 14:21
Preparing compressed (gzipped) Rails assets for Nginx mod_gzip_static
# lib/tasks/assets.rake
namespace :assets do
ManifestPattern = /^manifest-[0-9a-f]{32}\.json$/
ExtensionsToCompress = %w{.js .css .json}.freeze
desc "GZip assets"
task :compress do
files = Pathname.glob(Rails.root.join('public/assets/**/*')).map do |file|
next unless file.extname.in? ExtensionsToCompress