Skip to content

Instantly share code, notes, and snippets.

View berkes's full-sized avatar

Bèr Kessels berkes

View GitHub Profile
@berkes
berkes / String.rb
Created October 29, 2012 10:02
String.tenderloverized
class String
# http://confreaks.com/videos/1228-aloharuby2012-keynote-rails-4-and-the-future-of-web
def t13d
if length > 2
return "#{self[0,1]}#{(length - 2)}#{self[-1,1]}"
else
return self
end
end
end
@berkes
berkes / gotcha_isset.php
Created September 20, 2012 08:03
Isset acts weird in PHP.
<?php
function foo($bar = NULL) {
if (isset($bar)) {
print "bar is set\n";
var_dump($bar);
}
else {
print "bar is not set\n";
var_dump($bar);//If not set should throw at least a NOTICE.
php> $are_you_insane_php = (int) 'hello world'
php> var_dump($are_you_insane_php) #=> int(0)
@berkes
berkes / typecast.php
Created June 23, 2012 22:03
gotcha with PHP typecasting
<?php
$amount = 17.50;
print (int) $amount * 100; # => 1700 # My implementation. I was wrong.
print (int) ($amount * 100); # => 1750 # After bugfix. PHP first casts, then multiplies.
6ff235b69503dc6c7b1df425c003413c
@berkes
berkes / product_scopes_decorator.rb
Created February 28, 2012 10:36
Spree Decorator to add a custom ordering scope. Placed in "app/models/spree/product/"
Spree::Product.class_eval do
def self.simple_scopes
[
:ascend_by_random,
:ascend_by_updated_at,
:descend_by_updated_at,
:ascend_by_name,
:descend_by_name,
# Need to have master price scopes here
# This makes them appear in admin/product_groups/edit
1) SomeBarsController GET 'index' should be successful
Failure/Error: get 'index'
ActionController::RoutingError:
No route matches {:controller=>"some_bars"}
2) SomeBarsController GET 'index' should render Hello World
Failure/Error: get 'index'
ActionController::RoutingError:
No route matches {:controller=>"some_bars"}
@berkes
berkes / fucktards.php
Created December 29, 2011 10:08
Why the Fuck is that argument not used to ... ahhh. That is why. Morons!
$client = new SoapClient($cad_url);
$count = count($args);
if ($count == 0) {
$response = $client->$method();
}
elseif ($count == 1) {
$response = $client->$method($args[0]);
}
elseif ($count == 2) {
$response = $client->$method($args[0], $args[1]);
@berkes
berkes / some-form.css
Created December 7, 2011 13:15
WTF. This is /not/ how you make a form field required in Drupal.
.page-CENSORED #edit-somefield-wrapper label {
background: url(../images/required.gif) 40px top no-repeat;
}
<div id="block-views-news-block_3" class="block block-views first region-odd odd region-count-1 count-9 with-block-editing">
<div class="content">
<div class="views_view view view-news view-id-news view-display-id-block_3 view-dom-id-3">
<div class="views-admin-links views-hide">