Skip to content

Instantly share code, notes, and snippets.

@tdl
tdl / XML_to_JSON.rb
Created July 9, 2013 15:33
Convert XML to JSON
# inspired by http://stackoverflow.com/questions/1530324/ruby-xml-to-json-converter
require 'json'
require 'active_support/core_ext/hash'
STDOUT.write(JSON.pretty_generate(Hash.from_xml(ARGF.read)))
@tdl
tdl / pretty_print_YAML
Created July 9, 2013 09:57
Pretty print YAML with Ruby
ruby -ryaml -rpp -e "pp YAML.load(STDIN)" < infile > outfile
@tdl
tdl / pretty_print_JSON
Created July 9, 2013 09:14
Pretty-print JSON with Ruby
ruby -rjson -e "STDOUT.write JSON.pretty_generate(JSON.load(STDIN))" < infile > outfile
@tdl
tdl / Elasticsearch_users.md
Last active December 17, 2015 23:58
Well-known companies / services using ElasticSearch
@tdl
tdl / application.rb
Last active January 18, 2021 07:11
Hacky Rack middleware to get backtrace of hung Unicorn workers
# config/application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(:default, Rails.env)
module MyApp
class Application < Rails::Application
# configure Rails to inject this middleware. Must be at least after Rails logger!
@tdl
tdl / Gemfile
Last active December 17, 2015 06:19
Using MiniProfiler in production on Heroku
# it's best to depend on trunk of MiniProfiler, e.g. due to the issue I had with
# graphs not showing up over HTTPS which is fixed in
# https://github.com/SamSaffron/MiniProfiler/commit/831b917e70d57bc3c03858c46b3c5828f73e3f35
gem 'rack-mini-profiler', git: 'git://github.com/SamSaffron/MiniProfiler.git'
@tdl
tdl / xml-de-tag
Last active December 14, 2015 05:09
De-tag XML
ruby -rnokogiri -ropen-uri -e 'puts Nokogiri::XML(open("http://www.w3schools.com/xml/note.xml")).xpath("//text()").to_s'
@tdl
tdl / FTP script
Created February 23, 2013 10:48
FTP script for uploading a file to a remote host
open <hostname>
<user>
<pass>
binary
put <filename>
quit
@tdl
tdl / gist:4193751
Created December 3, 2012 09:04
Batch rename on Unix
# change filenames, replacing "fgh" by "abc"
for f in fgh*; do mv "$f" "${f/fgh/abc}";done