Skip to content

Instantly share code, notes, and snippets.

class Foo < Sinatra::Base
@@server_instance = nil
def self.run!(options={})
set options
handler = detect_rack_handler
handler_name = handler.name.gsub(/.*::/, '')
puts "== Sinatra/#{Sinatra::VERSION} has taken the stage " +
"on #{port} for #{environment} with backup from #{handler_name}" unless handler_name =~/cgi/i
handler.run self, :Host => host, :Port => port do |server|
@@server_instance = server
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<title>jQuery Column Tree Table</title>
<link rel="stylesheet" href="http://jqueryui.com/themeroller/css/parseTheme.css.php?ffDefault=Lucida+Grande,+Lucida+Sans,+Arial,+sans-serif&fwDefault=bold&fsDefault=1.1em&cornerRadius=5px&bgColorHeader=5c9ccc&bgTextureHeader=12_gloss_wave.png&bgImgOpacityHeader=55&borderColorHeader=4297d7&fcHeader=ffffff&iconColorHeader=d8e7f3&bgColorContent=fcfdfd&bgTextureContent=06_inset_hard.png&bgImgOpacityContent=100&borderColorContent=a6c9e2&fcContent=222222&iconColorContent=469bdd&bgColorDefault=dfeffc&bgTextureDefault=02_glass.png&bgImgOpacityDefault=85&borderColorDefault=c5dbec&fcDefault=2e6e9e&iconColorDefault=6da8d5&bgColorHover=d0e5f5&bgTextureHover=02_glass.png&bgImgOpacityHover=75&borderColorHover=79b7e7&fcHover=1d5987&iconColo
require 'rubygems'
require 'mongo_mapper'
require 'active_support'
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
:default => "%m/%d/%Y"
)
class Time
def self.to_mongo(value)
require 'rubygems'
require 'rmagick'
require 'color_namer'
img = Magick::ImageList.new('photo.jpg')
img.resize_to_fit!(500) # resize the image to have faster quantization
quantized = img.quantize(16) # quantize the photo to reduce number of colors
img.destroy! # prevent memory leaks
@retro
retro / canjs_firebase_chat_demo.html
Created April 13, 2012 12:44
Implementation of Firebase chat demo with CanJS. Uses observable and live binding
<html>
<head>
<title>CanJS Firebase chat demo</title>
<script type='text/javascript' src='http://static.firebase.com/demo/firebase.js'></script>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
<script type="text/javascript" src="http://retro.github.com/javascripts/can.jquery.js"></script>
<link rel='stylesheet' type='text/css' href='http://www.firebase.com/css/example.css'>
</head>
<body>
<div id='messagesDiv'></div>
@retro
retro / app.rb
Created August 30, 2012 10:18
Map classes to sinatra routes
require 'rubygems'
require 'sinatra'
class Handler
attr_reader :context
def initialize(context)
@context = context
end
def render
unless context.params[:username].nil?
<html>
<head>
<title>Tabs Demo!</title>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
.container {
margin-top: 20px;
}
</style>
</head>

Keybase proof

I hereby claim:

  • I am retro on github.
  • I am retro (https://keybase.io/retro) on keybase.
  • I have a public key whose fingerprint is 30F9 39EA 1BAC 3D1E 755B 27FF ABCB 01C8 06D4 3752

To claim this, I am signing this object:

;; If it's for the user stored in the `:current-user` named slot
(def schema {:users {:id :id}})
(def current-user-favorite-color [app-db]
(reaction
(let [db @app-db
current-user (edb/get-named-item schema app-db :users :current)]
(:favorite-color current-user))
(deftest trying-to-click-non-existing-element []
(syn-run!
(<! (s/click! ".non-existing-element")) ;; Waits for the element to appear on the page up to 6 seconds
(is false "This should never run"))) ;; will never run, and test will cleanly exit
(deftest typing []
(let [[container cleanup] (container!)
bootstrap #(el! "input" container)]
(.setTimeout js/window bootstrap 2000) ;; Add the element to page after two seconds
(syn-run!