Skip to content

Instantly share code, notes, and snippets.

View pvdb's full-sized avatar
🖥️
Making computers do things!

Peter Vandenberk pvdb

🖥️
Making computers do things!
View GitHub Profile
private
def mediainfo!
`#{@mediainfo_binary} #{@full_filename}`
end
>> require 'mediainfo'
=> true
>> mediainfo = Mediainfo.new "foo(bar).mov"
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `mediainfo foo(bar).mov'
private
def mediainfo!
raw_response = `#{@mediainfo_binary} #{@escaped_full_filename}`
raise "Execution of #{mediainfo_binary} failed!" unless $? == 0
return raw_response
end
>> require 'mediainfo'
=> true
>> mediainfo = Mediainfo.new "foo(bar).mov"
private
def mediainfo!
# ANSI-C quoting: http://www.faqs.org/docs/bashman/bashref_12.html
@escaped_full_filename = @full_filename.gsub(/\\|'/) { |c| "\\#{c}" }
raw_response = `#{@mediainfo_binary} $'#{@escaped_full_filename}'`
raise "Execution of #{mediainfo_binary} failed!" unless $? == 0
return raw_response
end
>> require 'mediainfo'
# question asked on aardvark.com: http://vark.com/t/b27d66
# Is there a ruby function to find the shortest and longest string inside an array?
# (my array will only store a bunch of stirngs)
# Here's a snippet of Ruby code that should get you going...
>> %w{ foo bar blegga very-long-string }.sort { |a, b| a.length <=> b.length }.first
=> "foo"
>> %w{ foo bar blegga very-long-string }.sort { |a, b| a.length <=> b.length }.last
=> "very-long-string"
#
# e.g. embedded tab "\t" and newline "\n" characters
#
>> puts 'first\tsecond\tthird'
first\tsecond\tthird
=> nil
>> puts "first\tsecond\tthird"
first second third
=> nil
#
# ActiveRecord SQL Logging on the Rails Console
# ---------------------------------------------
#
# Various blog posts out there show you how to log all SQL statements
# executed by ActiveRecord to STDOUT when you're in a Rails console:
#
# * http://robots.thoughtbot.com/post/159806033/irb-script-console-tips
# * http://weblog.jamisbuck.org/2007/1/8/watching-activerecord-do-it-s-thing
# * http://toolmantim.com/thoughts/system_wide_script_console_logging
#
# ActiveRecord SQL Logging on the Rails Console - revisited/updated
# -----------------------------------------------------------------
#
# If you're living on the edge ("edge Rails", that is) and would like to
# log all SQL statements executed by ActiveRecord to STDOUT when you're
# in a Rails console, then the ConsoleLogSubscriber class is for you!
#
# Notes:
#
#
# http://github.com/thoughtbot/paperclip/issues/issue/247
#
#
# put this in the relevant section of your config/application.rb
#
config.after_initialize do
@pvdb
pvdb / list_targets.sh
Last active November 8, 2023 08:18
List all targets (sometimes incorrectly referred to as "goals") in a GNU Makefile
#
# this gist can be used to list all targets, or - more correctly - rules,
# that are defined in a Makefile (and possibly other included Makefiles)
# and is inspired by Jack Kelly's reply to a StackOverflow question:
#
# http://stackoverflow.com/questions/3063507/list-goals-targets-in-gnu-make/3632592#3632592
#
# I also found this script - http://www.shelldorado.com/scripts/cmds/targets - which does
# something similar using awk, but it extracts targets from the "static" rules from a single
# Makefile, meaning it ignores any included Makefiles, as well as targets from "dynamic" rules
@pvdb
pvdb / deploy.md
Created March 13, 2011 10:09
Capistrano start/stop/restart tasks for Phusion Passsenger Standalone

With the introduction of Phusion Passenger Standalone, some of the established wisdom with regards to Capistrano tasks for managing Passenger are a tad outdated.

In particular, the start and stop tasks for Passenger are typically NOOPs, and only the restart task is deemed relevant. This is arguably no longer the case for standalone Passenger, where start and stop tasks do make sense, as they did back in the mongrel days.

The following Capistrano tasks illustrate how to start, stop and restart a standalone Passenger setup.

These tasks are for a Passenger setup that uses Unix domain sockets, but they can easily be modified for Passenger instances configured for TCP sockets.

    namespace :deploy do

task :start, :roles => :app, :except => { :no_release => t