Skip to content

Instantly share code, notes, and snippets.

require 'sinatra'
require 'sinatra/test/rspec'
require File.join(File.dirname(__FILE__), '../../server.rb')
Dir.chdir('../../')
describe 'Game logic' do
it 'should be able to play in 0,0' do
get '/new' #this route assigns data in session
Shoes.app :width => 300, :height => 300 do
@squares = []
(1..9).each do |n|
stack :width => 100, :height => 100 do
@squares[n] = image "1.gif" do
@squares[n] = image "2.gif"
end
end
end
end
require File.join(File.dirname(__FILE__), 'game_shoes.rb')
Shoes.app(:title => "Ric-rac-roe", :width => 630, :height => 670) do
background black
def init_game
@game = GameShoes.new
@images = []
3.times {@images << Array.new(3)}
end
Let's make a list of Sinatra-based apps!
Apps:
- http://github.com/cawel/ric-rac-roe "The classic tic-tac-toe game"
- http://github.com/cschneid/irclogger "Sinatra based irclogger.com"
- http://github.com/rtomayko/wink "minimalist blogging engine"
- http://github.com/foca/integrity "The easy and fun Continuous Integration server"
- http://github.com/sr/git-wiki "git-powered wiki"
- http://github.com/entp/seinfeld "Seinfeld-inspired productivity calendar to track your public github commits."
- http://github.com/karmi/marley "Marley, the blog engine without <textareas>."
@cawel
cawel / snippet.rb
Created February 18, 2009 19:09 — forked from macournoyer/snippet.rb
def self.memoize_with_memcache(name)
define_method "#{name}_with_memo" do
key = [self.class.name, id.to_s] * '/'
Cache.get(key) || Cache.put(key, name_without_memo)
end
alias_method_chain name.to_sym, :memo #needs :to_sym here, otherwise 'name' is unrecognized
end
#!/usr/bin/env ruby
app = Proc.new do |env|
`rake deploy:stage`
[200, {'Content-type' => 'text/plain'}, "ACK on the commit: thanks!"]
end
require 'rubygems'
require 'thin'
module SmartHippo::MonkeyPatches::Enumerable
def self.included(base)
base.class_eval do
# snap to nearest value in a collection of values
def snap_from value
value = value.to_i
self.sort_by{|i| (i - value).abs }.first
end
@cawel
cawel / ransack.rb
Last active December 16, 2015 14:29 — forked from RohanM/ransack.rb
# Patch for ransack (https://github.com/ernie/ransack) to use scopes
# Helps migrating from Searchlogic or MetaSearch
# Place this file into config/initializer/ransack.rb of your Rails 3.2 project
#
# Usage:
# class Debt < ActiveRecord::Base
# scope_ransackable :overdue
# scope :overdue, lambda { where(["status = 'open' AND due_date < ?", Date.today]) }
# end
#
@cawel
cawel / code-1.js
Last active August 29, 2015 14:09 — forked from bennadel/code-1.js
(function(){
// Define your class.
return( Singleton || Constructor );
})();
@cawel
cawel / gist:8b564a9ab298486e3e96
Last active August 29, 2015 14:09
blog-the-good-parts
Function.method('bind', function(that) {
var method = this,
slice = Array.prototype.slice,
args = slice.apply(arguments, [1]);
return function() {
return method.apply(that, args.concat( slice.apply(arguments, [0])) );
};
});