View h265_reencode.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Re-encode video files with the more efficient h.265 file format. | |
# | |
# The original file is appended with the extension `.original` once successfully converted. | |
# The new file has the .MOV extension. | |
# | |
require 'pathname' | |
EXTENSIONS = "m2ts,flv,mov,wmv,avi,mp4,mpg,m4a,3gp,3g2,mj2" |
View sftp.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pty' | |
require 'expect' | |
require 'semantic_logger' | |
# Sftp that works on both Ruby and JRuby. | |
# | |
# Example Usage: | |
# Sftp.upload( | |
# user: 'friend', | |
# password: 'secure', |
View autoload_patch.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fixes "LoadError" "no such file to load" on JRuby 1.7 | |
# Place at the top of application.rb | |
# Override Kernel#autoload and Module#autoload to #require when Web Server or Worker | |
# so that classes are all loaded in highly concurrent environments | |
# Also forces the code to be loaded up front instead of on demand in production | |
begin | |
# Since Rails has not yet been loaded we have to use the env vars | |
rails_env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development" | |
if (['production', 'release', 'hotfix'].include?(rails_env)) |
View my_app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# puma - Generic Red Hat Startup script for Puma | |
# chkconfig: 35 95 05 | |
# description: Generic Puma Startup Script | |
# processname: puma | |
# config: /etc/'filename'.conf | |
# pidfile: /var/run/puma/'filename'.pid |
View active_record_connection_adapters_jdbc_adapter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if defined?(Java) | |
class ActiveRecord::ConnectionAdapters::JdbcAdapter | |
# Returns each row as a hash | |
# Example: | |
# Inquiry.connection.exec_query_each('select * from inquiries') do |row| | |
# ap row | |
# end | |
def exec_query_each(sql, name = 'SQL', binds = [], &block) | |
log(sql, name) { @connection.exec_query_each(sql, binds, &block) } | |
end |
View upsert.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Perform an upsert. | |
# | |
# Insert a new document using the supplied data hash | |
# If the insert fails due to a duplicate record then the `update` values | |
# are applied. | |
# | |
# Example: | |
# | |
# # Values to insert | |
# insert = { |
View gist:e5e6b0bf01d6837624d4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'thread_safe' | |
require 'semantic_logger' | |
require 'gene_pool' | |
# Require original code since it contains more than just this class | |
require 'active_record/connection_adapters/abstract/connection_pool' | |
module ActiveRecord | |
# Not Used. Connection are no longer timed out | |
# A warning is logged when the connection time is exceeded | |
class ConnectionTimeoutError < ConnectionNotEstablished |
View redis_connection_pool.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Implement a Redis Connection Pool | |
# | |
# Convenience methods | |
# Instead of having to write: | |
# redis_pool.perform {|redis| redis.get('key')} | |
# The following can be used | |
# redis_pool.get('key') | |
# | |
# This applies to all Redis methods except quit. RedisPool#quit calls quit | |
# on all instances of Redis already in the pool |
View collection.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# NOTE: This gist is now deprecated and has been moved into a gem: https://github.com/reidmorrison/mongo_ha | |
# | |
require 'mongo/collection' | |
module Mongo | |
class Collection | |
alias_method :find_one_original, :find_one | |
def find_one(*args) |