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 / ruby_on_rails.txt
Created November 8, 2013 15:32
Ruby on Rails Windows startup script
@ECHO OFF
REM - This file is used to start-up the Rails Server on this app automatically or by clicking it.
REM - Open and save this file as a .bat and drop it in Windows Start -> All Programs -> start up folder.
REM - Point the path below to the app (stockist) for it to work. Let me know if nothing works.
CD C:\ssing\Sites\stockist
rails server webrick -p 3000 -e production
ECHO Hello Sam, Your Rails app (Stockist) is running. Press any key to close this window if it persists
@theCrab
theCrab / pdf_rails_this.rb
Created July 23, 2013 18:19
Prawn Rails this please
# Using gem prawn_rails try and put this results to a pdf in a nice format as follows:
# For each first and second array elements show the rest of the array with the following headers i.9ie
# STYLE(i[0]), COLUR(i[1]), SIZE(i[3]), STOCK(i[4]), MIN_STOCK(i[6]), REQUIRED(i[7])
[
["UD/BAG/PE/EXTRAZIP/BLACK", "**PLAIN", " |----- |", "BLACK PE BAG +ZIP", -12, 16, 28, "00015463", 0]
["UD/BAG/PE/EXTRAZIP/MAROON", "EAGLE PRIMARY(LN)", " |----- |", "MAROON PE BAG +ZIP", -15, 8, 23, "00015477", 0]
["UD/BAG/PE/EXTRAZIP/NAVY", "METHERINGHAM PRIMARY SCHOO(LN)", " |----- |", "NAVY PE BAG +ZIP", 3, 8, 5, "00015472", 0]
["UD/BAG/PE/EXTRAZIP/NAVY", "ST FAITH AND ST MARTIN COF(LN)", " |----- |", "NAVY PE BAG +ZIP", 11, 14, 3, "00015474", 0]
["UD/BAG/PE/EXTRAZIP/NAVY", "ST HUGHS CATHOLIC PRIMARY (LN)", " |----- |", "NAVY PE BAG +ZIP", -1, 14, 15, "00015475", 0]
@theCrab
theCrab / reports.rb
Created July 21, 2013 16:24
PDF report generator
# gem install rdbi rdbi-driver-odbc
require "rdbi-driver-odbc"
dbh = RDBI.connect(
:ODBC,
:db => "db_name",
:username => "db_username",
:password => "db_password"
)
worker_processes 1;
user nobody nogroup;
pid /tmp/nginx.pid;
error_log /tmp/nginx.error.log;
events {
worker_connections 1024;
accept_mutex off;
}
http {
default_type application/octet-stream;
@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'
@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 / 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 / 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 / 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 / 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|