This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Date | |
class FancyInteger(val integer: Int) { | |
def day: Int = integer * 86400 | |
def hour: Int = integer * 3600 | |
def minute: Int = integer * 60 | |
def ago: Date = new Date(System.currentTimeMillis() - integer * 1000) | |
} | |
implicit def int2FancyInt(integer: Int): FancyInteger = new FancyInteger(integer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cooking with Chef: Your servers will thank you | |
When you hear "sysadmin work", do you think of ssh, vi, and shell scripts? If you do, it's probably not the most fun sounding work. Repetitive, tedious, and error-prone are words that come to mind. | |
Thankfully, configuring servers is all but a solved problem thanks to Chef. The days of vi, and shell scripts are mostly over. Building complex infrastructure has never been easier. | |
Whether you manage a multi-datacenter cluster, or the VPS that runs your blog, you have a tremendous amount to gain from configuration management. In this talk, I'll show you how it works. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Mysql::Result | |
def each_utf8(&block) | |
each_orig do |row| | |
yield row.map {|col| String === col ? col.force_encoding("utf-8") : col } | |
end | |
end | |
alias each_orig each | |
alias each each_utf8 | |
def each_hash_utf8(&block) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list match { | |
case List(_, 3, _, _) => println("Four elements, with the 2nd being '3'.") | |
case List(_*) => println("Any other list with 0 or more elements.") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package journalist | |
import java.util.Date | |
object FancyInt { | |
implicit def int2FancyInt(int: Int): FancyInt = new FancyInt(int) | |
} | |
class FancyInt(val integer: Int) { | |
def day: Int = integer * 86400 | |
def days: Int = day |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> <WTF /> | |
res62: scala.xml.Elem = <WTF></WTF> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Date | |
object FancyInt { | |
implicit def int2FancyInt(int: Int): FancyInt = new FancyInt(int) | |
} | |
class FancyInt(val integer: Int) { | |
def day: Int = integer * 86400 | |
def days: Int = day | |
def hour: Int = integer * 3600 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Tappable { | |
implicit def any2Tappable[A](toTap: A): Tappable[A] = new Tappable(toTap) | |
} | |
class Tappable[A](toTap: A) { | |
def tap(block: (A) => Unit): A = { block(toTap); toTap } | |
} | |
scala> import Tappable._ | |
import Tappable._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sequel' | |
# Out of the box, Sequel uses IS TRUE/FALSE for boolean parameters | |
# This prevents MySQL from using indexes. | |
# | |
# This patch fixes that. | |
module Sequel | |
module SQL | |
class BooleanExpression | |
def self.from_value_pairs(pairs, op=:AND, negate=false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `index_addresses_on_user_id` ( | |
`id` binary(16) NOT NULL DEFAULT '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0', | |
`user_id` int(11) NOT NULL DEFAULT '0', | |
PRIMARY KEY (`user_id`,`id`) | |
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |