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
Verifying my Blockstack ID is secured with the address 1DcoBDY6S7QELM7qvmgqibASxd3jP2L2kB https://explorer.blockstack.org/address/1DcoBDY6S7QELM7qvmgqibASxd3jP2L2kB
@JonCrawford
JonCrawford / clean_resque_worker_keys.rb
Created October 13, 2015 14:43
Clean Stale Resque Workers
Resque.working.select{|w| DateTime.parse(w.job["run_at"]) < 5.hours.ago }.map do |worker|
worker.shutdown
worker.unregister_worker
end
@JonCrawford
JonCrawford / sql_queries.sql
Created October 30, 2014 00:13
Vanity ID SNAFU Recovery
SELECT orders.id, orders.vanity_id, orders.payment_state, orders.confirmed_at, orders.store_id, store_subdomain from orders WHERE orders.vanity_id < 100000 and orders.confirmed_at > DATE_SUB(NOW(), INTERVAL 5 DAY) AND orders.store_id IN (528222, 18784) order by vanity_id, store_id;
@JonCrawford
JonCrawford / collection.liquid
Created July 14, 2012 23:52
Adding on sale, preorder, sold out, and coming soon to your product page
...
<li class="product" id="products_{{product.id}}">
<a href="{{product.url}}">
<span class="{{ product.css_class }}">
{% if product.on_sale %}
<img src="/themes/default/images/label-onsale.png" width="98" height="98" alt="On Sale" />
{% endif %}
{% if product.preorder %}
<img src="/themes/default/images/label-preorder.png" width="98" height="98" alt="Pre-Order" />
{% endif %}
@JonCrawford
JonCrawford / store.rb
Created April 17, 2012 23:09
Use after_commit instead of after_create for Resque jobs.
# Redis is faster than Mysql so it may cause a RecordNotFound to happen if enqueued from after_create
before_create :set_recently_opened
after_commit :if => :recently_opened? do |record|
Resque.enqueue StoreAfterCreate, record.id
UserMailer.store_signup(record.owner_user_id, record.id).deliver
end
def set_recently_opened
@recently_opened = true
end
@JonCrawford
JonCrawford / resque_transition.rb
Created April 17, 2012 21:03
Moving from delayed_job to resque
self.send_later :update_associations
Resque.enqueue UpdateAssociations, self.id
@JonCrawford
JonCrawford / product_showcase.css
Created June 27, 2011 01:26
Storenvy Product Showcase Slider - This code is provided as-is and is not supported by Storenvy.
/* Add this CSS to your store Styles section under CSS mode */
/* http://www.storenvy.com/ */
/* Photo Slider */
.product_photo_slider {
background: #fff; /*: Product Slider Background :*/
border: 5px solid #eaeaea; /*: Product Slider Border :*/
color: #555; /*: Product Slider Product Description :*/
display: block;
margin-left:8px;
class VisitorStats
def initialize
@redis = Redis.new
end
# every time there's a hit, increment a counter for the
# day and week, and add the session id to a set of unique
# vistitors for the day/week
def hit(session_id)
today = Date.today
# Bash snippet to open new shells in most recently visited dir.
# Useful if you want to open a new terminal tab at the present
# tab's location.
#
# Put this in your .bashrc or whatever.
pathed_cd () {
if [ "$1" == "" ]; then
cd
else
def random_elements(arr, num_items)
el = arr.dup
results = []
num_items.times{results << el.delete(el[rand(el.size)])}
return results
end
random_elements((1..10000).to_a, 25)