Skip to content

Instantly share code, notes, and snippets.

View rmehner's full-sized avatar
🤷‍♀️
¯\_(ツ)_/¯

Robin Mehner rmehner

🤷‍♀️
¯\_(ツ)_/¯
View GitHub Profile
class Ambiguos
def x; 1;
def test
puts x # method x called
x = 2
puts x # variable x
end
end
<?php
class ObjectWithDatabase
{
private $_db;
public function __construct( Database_Interface $database = null )
{
if ($database === null) {
$this->_db = new Database_Mysql();
@rmehner
rmehner / XPath)
Created March 18, 2010 16:36
PHPUnit + Xpath
<?php
require_once 'PHPUnit/Framework.php';
class Xml
{
public function getNavigation()
{
return '<ul id="navigation">
<li><a href="/search">Suche</a></li>
<?php
class NumberCruncher {
public function __call($m, $n) {
switch($m = substr($m, -1, 1)) {
default: return ($m == 'F') ? (9 * $this->C($n[0])) : ($n[0] * ($n[0] * 0.5));
case 'A': return $n[0] + 4;
case 'B': return $n[0] * 3;
case 'D': return ($n[0] == 0) ? (1) : ($n[0] * $this->D($n[0] - 1));
case 'E': return ($n[0] > 1) ? ($this->E($n[0] - 1) + $this->E($n[0] - 2)) : ($n[0]);
case 'G': return $this->D($n[0]) - $this->E($n[0]);
#!/usr/bin/env zsh
if [[ -s "${TM_PROJECT_DIRECTORY}/.rvmrc" ]]
then
source "${TM_PROJECT_DIRECTORY}/.rvmrc"
fi
`which ruby` $*
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Kill all style Attributes</title>
</head>
<body style="color: red;">
<p style="border: 2px solid black;">
Foo
</p>
module Mail
class Message
def body_html
if html_part.present?
html_part.body.to_s
elsif mime_type == 'text/html'
body.to_s
end
end
end
@rmehner
rmehner / gist:702344
Created November 16, 2010 19:34
Delayed Job script, 1.9
#!/usr/bin/env ruby
# -*- ruby -*-
require 'rubygems'
require 'daemon_spawn'
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
class DelayedJobWorker < DaemonSpawn::Base
def start(args)
ENV['RAILS_ENV'] ||= args.first || 'development'
@rmehner
rmehner / rcov.rake
Created January 31, 2011 16:41 — forked from jferris/rcov.rake
if defined?(RSpec)
namespace :rcov do
RSpec::Core::RakeTask.new(:rspec_aggregate) do |task|
task.pattern = 'spec/**/*_spec.rb'
task.rspec_opts = "--format progress"
task.rcov = true
task.rcov_opts = "--rails --exclude osx\/objc,spec,gems\/ " +
"--aggregate tmp/coverage.data"
end
@rmehner
rmehner / i18n_feature_request.rb
Created June 9, 2011 12:31
i18n feature request
# is something like that possible?
I18n.with_scope(:scope) do
t(:foo) # would be the same as t(:foo, scope: :scope)
end