Skip to content

Instantly share code, notes, and snippets.

@dolzenko
dolzenko / acts_as.rb
Created June 4, 2009 08:52
My attempt at abstracting acts_as_* pattern
class Class
def acts_as(*args)
modules_with_options = []
for arg in args
if arg.is_a?(Module)
modules_with_options << [arg]
elsif arg.is_a?(Hash)
raise ArgumentError, "Options without module" unless modules_with_options[-1][0].is_a?(Module)
modules_with_options[-1][1] = arg
end
@dolzenko
dolzenko / tinymce-content.css
Created July 14, 2009 12:23
Style un-reset for TinyMCE content inserted on the pages with YUI CSS reset
/* Style un-reset for TinyMCE content inserted on the pages with YUI CSS reset.
* Added along with YUI CSS reset to the content_css option of TinyMCE and to the page on which TinyMCE content should be displayed.
*/
/* This part is based on tinymce-3.2.1.1\jscripts\tiny_mce\themes\advanced\skins\default\content.css */
.mceContentBody,
.mceContentBody td,
.mceContentBody pre
{
@dolzenko
dolzenko / sum_with_enumerable_fallback
Created October 19, 2009 15:05
sum_with_enumerable_fallback
ActiveRecord::Associations::AssociationCollection.class_eval do
def sum_with_enumerable_fallback(*args, &block)
if args.empty? && block
to_a.sum(&block)
else
sum_without_enumerable_fallback(*args)
end
end
alias_method_chain :sum, :enumerable_fallback
@dolzenko
dolzenko / Dead Simple JavaScript Class Pattern (jQuery compatible).js
Created October 27, 2009 20:39
Dead Simple JavaScript Class Pattern (jQuery compatible)
var MyClass = function() {
var self = this;
$.extend(self, {
initialize: function(constructor_arg1, constructor_arg2) {
self.method();
},
method: function() {
}
// other methods below...
@dolzenko
dolzenko / parse_rails_log_file_using_enumerable_slice_before.rb
Created March 9, 2010 19:49
parse_rails_log_file_using_enumerable_slice_before.rb
def parse_rails_log_file(file)
# Remove all empty lines
lines = file.each_line.map(&:strip).reject(&:empty?)
# Use +Enumerable#slice_before+ to slice log file into sections for each request
lines.slice_before(/Started (GET|POST|PUT|DELETE)/).each_with_object({}) do |request_log, totals|
# Only include successfully finished actions in report
if duration = request_log.last[/Completed 200 OK in (?<duration>\d+)ms/, :duration]
action_name = request_log.first[/Started (GET|POST|PUT|DELETE) "(?<action>.+?)" for/, :action]
totals[action_name] ||= 0
@dolzenko
dolzenko / parse_ini_file_using_enumerable_slice_before.rb
Created March 9, 2010 19:54
parse_ini_file_using_enumerable_slice_before.rb
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) }]
@dolzenko
dolzenko / extract_tables_from_dump_using_enumerable_slice_before.rb
Created March 9, 2010 20:33
extract_tables_from_dump_using_enumerable_slice_before
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
@dolzenko
dolzenko / grep_rails_log_file.rb
Created March 10, 2010 11:44
grep_rails_log_file
#!/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
@dolzenko
dolzenko / isolate.bat
Created March 20, 2010 08:26
Quietly enjoy your reclusive tendencies
taskkill /f /im gnotify.exe
taskkill /f /im skype.exe
taskkill /f /im miranda32.exe
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__)