Skip to content

Instantly share code, notes, and snippets.

report = Garb::Report.new(profile, :metrics => [:visits], :dimensions => [:hostname])
report.filters {:hostname.does_not_match => 'record.net.au'}
report.results
@tpitale
tpitale / integer_csv.rb
Created April 19, 2011 23:25
DataMapper Integer CSV Type
require 'dm-core'
class IntegerCsv < DataMapper::Property::Text
def primitive?(value)
super || value.kind_of?(::Array)
end
def load(value)
case value
@tpitale
tpitale / employee_photo_uploader.rb
Created May 9, 2011 15:05
Example B&W photo version with CarrierWave and MiniMagick
# encoding: utf-8
require 'carrierwave/processing/mini_magick'
class EmployeePhotoUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
@tpitale
tpitale / page1.html
Created August 2, 2011 21:07
GA History Example
<!DOCTYPE HTML>
<html>
<head>
<title>Examples Index</title>
</head>
<body data-controller="examples" data-action="index">
<div id="content">
<h1>Page 1</h1>
<a href="page2.js" data-remote="true">Page 2</a>
</div>
@tpitale
tpitale / lib-sunspot-data_mapper.rb
Created October 16, 2011 16:18 — forked from dkubb/dm_sunspot.rb
DataMapper and Sunspot Integration Extension
module Sunspot
module DataMapper
def self.included(base)
base.class_eval do
alias new_record? new?
end
base.extend Sunspot::Rails::Searchable::ActsAsMethods
Sunspot::Adapters::DataAccessor.register(DataAccessor, base)
@tpitale
tpitale / oauth_signin.rb
Created November 15, 2011 17:18
OAuth Example for Garb
# ----------------- OAUTH CONSUMER ------------------
consumer = OAuth::Consumer.new('anonymous', 'anonymous', {
:site => 'https://www.google.com',
:request_token_path => '/accounts/OAuthGetRequestToken',
:access_token_path => '/accounts/OAuthGetAccessToken',
:authorize_path => '/accounts/OAuthAuthorizeToken'
})
# ----------------- NEW OAUTH TOKEN ------------------
request_token = consumer.get_request_token({}, {:scope => 'https://www.google.com/analytics/feeds'})
@tpitale
tpitale / gist:2037000
Created March 14, 2012 14:51
Handy little script to run a glob directory of test/unit tests
#!/usr/bin/env ruby
$: << 'test' << 'lib'
Dir.glob(ARGV).each {|f| load f unless f =~ /^-/}
# Usage: ruby_test test/unit/**/*.rb
21:47:15 web.1 | SQL (51.210ms) SELECT "id", "counts", "successful", "created_at", "completed_at", "retailer_id" FROM "log_extracts" WHERE "retailer_id" IN (20, 13, 12, 21, 19, 17, 3, 6, 16, 22, 4, 10, 7, 8, 9, 14, 11, 1, 2, 5, 18, 15) ORDER BY "id"
21:47:15 web.1 | SQL (1.790ms) SELECT "id", "counts", "successful", "created_at", "completed_at", "retailer_id" FROM "log_extracts" WHERE "retailer_id" = 20 ORDER BY "created_at" DESC LIMIT 1
21:47:15 web.1 | SQL (2.306ms) SELECT "id", "counts", "successful", "created_at", "completed_at", "retailer_id" FROM "log_extracts" WHERE "retailer_id" = 13 ORDER BY "created_at" DESC LIMIT 1
21:47:15 web.1 | SQL (1.429ms) SELECT "id", "counts", "successful", "created_at", "completed_at", "retailer_id" FROM "log_extracts" WHERE "retailer_id" = 12 ORDER BY "created_at" DESC LIMIT 1
21:47:15 web.1 | SQL (0.889ms) SELECT "id", "counts", "successful", "created_at", "completed_at", "retailer_id" FROM "log_extracts" WHERE "retailer_id" = 21 O
@tpitale
tpitale / form.handlebars
Created August 8, 2012 18:43
grouped_select.js
{{view Ember.GroupedSelect
groupedContentBinding="App.groupedServiceCodes"
contentBinding="App.flattenedServiceCodes"
selectionBinding="service_code"
optionLabelPath="content.description"
optionValuePath="content.id"
}}
<!-- groupedServiceCodes is an array of Ember.Objects with a label, and content -->
<!-- flattenedServiceCodes is the content arrays from groupedServiceCodes concatted together so they have the same order as the select -->
@tpitale
tpitale / reel_ws_pg_example.rb
Last active March 23, 2017 13:03
Reel Websocket Server using PG Listen/Notify for crude pubsub
require 'rubygems'
require 'bundler/setup'
require 'reel'
require 'celluloid/io'
require 'pg'
module PGNotifications
def self.included(actor)
actor.send(:include, Celluloid::IO)
end