Skip to content

Instantly share code, notes, and snippets.

def playlist
list = []
songs = Song.all
songs.each do |s|
list.push([trackinfo => "#{s.artist.name} | #{s.name}", mp3 => "#{s.mp3.url}"])
end
return list.to_json
end
def search
@posts = Post.find(:all, :conditions => ['title LIKE ?', "#{params[:query]}%"], :order => "title")
results = [:query => "#{params[:query]}"]
suggestions = []
@posts.each do |x|
suggestions << "#{x.title}"
end
results << {:suggestions => suggestions}
puts results
respond_to do |format|
$text = $tweet->title;
$text = preg_replace("#(^|[\n ])@([^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://www.twitter.com/\\2\" >@\\2</a>'", $text);
$text = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t<]*)#ise", "'\\1<a href=\"\\2\" >\\2</a>'", $text);
$text = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://\\2\" >\\2</a>'", $text);
<?php
$show = 10; # The number of posts to display on this page
if (isset($_GET['pageID']))
{
$pageID = $_GET['pageID'];
} else {
$pageID = 1;
}
@jbynum
jbynum / Paginate Custom Posts
Created October 22, 2010 21:38
how to paginate custom post type in wordpress
<?php
$docs = get_posts('numberposts=-1&post_type=page&post_parent=36&orderby=title&order=ASC');
$faculty = array();
foreach ($docs as $doc) {
array_push($faculty, $doc->ID);
}
$currentElement = array_search($post->ID, $faculty);
$next = isset( $faculty[$currentElement+1] ) ? $faculty[$currentElement+1] : null;
$prev = isset($faculty[$currentElement-1]) ? $faculty[$currentElement-1] : null;
if ( !is_null($prev) ) {
total = 0
(0...1000).each do |i|
total += i if (i%3 == 0 || i%5 == 0)
end
puts total
@jbynum
jbynum / gist:1186774
Created September 1, 2011 17:52
search for bands by gener
def location
@genre = Genre.find_by_slug(params[:slug])
if @genre.nil?
render :template => 'site/not_found', :status => '404'
end
@title = "#{params[:city] + ',' if params[:city]} #{params[:state]} #{@genre.name}"
@results = []
@bands = Band.near(
[params[:city], params[:state]].join(" "),
3000,
def add_product(product)
current_item = line_items.find_by_mnetid(product[:mnetid])
if current_item
current_item.errors[:base] << "This is already in your cart"
#raise "This is already in your cart"
return false
else
current_item = line_items.build(
:mnetid => product[:mnetid],
:title => product[:title],
config.model Merchant do
create do
field :merchant_level do
render do
bindings[:view].render :partial => "admin/fields/merchant_level", :locals => {:field => self, :form => bindings[:form]}
end
end
end
end
@jbynum
jbynum / pow-restart
Created January 9, 2012 23:48
Shell-script to restart Pow when it stops reponding
#!/bin/bash
# Restarts Pow when DNS fails to resolve
lsof | grep 20560 | awk '{print $2}' | xargs kill -9
launchctl unload ~/Library/LaunchAgents/cx.pow.powd.plist
launchctl load ~/Library/LaunchAgents/cx.pow.powd.plist