Skip to content

Instantly share code, notes, and snippets.

@scottkf
scottkf / product_scopes.rb
Last active August 29, 2015 13:56
Sort by stock in spree commerce
add_search_scope :by_stock_location do
order(%q{
(
SELECT
CASE
WHEN tt.count_on_hand > 0
THEN 2
WHEN zz.backorderable = true
THEN 1
ELSE 0
@scottkf
scottkf / config-deploy.rb
Created December 18, 2012 17:51
Puma capistrano deployment script, w/init.d script and nginx conf
require "bundler/capistrano"
server "server", :web, :app, :db, primary: true
set :application, "<application>"
set :user, "<user>"
set :group, "wheel"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
VERSION=2.6.7
apt-get -y install wget
rm -rf redis-$VERSION
wget http://redis.googlecode.com/files/redis-$VERSION.tar.gz -O redis-$VERSION.tar.gz
tar -xzvf redis-$VERSION.tar.gz
cd redis-$VERSION
./configure --prefix=/usr
make
rm -rf /tmp/redis-$VERSION.$$
mkdir /tmp/redis-$VERSION.$$
@scottkf
scottkf / hooks-before-fail-test.js
Created August 23, 2012 17:20
node-resourceful before update fail
var assert = require('assert'),
vows = require('vows'),
resourceful = require('../lib/resourceful');
vows.describe('resourceful/hooks/sync').addBatch({
"a Resource (update)": {
topic: function () {
return resourceful.define('ResourceUpdate', function () {
this.property('name');
this.property('full');
@scottkf
scottkf / omniauth-steam.rb
Created November 23, 2011 14:20
omniauth-steam, prior to being bundled
module OmniAuth
module Strategies
class Steam < OmniAuth::Strategies::OpenID
include OmniAuth::Strategy
args [:store, :api_key]
option :options, {}
option :identifier, "http://steamcommunity.com/openid"
option :name, :steam
@scottkf
scottkf / create_people.rb
Created October 31, 2011 13:37
Self-referential rails example
class CreatePeople < ActiveRecord::Migration
def change
create_table :people do |t|
t.string :name
t.timestamps
end
end
end
@scottkf
scottkf / app-views-index.jade
Created October 10, 2011 14:42
railwayjs environment config
- var items = ["facebook", "github", "twitter", "instagram"]
- if (!everyauth.loggedIn)
h2 Not Authenticated
each item in items
a(href='/auth/' + item)
span Connect with <span style="text-transform: capitalize">!{item}</span><br />
- else
h2 Authenticated
#user-id Logged in with `user.id` #{user.id} - aka `everyauth.user.id` #{everyauth.user.id}
require 'rspec'
require 'nokogiri'
require 'open-uri'
describe "nokogiri steam failure" do
it "should only see a url once since they don't repeat" do
doc = Nokogiri::HTML(open(URI.encode("http://store.steampowered.com/search/results?sort_by=Name&sort_order=ASC&category1=998&cc=us&v6=1&page=1")))
@kickthebaby = doc.search('//a[@href="http://store.steampowered.com/app/15540/?snr=1_7_7_230_150_1"]').size
@scottkf
scottkf / event.generate_a_calendar.php
Created April 4, 2011 18:47
The event needed for generating a calendar in Symphony CMS 2.2
<?php
require_once(TOOLKIT . '/class.event.php');
Class eventgenerate_a_calendar extends Event {
const ROOTELEMENT = 'generate-a-calendar';
public $eParamFILTERS = array();
public static function about() {
return array(
'name' => 'Generate a Calendar',
'author' => array(
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="date">
<xsl:import href="get-schedule.xsl" />
<!--
Name: XSLT Calendar