Skip to content

Instantly share code, notes, and snippets.

View ubermajestix's full-sized avatar

Tyler Montgomery ubermajestix

View GitHub Profile
def auto_complete_for_tag_name
puts "=="*45
puts "searching for tag: #{params[:tag][:name]}"
puts "=="*45
@tag_names = Ci::Sentiment::Tagging::TagName.search("#{params[:tag][:name]}")
render :partial => 'sources/tagname_autocomplete'
end
def find_collisions
@source = ::Ci::Sentiment::MessageExt::Source.find(params[:source_id])
# written by Tyler Montgomery tyler[dot]a[dot]montgomery[at]gmail
#---
# tyler_paginate accepts and will_paginate collection and the standard link_to_remote options to build ajaxy
# pagination links
#---
# in your view:
# <%= tyler_paginate @collection, :url=>{:action=>:pagination_action, :id=>@some_object_id}, :update=>"some_div" %>
# generates something like: < previous 11-20 of 457 next >
#---
# in your controller
begin
#do some stuff that might blow up
rescue
#probably log what just blew up
#move on
end
#!/usr/bin/env ruby
require 'rubygems'
require 'logger'
logger = Logger.new($stdout)
begin
# let's do something that will never exit
# and then we can watch this not die unless we use kill -9
while 2 > 1
def tyler_paginate(collection, opts={} )
#next / prev / pages
page_count = WillPaginate::ViewHelpers.total_pages_for_collection(collection)
pagination_method = collection.first.class.to_s.downcase + "_pagination"
start = ((collection.current_page-1) * collection.per_page ) + 1
last = (start + collection.per_page - 1) > collection.total_entries ? collection.total_entries : (start + collection.per_page - 1)
header = "#{start} - #{last} of #{collection.total_entries}"
if collection.total_entries > collection.per_page
if page_count > 1
if collection.offset != 0
def add_url_markup(text)
urls = []
users =[]
# find urls
text.split.each{|a| a=~/(http\:\/\/\S+)/; urls << $1}
# find twitter usernames (@someusername)
text.split.each{|a| a=~/(\@\S+)/; users << $1}
# add markup
users.compact.each{|user| text.gsub!(user, "<a href='http://twitter.com/#{user.gsub('@','')}'>#{user}</a>")}
urls.compact.each{|url| text.gsub!(url, "<a href='#{url}'>#{url}</a>")}
@ubermajestix
ubermajestix / dont_nav_elsewhere.html.erb
Created January 26, 2009 18:53
keep users from navigating away from a very important page
# in your layout
<head>
<%= stylesheet_link_tag'styles' %>
<%= javascript_include_tag :defaults %>
<%= yield :script %>
</head>
<body>
# ...
# in the view you don't want your user to navigate away from
# this is from my users_controller file
def reset_password
# reset user's password here...
respond_to do |format|
format.html { redirect_to(users_url) }
format.js do
render :update do |page|
# this is where I had a bunch of page. calls that I called in several methods
# they've all disapeared into the replace_user_row method
replace_user_row(page)
abstract (1.0.0)
actionmailer (2.2.2, 2.0.2, 1.3.3)
actionpack (2.2.2, 2.0.2, 1.13.3)
actionwebservice (1.2.3)
activerecord (2.2.2, 2.1.0, 2.0.2, 1.15.3)
activerecord-activesalesforce-adapter (2.0.0)
activeresource (2.2.2, 2.0.2)
activesalesforce (1.1.6)
activesupport (2.2.2, 2.1.2, 2.1.1, 2.1.0, 2.0.2, 1.4.2)
acts_as_versioned (0.2.3)
#...
Rails::Initializer.run do |config|
require 'actionmailer'
require "user_notification" # standard actionmailer class that lives in app/models/user_notification
# ...
end