Skip to content

Instantly share code, notes, and snippets.

View theCrab's full-sized avatar
💭
What happens when you take a long holiday from work? Shit happens

The Crab theCrab

💭
What happens when you take a long holiday from work? Shit happens
View GitHub Profile
@theCrab
theCrab / property.rb
Created February 19, 2013 15:38
Decipher this
class Property
include DataMapper::Resource
property :id, Serial
property :name, String, required: true
property :price, Integer, required: true
property :description, Text
has 1, :address
has n, :rooms
@theCrab
theCrab / variants.md
Created February 26, 2013 22:23
This graphic shows what am trying to achieve. Any ideas

admin_product_path

How do i deal with the update method accepting variant_ids? Is it the same way the create method creates each variant from the array of prototypes?

ProductVarintsManagement

class Friendship < ActiveRecord::Base
attr_accessible :friend_id, :user_id, :status
belongs_to :user
belongs_to :friend, :class_name => 'User', :counter_cache => :friends_count
def self.request(user, friend)
unless user == friend or Friendship.where(:user_id => user, :friend_id => friend).exists?
transaction do
create({:user => user, :friend => friend, :status => 'pending'}, :without_protection => true)
create({:user => friend, :friend => user, :status => 'requested'}, :without_protection => true)
@theCrab
theCrab / SKU.rb
Last active December 14, 2015 14:18
Auto generating an SKU and appending it to the Master product
# I have a product with a master_SKU = 'BBLZ-A0-00000'
# auto generate a variant SKU for each product variant
# @return variant_SKU = 'BBLZ-A0-00001' OR 'BBLZ-A0-00020'
variants = Product.variants
variants_len = variants.length
i = 0
master_SKU = 'BBLZ-A0-'
v_sku = '00000'
while i < variants_len
@theCrab
theCrab / authenticication_helpers.rb
Created March 14, 2013 15:03
Spree RSpec sign_in_as!(user) helper method undefined spec/spec_helper.rb spec/support/authenticication_helpers.rb
module AuthenticationHelpers
def sign_in_as!(user)
visit '/login'
fill_in 'Email', :with => user.email
fill_in 'Password', :with => "secret"
click_button 'Login'
end
end
RSpec.configure do |config|
@theCrab
theCrab / verifone.rb
Created March 27, 2013 21:23
verifone spree payment gateway. VX680 Terminal
require "rubygems"
require "net/telnet"
params = "
T, ##= 1 String [required] Message Type. 'T' to be passed, to define a transaction record
, ##= 2 Account Number. This field is no longer used. Use Field 24
01, ##= 3 Integer [required] Transaction Type. ‘01’ – Purchase, ‘02’ – Refund, ‘04’ – Cash advance
0000, ##= 4 Integer [required] Modifier.
, ##= 5 Reserved, Leave Blank
, ##= 6 Reserved, Leave Blank
@theCrab
theCrab / expected_array.rb
Last active December 15, 2015 12:59
At every 4th line (where the integer is) I want to create a new CSV line The Integer is the first field in the row. NOTE: Some of the lines are blank " ", and ENCODING is funny Text lines to CSV in ruby
# Verifone Error codes. There are 215 codes and they are [-1...-189] and [-999...-1014]. Just take the important ones :=(
error_codes = [
[ code: "-0", description: "Unspecified error", action: "Contact VeriFone" ],
[ code: "-1", description: "Invalid transaction type", action: " Use alternative method for transaction type" ],
[ code: "-2", description: " ", action: "" ],
[ code: "-3", description: " ", action: "" ],
[ code: "-4", description: " ", action: "" ],
[ code: "-5", description: " ", action: "" ],
[ code: "-6", description: " ", action: "" ],
[ code: "-7", description: " ", action: "" ],
@theCrab
theCrab / errors.sh
Created April 3, 2013 13:03
Deploying spree on heroku gives me this errors
the-crab$ git push heroku master
Counting objects: 970, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (829/829), done.
Writing objects: 100% (970/970), 5.09 MiB | 327 KiB/s, done.
Total 970 (delta 110), reused 0 (delta 0)
-----> Ruby/Rails app detected
-----> Using Ruby version: ruby-1.9.3
-----> Installing dependencies using Bundler version 1.3.2
@theCrab
theCrab / verifone.rb
Created April 3, 2013 16:10
Verifone UK Spree Payment Gateway Integration
# encoding: utf-8
require "rubygems"
require "net/telnet"
# request_params = "T,,01,0000,,,,,,,10.00,0.00000,,,,,,,,,,,\n"
begin
puts 'Trying.....'
printo = Net::Telnet::new( "Host" => "192.168.2.37", "Port" => 25000, "Telnetmode" => true )
@theCrab
theCrab / devise_error.sh
Created April 30, 2013 11:34
Devise user_signed_in? error
NoMethodError - undefined method `user_signed_in?' for #<#<Class:0x007ff4e946dff8>:0x007ff4eef44648>:
(gem) spree_core-1.3.2/app/helpers/spree/base_helper.rb:162:in `method_missing'
app/views/spree/shared/_nav_bar.html.erb:2:in `_6fd4240c6a08c5260228ac2bcf10cc4a'
(gem) actionpack-3.2.13/lib/action_view/template.rb:145:in `block in render'
(gem) activesupport-3.2.13/lib/active_support/notifications.rb:123:in `block in instrument'
(gem) activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
(gem) activesupport-3.2.13/lib/active_support/notifications.rb:123:in `instrument'
(gem) actionpack-3.2.13/lib/action_view/template.rb:143:in `render'
(gem) deface-0.9.1/lib/deface/action_view_extensions.rb:37:in `render'
(gem) actionpack-3.2.13/lib/action_view/renderer/partial_renderer.rb:265:in `render_partial'