Skip to content

Instantly share code, notes, and snippets.

View trevorturk's full-sized avatar

Trevor Turk trevorturk

  • Chicago
View GitHub Profile
@trevorturk
trevorturk / comments.php
Created September 20, 2010 15:04
Simplest: just about the simplest possible theme for WordPress
<?php if ( $comments ) : ?>
<div id="comments">
<h3>Comments</h3>
<?php wp_list_comments(); ?>
<div class="pagination"><?php paginate_comments_links(); ?></div>
</div><!-- comments -->
<?php endif; ?>
<?php if ( comments_open() || pings_open() ) : ?>
<?php comment_form( 'comment_notes_before=&comment_notes_after=' ); ?>
<?php elseif ( $comments ) : ?>
# db/schema.rb
create_table "feed_items", :force => true do |t|
t.integer "user_id"
t.integer "post_id"
t.datetime "post_created_at"
end
add_index "feed_items", ["user_id", "post_created_at"], :name => "index_feed_items_on_user_id_and_post_created_at"
$('.submittable').live('change', function() {
$(this).parents('form:first').submit();
});
class Video < ActiveRecord::Base
before_validation :set_attrs_via_embedly, :on => :create
def set_attrs_via_embedly
# example url: http://www.youtube.com/watch?v=oHg5SJYRHA0
attrs = Embedly.get_attrs url
errors[:base] << "is not a video" unless attrs['type'] == 'video'
self.attributes = attrs
end
# /1-rick-roll-d -- videos to_param always starts with a number
match '/:id' => 'videos#show', :constraints => {:id => /^\d/}, :as => :video
# /trevor -- usernames can't start with a number
match '/:id' => 'users#show', :as => :user
ruby-1.8.7-p174 ~ > gem list
*** LOCAL GEMS ***
rack (1.1.0)
rake (0.8.7)
rdoc (2.5.8)
ruby-1.8.7-p174 ~ > gem install passenger
Building native extensions. This could take a while...
Building native extensions. This could take a while...
From bb2a78858cffa7c6937642986e9aca1a4f862c0d Mon Sep 17 00:00:00 2001
From: Ilya Grigorik <ilya@igvita.com>
Date: Thu, 10 Jun 2010 00:46:48 -0400
Subject: [PATCH] async rails3
---
Gemfile | 6 ++++++
app/controllers/widgets_controller.rb | 6 ++++++
app/models/widget.rb | 2 ++
config.ru | 1 +
require 'test_helper'
class UsersTest < ActionController::IntegrationTest
setup do
reset!
@conn = Faraday::Connection.new do |b|
b.adapter :action_dispatch, @integration_session
b.response :rails_json
end
end
STDOUT.sync = true
require 'queue'
start_time = Time.now.to_i
msg = 0
queue = Queue.new("testing")
queue.subscribe do |obj|
msg += 1
@trevorturk
trevorturk / gist:404555
Created May 18, 2010 03:04
Weekly Digest - Ruby script for pulling Delicious links
require 'rubygems'
require 'rest_client'
require 'json'
req = RestClient.get 'http://feeds.delicious.com/v2/json/trevorturk?count=100'
links = JSON.parse(req.body)
body = ''
links.each do |l|
body << "<p><a href=\"#{l['u']}\">#{l['d']}</a></p>\n"