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 SurroundingRange | |
attr_reader :point, :field | |
def initialize(point, field) | |
@point, @field = point, field | |
end | |
def points | |
horizontal = [point.x - 1, 0].max..[point.x + 1, field.width - 1].min | |
vertical = [point.y - 1, 0].max..[point.y + 1, field.height - 1].min |
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 'fileutils' | |
NAME = ARGV[0] | |
MODULE_NAME = NAME.gsub(/(?:^|_)(.)/) { $1.upcase } | |
ROOT = File.join(FileUtils.pwd, NAME) | |
def in_dir(dir) | |
old_dir = FileUtils.pwd | |
FileUtils.cd dir | |
yield | |
FileUtils.cd old_dir |
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
// Media Queries in Sass 3.2 | |
// | |
// These mixins make media queries a breeze with Sass. | |
// The media queries from mobile up until desktop all | |
// trigger at different points along the way | |
// | |
// And important point to remember is that and width | |
// over the portrait width is considered to be part of the | |
// landscape width. This allows us to capture widths of devices | |
// that might not fit the dimensions exactly. This means the break |
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 unittest | |
def toRoman(n): | |
""" | |
Convert an integer to Roman numerals. Returns an empty string for 0. | |
""" | |
if n == 0: | |
return '' | |
map = { 1: 'I', 4: 'IV', 5: 'V', 9: 'IX', 10: 'X', 40: 'XL', 50: 'L', 90: 'XC', 100: 'C' } | |
key = max(k for k, v in map.iteritems() if k <= n) |
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
# Make sure you have eventmachine installed and run the server: | |
# | |
# ruby -rubygems game.rb | |
# | |
# When the server is running, clients can connect and issue commands. | |
# Currently supported commands: | |
# | |
# * look: list the players in the arena. | |
# * join [nickname]: join the arena using a nickname | |
# * leave: leave the arena |
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
.DS_Store | |
*.csv | |
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
# app/controllers/pages_controller.rb | |
class PagesController < ApplicationController | |
def login | |
end | |
def forgot_password | |
end | |
end | |
# app/views/pages/login.html.haml |
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
# Lotus has different applications in a single project, optionally with different configurations and/or mappings. | |
# ROM::Lotus should/could conigure a different setup per application, rather than a single global setup. | |
# Relations could be global (defined in ./lib) while mappings might live in both (./apps/web/ and ./lib). | |
# This would resemble how Lotus::Model is organised. | |
# | |
# The only problem here is that Lotus has no hooks for loading framework (it's all hard-coded)s, and | |
# therefore we can't easily extend the application load process with our custom setup code without | |
# resorting to monkeypatching. | |
# apps/web/application.rb |
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
# quick hacky class to make #111 + #456 possible. | |
# Make it a textmate command by adding "#!/usr/bin/env ruby -w" to the top | |
# and "print Color.parse(STDIN.read)" to the bottom. | |
class Color | |
OPERATORS = [:+, :-, :*, :/] | |
def initialize(*args) | |
if [*args].size == 3 | |
@r, @g, @b = *args |
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
def to_list(text) | |
ol_prefix = /^\d+\.?\s*/ | |
dl_prefix = /^(.+):\s*/ | |
ul_prefix = /^[^\s]+\s*/ | |
lines = text.split("\n").map { |line| line.strip } | |
if lines.any? | |
tag, pattern = if lines.first =~ ol_prefix | |
['ol', ol_prefix] | |
elsif lines.first =~ dl_prefix |