Skip to content

Instantly share code, notes, and snippets.

View JonCrawford's full-sized avatar
🏗️
Helping startups on product, tech & data analytics

Jonathan Crawford JonCrawford

🏗️
Helping startups on product, tech & data analytics
View GitHub Profile
> Product.best_sellers
'SELECT `products`.*, COUNT(*) AS total FROM `products` INNER JOIN order_items ON order_items.product_id = products.id INNER JOIN orders ON orders.id=order_items.order_id WHERE ((orders.payment_state=3) GROUP BY products.id ORDER BY total DESC'
# Yay!
> @store.products.best_sellers
'SELECT `products`.*, COUNT(*) AS total FROM `products` INNER JOIN order_items ON order_items.product_id = products.id INNER JOIN orders ON orders.id=order_items.order_id WHERE (`products`.store_id = 464) AND (orders.payment_state=3) GROUP BY products.id ORDER BY products.name ASC'
# Nooo!!!
class AddSecurityStringToOrder < ActiveRecord::Migration
def self.up
add_column :orders, :security_string, :string
end
def self.down
remove_column :orders, :security_string
end
end
## Colors Git and shows branch
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
function proml {
local BLUE="\[\033[0;34m\]"
local RED="\[\033[0;31m\]"
local LIGHT_RED="\[\033[1;31m\]"
@JonCrawford
JonCrawford / gist:44415
Created January 7, 2009 20:45 — forked from anonymous/gist:44410
Improved! A slight alteratiion of DHH's dynamic subdomain technique.
# 1) Point *.example.com in your DNS setup to your server.
#
# 2) Setup an Apache vhost to catch the star pointer:
#
# <VirtualHost *:80>
# ServerName *.example.com
# </VirtualHost>
#
# 3) Set the current account from the subdomain
class ApplicationController < ActionController::Base
$ gem install bleak_house
Building native extensions. This could take a while...
ERROR: Error installing bleak_house:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb install bleak_house
extconf.rb:3:in `exec': No such file or directory - ruby-bleak-house build_snapshot.rb (Errno::ENOENT)
from extconf.rb:3
str = "So don't return this (but do return this)"
start = str.index("(")+1
stop = str.rindex(")")-1
str[start..stop]
## Tests
def test_grouped_options_for_select_with_array
assert_dom_equal(
"<optgroup label=\"North America\"><option value=\"US\">United States</option>\n<option value=\"Canada\">Canada</option></optgroup><optgroup label=\"Europe\"><option value=\"GB\">Great Britain</option>\n<option value=\"Germany\">Germany</option></optgroup>",
grouped_options_for_select([
["North America",
[['United States','US'],"Canada"]],
["Europe",
[["Great Britain","GB"], "Germany"]]
])
def optgroups_with_options(groups, options, selected = nil, prompt = nil)
return "<option>Error: Sizes don't match.</option>" if groups.size != options.size
str = String.new
unless prompt.nil?
if prompt.is_a? String
str += content_tag :option, prompt, :value => ""
elsif prompt.is_a? Array
str += content_tag( :option, prompt[0], :value => prompt[1])
end
end
<div class="product_row add_new_product" id="new_design">
<a href="#" onclick="try {
new Insertion.Before(&quot;new_design&quot;, &quot;\n&lt;div class=\&quot;product_row add_new_product\&quot; id=\&quot;new_product\&quot;&gt;\n &lt;a href=\&quot;#\&quot; onclick=\&quot;try {\nnew Insertion.Before(&quot;new_product&quot;, &quot;&lt;p&gt;This works.&lt;/p&gt;&quot;);\n} catch (e) { alert('RJS error:\\n\\n' + e.toString()); alert('new Insertion.Before(\\&quot;new_product\\&quot;, \\&quot;&lt;p&gt;This works.&lt;/p&gt;\\&quot;);'); throw e }; return false;\&quot;&gt;Add another product&lt;/a&gt;&lt;/div&gt;&quot;);
} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('new Insertion.Before(\&quot;new_design\&quot;, \&quot;\\n&lt;div class=\\\&quot;product_row add_new_product\\\&quot; id=\\\&quot;new_product\\\&quot;&gt;\\n &lt;a href=\\\&quot;#\\\&quot; onclick=\\\&quot;try {\\nnew Insertion.Before(&quot;new_product&quot;, &quot;&lt;p&gt;This works.&lt;/p&gt;&quot;);\\n} catch (e) { alert(\'