Skip to content

Instantly share code, notes, and snippets.

Martin Carel cawel

Block or report user

Report or block cawel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View test_game.rb
require 'sinatra'
require 'sinatra/test/rspec'
require File.join(File.dirname(__FILE__), '../../server.rb')
describe 'Game logic' do
it 'should be able to play in 0,0' do
get '/new' #this route assigns data in session
View tictactoe.rb :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"
View tictactoe_shoes.rb
require File.join(File.dirname(__FILE__), 'game_shoes.rb') => "Ric-rac-roe", :width => 630, :height => 670) do
background black
def init_game
@game =
@images = []
3.times {@images <<}
View sinatra-apps.txt
Let's make a list of Sinatra-based apps!
- "The classic tic-tac-toe game"
- "Sinatra based"
- "minimalist blogging engine"
- "The easy and fun Continuous Integration server"
- "git-powered wiki"
- "Seinfeld-inspired productivity calendar to track your public github commits."
- "Marley, the blog engine without <textareas>."
View snippet.rb
def self.memoize_with_memcache(name)
define_method "#{name}_with_memo" do
key = [, id.to_s] * '/'
Cache.get(key) || Cache.put(key, name_without_memo)
alias_method_chain name.to_sym, :memo #needs :to_sym here, otherwise 'name' is unrecognized
View service_hook.rb
#!/usr/bin/env ruby
app = do |env|
`rake deploy:stage`
[200, {'Content-type' => 'text/plain'}, "ACK on the commit: thanks!"]
require 'rubygems'
require 'thin'
View gist:388607
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
View ransack.rb
# Patch for 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 < ?",]) }
# end
View code-1.js
// Define your class.
return( Singleton || Constructor );
cawel / gist:8b564a9ab298486e3e96
Last active Aug 29, 2015
View gist:8b564a9ab298486e3e96
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])) );
You can’t perform that action at this time.