Skip to content

Instantly share code, notes, and snippets.

Example Run

RQ Worker

✪ rqworker --db 10 default high
16:06:30 RQ worker started, version 0.3.7
16:06:30 
16:06:30 *** Listening on default, high...
16:06:49 high: jobs.multiply(5, 2) (2df52ba2-bd32-4849-a8e1-c5241c78b542)
16:06:49 Job OK, result = 10
@jbynum
jbynum / gist:3178051
Created July 25, 2012 19:28
color helpers
# Amount should be a decimal between 0 and 1. Lower means darker
def darken_color(hex_color, amount=0.4)
hex_color = hex_color.gsub('#','')
rgb = hex_color.scan(/../).map {|color| color.hex}
rgb[0] = (rgb[0].to_i * amount).round
rgb[1] = (rgb[1].to_i * amount).round
rgb[2] = (rgb[2].to_i * amount).round
"#%02x%02x%02x" % rgb
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
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
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],
@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,
total = 0
(0...1000).each do |i|
total += i if (i%3 == 0 || i%5 == 0)
end
puts total
@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) ) {
<?php
$show = 10; # The number of posts to display on this page
if (isset($_GET['pageID']))
{
$pageID = $_GET['pageID'];
} else {
$pageID = 1;
}
$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);