This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on work from http://mifsud.me/simple-two-legged-oauth-provider-in-rails-2 | |
# Note that you need a user with :api_key and :secret fields | |
require 'oauth/request_proxy/rack_request' | |
class ApplicationController < ActionController::Base | |
protect_from_forgery | |
protected | |
def run_oauth_check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DataMapper::Resource | |
def becomes(klass) | |
became = klass.new | |
self.send(:properties).each do |prop| | |
became.instance_variable_set("#{prop.instance_variable_name}", prop.get(self)) | |
end | |
became.instance_variable_set(:@_persistence_state, @_persistence_state) | |
became.instance_variable_set(:@errors, errors) | |
became.type = self.class.name.demodulize | |
became |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -w | |
file = "products.csv" | |
lines_per_file = 20000 | |
header_lines = 1 | |
extension = File.extname(file) | |
basename = File.basename(file, extension) | |
File.open(file) do |f| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.fn.ratingSelector = function(){ | |
return $(this).each(function(){ | |
var stars_element = null, | |
rating_element = null; | |
stars_element = $(this).find('span.rating_stars'); | |
rating_element = $(this).find('input'); | |
if (stars_element.size() && rating_element.size()) | |
stars_element.click(function(ev){ | |
var stars_coords = stars_element.offset(); | |
var offset = ev.pageX - stars_coords.left; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!class_exists('Better_EE')) { | |
class Better_EE { | |
public static $field_defaults = array( | |
'site_id' => 1, | |
'field_type' => 'text', | |
'field_fmt' => 'none', | |
'field_show_fmt' => 'n', | |
'field_maxl' => 500, | |
'field_label' => '', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DataMapper | |
module Validations | |
class NumericalityValidator < GenericValidator | |
private | |
def value_as_string(value) | |
case value | |
when Float then value.to_d(options.fetch(:precision, nil)).round(options.fetch(:scale, 20)).to_s('F') | |
when BigDecimal then value.to_s('F') | |
else value.to_s | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'data_mapper' | |
DataMapper::Logger.new($stdout) | |
DataMapper.setup(:default, 'sqlite::memory:') | |
class Pack | |
include DataMapper::Resource | |
belongs_to :school | |
has n, :pack_orders | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$grouped_product = new Shop_Product(null, array('no_validation' => true, 'no_column_init' => true, 'no_timestamps' => true)); | |
$data = $_POST['Shop_Product']; | |
$data['grouped'] = 1; | |
$data['name'] = $product->name . ' ('.$attributes->name.')'; | |
$data['url_name'] .= '_'.uniqid('', true); | |
$data['sku'] .= '-' . strtolower($attributes->sku.uniqid('', true)); | |
$data['grouped_option_desc'] = $attributes->name; | |
$data['x_aga_ids'] = join(':', $ids); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set :application, "yyyyyyyyyyy" | |
set :repository, "here-be-your-githubs" | |
set :scm, :git | |
set :branch, "master" | |
set :user, "xxxxxxxx" | |
set :scm_verbose, true | |
default_run_options[:pty] = true | |
set :deploy_via, :remote_cache | |
ssh_options[:forward_agent] = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'data_mapper' | |
::DataMapper.setup(:default,'mysql://[email protected]/test') | |
class CartItem | |
include DataMapper::Resource | |
belongs_to :product | |
property :id, Serial | |
end |