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
def parse_ini_file(file) | |
# Use +Enumerable#slice_before+ to slice ini file into sections where | |
# start of new section is detected with regexp matching the opening square bracket | |
file.each_line.slice_before(/\[/).each_with_object({}) do |section, config| | |
# Remove the first element which is the section header and extract header name | |
section_name = section.shift[/\[(?<section_name>.+?)\]/, :section_name] # use Oniguruma's named capture | |
# Use Hash[] class method to create parameters hash from key/value assoc array | |
section_parameters = Hash[section.map { |parameter| parameter.split("=").map(&:strip) }] |
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 ARGV.size < 1 | |
puts "Use like mysqldump database_name | ./#{ $PROGRAM_NAME } table_name[s]" | |
exit(0) | |
end | |
# Dump for each table in standard mysqldump output is started with the line like: | |
# | |
# -- Table structure for table `access_rights` | |
# | |
# Use +Enumerable#slice_before+ to slice the whole dump into sections per table |
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 | |
if ARGV.empty? | |
puts <<-USAGE | |
Use like tail -f log/production.log | #{ $PROGRAM_NAME } request_regexp | |
Examples: | |
Show only local requests: | |
tail -f log/production.log | #{ $PROGRAM_NAME } 127.0.0.1 |
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
taskkill /f /im gnotify.exe | |
taskkill /f /im skype.exe | |
taskkill /f /im miranda32.exe |
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
diff --git a/ext/internal/node/node_type_descrip.c.rpp b/ext/internal/node/node_type_descrip.c.rpp | |
index 10ae8a3..5ae8ca4 100644 | |
--- a/ext/internal/node/node_type_descrip.c.rpp | |
+++ b/ext/internal/node/node_type_descrip.c.rpp | |
@@ -3,7 +3,7 @@ | |
Node_Type_Descrip node_type_descrips_unsorted[] = { | |
#ruby <<END | |
-require 'node_type_descrip' | |
+require File.expand_path('../node_type_descrip', __FILE__) |
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
# Check Thomas Sawyer take on the problem http://github.com/rubyworks/paramix | |
module IncludableWithOptions | |
class << self | |
attr_accessor :last_default_options | |
end | |
def self.included(includable_with_options) | |
%w(string/methodize kernel/constant module/basename module/spacename).each { |facets_core_ext| require "facets/#{ facets_core_ext }" } | |
raise "IncludableWithOptions should be included by the Module" unless includable_with_options.instance_of?(Module) |
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
module TryBlock | |
def self.install! | |
unless Object.include?(self) | |
Object.send(:include, self) | |
Object.send(:public, :try_block) | |
end | |
end | |
def self.is_nil_exception_message?(message) | |
message =~ /You have a nil object when you didn't expect it/ || |
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
# Safe way to intercept IO stream | |
# where just replacing STDOUT doesn't work: | |
# http://rubyforge.org/tracker/index.php?func=detail&aid=5217&group_id=426&atid=1698 | |
# | |
module IoInterceptor | |
def intercept | |
begin | |
@intercept = true | |
@intercepted = "" | |
yield |
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
# ## ShellOut | |
# | |
# Provides a convenient feature-rich way to "shell out" to external commands. | |
# Most useful features come from using `PTY` to execute the command. Not available | |
# on Windows, `Kernel#system` will be used instead. | |
# | |
# ## Features | |
# | |
# ### Interruption | |
# |
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 "net/http" | |
Net::HTTP.module_eval do | |
def D(msg) | |
(@debug_output ||= STDERR) << msg << "\n" | |
end | |
end |