Skip to content

Instantly share code, notes, and snippets.

@kitop
kitop / twitter-cards.liquid
Created September 16, 2013 18:56
Twitter Cards Snippet for Shopify Stores
{% comment %}
This is for widgets that share content on Twitter.
Twitter developer info: https://dev.twitter.com/docs/cards
Brought to you by Viralica http://viralica.com
{% endcomment %}
{% if template contains 'product' %}
<meta name="twitter:card" content="product">
<meta name="twitter:title" content="{{ product.title }}" />
<meta name="twitter:description" content="{{ product.description | strip_html | strip_newlines | truncatewords: 160, '' | escape }}" />
class ProductsController < ApplicationController
def preview
begin
ActiveRecord::Base.transaction do
if request.referer =~ %r{/admin/products/(.+)/edit}
@product = Product.find($1)
@product.update_attributes(params[:product])
else
@product = Product.new(params[:product])
raise "Invalid" unless @product.valid?
require 'spec_helper'
# it's important to add the ':worker => true' setting so tests don't run in a transaction. This is configured in spec_helper
describe EmailWorker, :worker => true do
before(:each) do
@user = FactoryGirl.create :user
end
let(:worker){ EmailWorker.new }
class EmailWorker
include SuckerPunch::Worker
def perform(user_id)
ActiveRecord::Base.connection_pool.with_connection do
user = User.find(user_id)
UserMailer.welcome(user).deliver
end
end
@kitop
kitop / unicorn.rb
Created February 18, 2013 22:30
Unicorn config example
# config/unicorn.rb
worker_processes 4
timeout 30
preload_app true
before_fork do |server, worker|
# Replace with your ORM of choice
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
@kitop
kitop / gslyaml.rb
Created June 24, 2011 18:47 — forked from EmmanuelOga/gslyaml.rb
GSL::Vector to YAML
# http://tech.natemurray.com/2007/03/custom-yaml-emitter.html
require 'psych'
require 'yaml'
require 'gsl'
v = GSL::Vector.alloc 1..10
class GSL::Vector
Building native extensions. This could take a while...
ERROR: Error installing patron:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-1.9.2-p136/bin/ruby extconf.rb
checking for curl-config... yes
checking for rb_thread_blocking_region()... yes
creating Makefile
make