Skip to content

Instantly share code, notes, and snippets.

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)
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.
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)
list match {
case List(_, 3, _, _) => println("Four elements, with the 2nd being '3'.")
case List(_*) => println("Any other list with 0 or more elements.")
}
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
scala> <WTF />
res62: scala.xml.Elem = <WTF></WTF>
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
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._
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)
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