<?php
/*
$foo = {
...

PHP JSON Literals in PHP

by Adam, May 31, 2011 22:13, 2 refactorings, tagged with json, preprocessor, variables

On a forum I was reading, s...

A8d3f35baafdaea851914b17dae9e1fc Talk
#ifndef _SPLIT_H_
#define _SPLIT_H_
...

C On A Java-like function split

by Adam, September 17, 2008 18:54
A8d3f35baafdaea851914b17dae9e1fc Talk
@feedbacks.each do |feedback|
  data.each do |key,value|
    question = feedback.send("question#{key + 1}")
...

Ruby On Horrible loop

by Adam, September 17, 2008 16:34 Star_fullStar_fullStar_fullStar_full
A8d3f35baafdaea851914b17dae9e1fc Talk
module Enumerable
  # Ruby 1.8.7 introduces group_by, but the result isn't ordered. Override it.
  remove_method(:group_by) if [].respond_to?(:group_by) && RUBY_VERSION < '1.9'
...

Ruby On sort_by_multiple

by Adam, September 05, 2008 18:59

Are you using Ruby 1.9 by a...

A8d3f35baafdaea851914b17dae9e1fc Talk

Ruby On sort_by_multiple

by Adam, September 05, 2008 18:11 Star_fullStar_fullStar_fullStar_full

That error is normal under ...

A8d3f35baafdaea851914b17dae9e1fc Talk

Ruby On sort_by_multiple

by Adam, September 05, 2008 17:29

How strange. It passes all ...

A8d3f35baafdaea851914b17dae9e1fc Talk
require "activesupport"

...

Ruby On sort_by_multiple

by Adam, September 05, 2008 15:57 Star_fullStar_fullStar_fullStar_full

This is quite a bit faster ...

A8d3f35baafdaea851914b17dae9e1fc Talk
class Summary < Struct.new(:klass, :options)
  def range
    options[:range] || options[:from]..options[:to]
...

Ruby On Rails Active Record Time Su...

by Adam, September 03, 2008 16:21

This is completely untested...

A8d3f35baafdaea851914b17dae9e1fc Talk
task :status_codes do
  require 'action_controller/status_codes'
  include ActionController::StatusCodes  
...

Ruby On A Rails rake task to lookup...

by Adam, September 03, 2008 05:14
A8d3f35baafdaea851914b17dae9e1fc Talk

Ruby On Too many assignments and co...

by Adam, August 29, 2008 21:11

Edit: Double post.

A8d3f35baafdaea851914b17dae9e1fc Talk
class Commentor
  def comment_type
    self.class.to_s.downcase
...

Ruby On Too many assignments and co...

by Adam, August 29, 2008 21:03

I couldn't quite discern wh...

A8d3f35baafdaea851914b17dae9e1fc Talk
def test_web_browser
  %w(Firefox/3 Firefox/2 MSIE\ 6 MSIE\ 7 Opera).detect do |agent|
    request.user_agent =~ Regexp.new(agent)
...

Ruby On Code to detect the web browser

by Adam, August 28, 2008 22:02

@Nicolás - I don't think t...

A8d3f35baafdaea851914b17dae9e1fc Talk
class Normalizer < Struct.new(:string)
  REPLACEMENTS = {
    0x92 => "&#39;",
...

Ruby On simplify multiple gsub

by Adam, August 28, 2008 18:50
A8d3f35baafdaea851914b17dae9e1fc Talk
def test_web_browser
  catch(:match) do
    ["Firefox/3", "Firefox/2", "MSIE 6", "MSIE 7", "Opera"].each do |ua|
...

Ruby On Code to detect the web browser

by Adam, August 28, 2008 18:32 Star_full
A8d3f35baafdaea851914b17dae9e1fc Talk
"\xBD + \xBC".chars.normalize.to_s
=> "1/2 + 1/4"

Ruby On simplify multiple gsub

by Adam, August 27, 2008 13:42 Star_fullStar_fullStar_fullStar_fullStar_full

Perhaps I wasn't clear with...

A8d3f35baafdaea851914b17dae9e1fc Talk
data.chars.normalize!

Ruby On simplify multiple gsub

by Adam, August 27, 2008 04:07 Star_fullStar_fullStar_fullStar_fullStar_full

Why not use ActiveSupport::...

A8d3f35baafdaea851914b17dae9e1fc Talk
require 'transaction/simple/group'

def transact(objects, action)
...

Ruby On Code transactions

by Adam, August 20, 2008 14:06 Star_fullStar_fullStar_fullStar_fullStar_full
A8d3f35baafdaea851914b17dae9e1fc Talk
<span class="bluelinks-allsmall">
	<% if user.normal? %>
...

Ruby On Link to if else simple cond...

by Adam, August 20, 2008 13:51 Star_fullStar_fullStar_fullStar_full

You should be using named r...

A8d3f35baafdaea851914b17dae9e1fc Talk
def sort(array)
  array.inject([]) do |sorted,element|
    small, large = sorted.partition { |item| item < element }
...

Ruby On Method for sorting

by Adam, August 20, 2008 05:21 Star_fullStar_fullStar_fullStar_fullStar_full

Here is your sort algorithm...

A8d3f35baafdaea851914b17dae9e1fc Talk
module ApplicationHelper
  def present(object)
...

Ruby On Default value for user column

by Adam, August 20, 2008 04:22 Star_fullStar_fullStar_fullStar_full

I disagree with the others ...

A8d3f35baafdaea851914b17dae9e1fc Talk
puts "Enter words, blank row quits."        

while !(line = gets.chomp).empty?
...

Ruby On Method for sorting

by Adam, August 19, 2008 17:43

Although I understand that ...

A8d3f35baafdaea851914b17dae9e1fc Talk
def self.favorite?(object)
  if reflection = object.class.reflect_on_association(:favorites)
    send("find_by_#{reflection.primary_key_name}", object)
...

Ruby On How to benchmark

by Adam, August 19, 2008 15:43 Star_fullStar_fullStar_fullStar_fullStar_full

Use script/performance/benc...

A8d3f35baafdaea851914b17dae9e1fc Talk
<%= pluralize(@resource.favorites.length, "Favorite") %>

Ruby On simple pluralize

by Adam, August 19, 2008 14:16 Star_fullStar_fullStar_fullStar_fullStar_full
A8d3f35baafdaea851914b17dae9e1fc Talk
require "csv"
require "enumerator"

...

Ruby On CSV turn in to an array of ...

by Adam, August 15, 2008 13:23 Star_fullStar_fullStar_fullStar_fullStar_full
A8d3f35baafdaea851914b17dae9e1fc Talk
class Report < ActiveRecord::Base
  %w[hits uniques].each { |const| const_set(const.upcase, const) }
end

Ruby On A shorter way to declare cl...

by Adam, August 14, 2008 20:13 Star_fullStar_fullStar_fullStar_fullStar_full
A8d3f35baafdaea851914b17dae9e1fc Talk