Skip to content

Instantly share code, notes, and snippets.

View eltiare's full-sized avatar

Jeremy Nicoll eltiare

View GitHub Profile
@eltiare
eltiare / simple-slideshow.html
Created March 6, 2011 07:46
An easy way to rotate images in a slideshow via jQuery
<html>
<head>
<title>Simple Slideshow</title>
<style type='text/css'>
#slideshow { position: relative; }
#slideshow img { position: absolute; top: 0; left: 0; }
</style>
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
var image_counter = -1;
@eltiare
eltiare / view-hack.rb
Created January 26, 2011 03:36
Hacking Sinatra's views to make organization easier when using multiple apps.
require 'sinatra/base'
class Kazoo::Sinatra < Sinatra::Base
def render(engine, data, options = {}, *args)
if !options[:views] && data.is_a?(Symbol) && !data.to_s.match('/')
data = :"#{decamelize(self.class.name)}/#{data}"
options[:layout] ||= :'layouts/application'
end
@eltiare
eltiare / interleave.rb
Created January 15, 2011 22:10
Interleaves another array into the current one, returns a new array
class Array
def interleave(other)
arr = []
size.times { |i| arr << self[i]; arr << other[i] unless i + 1 > other.size }
left = other[size - 1 .. -1]
arr += left if left
arr
end
end
ree-1.8.7-2010.02 > post = Post.all[3]
typewhat_production['posts'].find({}, {})
=> #<Post _id: 4d2f69c90190bd17a7000001, created_at: Thu Jan 13 21:08:25 UTC 2011, image_filename: "captcha-hindi.png", title: "Zepplin 4?", updated_at: Thu Jan 13 21:15:27 UTC 2011, user_url: nil, approved: false, user_id: nil, user_name: "", approved_at: nil, user_email: "", : "">
ree-1.8.7-2010.02 > post.approve!
=> Thu, 13 Jan 2011 21:17:50 +0000
ree-1.8.7-2010.02 > post.save
MONGODB typewhat_production['posts'].update({"_id"=>BSON::ObjectId('4d2f69c90190bd17a7000001')}, {"$set"=>{"updated_at"=>Thu Jan 13 21:17:52 UTC 2011, "approved"=>true, "approved_at"=>Thu Jan 13 21:17:50 UTC 2011}})
=> true
ree-1.8.7-2010.02 > post.reload
typewhat_production['posts'].find({:_id=>BSON::ObjectId('4d2f69c90190bd17a7000001')}, {}).limit(-1)
var application = {
page_loaded : false,
page_init : function() {
var i;
application.page_loaded = true;
// Load scripts that have not already been loaded.
var script;
for (i=0; script = application.scripts_to_load[i]; i++) {
<ul class="jqueryFileTree" style="display: none;">
<% @dirs.each do |dir| %>
<li class="directory collapsed"><a href="#" rel="<%= params[:dir] / dir %>"><%= dir %></a></li>
<% end %>
<% @files.each do |file| %>
<li class="file ext_<%= File.extname(file)[1..-1] %>"><a href="#" rel="<%= params[:dir] / file %>"><%= file %></a></li>
<% end %>
</ul>
# Routes
match '/javascripts/ckeditor/plugins/filemanager/connectors/rb/filemanager.rb', :to => 'filemanager#show'
match '/javascripts/ckeditor/plugins/filemanager/scripts/jquery.filetree/connectors/jqueryFileTree.rb', :to => 'filemanager#filetree'
# Duck punching
class Pathname
def /(other); File.join(self, other) end
end
class String
class MiniRouter
class << self
def routes; @routes ||= [] end
def named_routes; @named_routes ||= {} end
def context; @context ||= Context.new(self) end
def add_routes(&blk)
raise 'add_routes requires a block' unless block_given?
context.instance_eval(&blk)
end
<html>
<head>
<title>Testing</title>
</head>
<body>
<form action="./" method="post">
<input type="text" name="question[id]"/>
<input type="text" name="question[text]" />
<input type="text" name="question[user][email]" />
</form>
class User
include DataMapper::Resource
property :id, Serial
property :priority, Integer
end
class Posting
property :id, Serial