Skip to content

Instantly share code, notes, and snippets.

View berkes's full-sized avatar

Bèr Kessels berkes

View GitHub Profile
@berkes
berkes / service.rb
Created December 31, 2010 11:42
example with identica.
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Service
include MongoMapper::Document
include ActionView::Helpers::TextHelper
belongs_to :user
class Services::Twitter < Service
MAX_CHARACTERS = 140
def post(post, url='')
Rails.logger.debug("event=post_to_service type=twitter sender_id=#{self.user_id}")
message = public_message(post, url)
twitter_key = SERVICES['twitter']['consumer_key']
twitter_consumer_secret = SERVICES['twitter']['consumer_secret']
@berkes
berkes / croptoelie.rb
Created February 11, 2011 09:50
SmartCropper testbed. Use in irb as: load 'croptoelie.rb'; CropToelie.new('not_too_big_image.jpg')
require 'RMagick'
class CropToelie
include Magick
attr_accessor :image
attr_accessor :width
attr_accessor :height
attr_accessor :step_size
def initialize image_path
@berkes
berkes / gist:829242
Created February 16, 2011 11:39
ZOMGWTFBBQ! Maybe he is better as a carpenter?
<?php
/*
Plugin Name: WP-TweetButton
Version: 1.7.5
Description: Automatically adds the new Official Twitter Tweet Button to your Blog.Easily Customizable from the Dashboard(with Tweet Syntax, hash tags and much more.).
Author: CoderPlus
Author URI: http://coderplus.com
Plugin URI: http://coderplus.com/2010/08/twitter-tweet-button-plugin-for-wordpress/
wp-tweetbutton
*/
@berkes
berkes / coding_guideline_helper.php
Created November 3, 2011 15:28
Purrfect Drupal Coding Guideline Helper: Completely randomise your array and object usage.
<?php
/**
* Usage
* $inconsistent_view_thingy = views_get_view("some_view_name");
* $more_inconsistent_view_thingy = rand_obj_or_array($inconsistent_view_thingy);
*/
function rand_obj_or_array($thing) {
$det = rand(0,2);
if (isset($weather_data[$column]) && $weather_data[$column] && isset($mapping[$weather_data[$column]]) && $mapping[$weather_data[$column]]) {
if (isset($field['weatherfield_settings']['cs'][$column]['s'][$mid]['g']['options_files'][$mapping[$weather_data[$column]]]) && isset($field['weatherfield_settings']['cs'][$column]['s'][$mid]['g']['options_files'][$mapping[$weather_data[$column]]]['fid'])) {
if (isset($files[$field['field_name']][$field['weatherfield_settings']['cs'][$column]['s'][$mid]['g']['options_files'][$mapping[$weather_data[$column]]]['fid']])) {
$column_output = theme('image', $files[$field['field_name']][$field['weatherfield_settings']['cs'][$column]['s'][$mid]['g']['options_files'][$mapping[$weather_data[$column]]]['fid']]->filepath);
}
}
}
<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">
@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;
}
@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]);
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"}