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
# as a String | |
HOME = ENV['HOME'] || File.expand_path("~#{Etc.getlogin}") | |
# as a Pathname | |
HOME = Pathname.new(ENV['HOME'] || File.expand_path("~#{Etc.getlogin}")) |
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
#!/usr/bin/env ruby | |
# A quick and dirty implementation of an HTTP proxy server in Ruby | |
# because I did not want to install anything. | |
# | |
# Copyright (C) 2009-2014 Torsten Becker <torsten.becker@gmail.com> | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining | |
# a copy of this software and associated documentation files (the | |
# "Software"), to deal in the Software without restriction, including | |
# without limitation the rights to use, copy, modify, merge, publish, |
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
#!/usr/bin/env ruby | |
require 'pp' | |
def ruby_repl processor = nil | |
unless (processor && Proc === processor) || block_given? | |
warn "Please invoke `ruby_repl` with a block or a proc..." | |
else | |
in_pry = Kernel.const_defined?("Pry::ColorPrinter") | |
cmd_count = 0 # for use in the command prompt |
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
# | |
# This first version should work on Mac OS X and Linux, but it spawns a process | |
# | |
# the number of TCP connections owned by the process. | |
def Process.tcp_count() `lsof -l -n -P -p #{Process.pid} -a -i tcp | egrep -v '^COMMAND' | wc -l`.chomp.to_i ; end |
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
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" |
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
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' |
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
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' |
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
# 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" |
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
# | |
# 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 |
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
# | |
# 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 |
OlderNewer