Skip to content

Instantly share code, notes, and snippets.

@thieso2
thieso2 / gist:138098
Created June 30, 2009 09:57
emulates Objective-C pose_as call. Demo use-case: add HTTP_PROXY support to Net::HTTP
class Object
def pose_as(klass)
namespace = klass.to_s.split("::")
klass = namespace.pop
if namespace.any?
eval <<-EOT
module ::#{namespace.join("::")}
send(:remove_const, :"#{klass}")
#{klass} = #{self}
@thieso2
thieso2 / require_timings.rb
Created February 23, 2010 07:45
Show require calls with timing
require 'benchmark'
$require_level = 0
module Kernel
alias require_without_timing require
def require(path)
result = seconds = nil
begin
$require_level += 1
class Module
def method_added(symbol)
p caller if symbol == :h
end
end
class ActiveRecord::ConnectionAdapters::AbstractAdapter
def called_by(original_caller)
str = original_caller.reject { |info| !info.match /#{Rails.root}/ }.first
str.gsub(Rails.root,'')
end
def log_info(sql, name, ms)
if @logger && @logger.debug?
name = '%s (%.1fms) %s' % [name || 'SQL', ms, called_by(caller)]
@logger.debug(format_log_entry(name, sql.squeeze(' ')))
[mysqld]
max_allowed_packet      = 16M
innodb_file_per_table
query_cache_size = 32M
innodb_additional_mem_pool_size = 256M
innodb_buffer_pool_size = 512M
innodb_log_buffer_size = 256M
innodb_log_file_size = 256M
#bulk_insert_buffer_size = 256M
innodb_flush_method = O_DSYNC
diff --git a/ext/perftools.c b/ext/perftools.c
index e6f97f1..ace2e01 100644
--- a/ext/perftools.c
+++ b/ext/perftools.c
@@ -159,6 +159,8 @@ static VALUE Isend;
case VM_FRAME_MAGIC_CFUNC:
self = cfp->self;
#ifdef HAVE_METHOD_H
+ if (! cfp->me) break;
+
New file: inline_levenshtein
inline do |builder|
builder.add_link_flags '-lruby'
builder.c_raw <<-EOT
long minimum(long a,long b,long c)
/*Gets the minimum of three values*/
{
long min=a;
if(b<min)
@thieso2
thieso2 / gist:785880
Created January 19, 2011 08:42
crunde init script for solr (bundled with sunspot)
We couldn’t find that file to show.
@thieso2
thieso2 / plat_forms_2011 rake stats
Created January 20, 2011 13:47
rake stats fop tmp8's Plat_Forms Submission 2011 (http://www.plat-forms.org/platforms-2011)
(in /Users/thieso/zips/plat_forms_2011)
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers | 471 | 384 | 14 | 50 | 3 | 5 |
| Helpers | 41 | 38 | 0 | 5 | 0 | 5 |
| Models | 522 | 416 | 11 | 45 | 4 | 7 |
| Libraries | 30 | 27 | 1 | 3 | 3 | 7 |
| Integration tests | 64 | 49 | 3 | 1 | 0 | 47 |
| Functional tests | 592 | 478 | 8 | 1 | 0 | 476 |
<?php
function calculate_total($haehnchen_preis, $haehnchen_anzahl) {
$mein_profit = 100;
return $haehnchen_preis * $haehnchen_anzahl + $mein_profit;
}
?>