Skip to content

Instantly share code, notes, and snippets.

View djgraham's full-sized avatar
:shipit:
Oh hello!

David Graham djgraham

:shipit:
Oh hello!
View GitHub Profile
@djgraham
djgraham / PPT steps for status
Created October 28, 2019 01:29
OB connection_issue! PPT steps
Login to the usual dev FA account: https://fac.intNN.free.ag
create a new bank account
Create an Open Banking Modelo feed (choose any bank feed other than RBSG), Modelo login is mits / mits
Make sure to select at least one account and and complete setup to bank feed enablement.
Go into the int server console `devkit console int<NN>`
Find the bank feed you just created (`BankFeed.last` should find it)
Make sure you can mark it as connection issue, by calling the `connection_issue!` method on the bank feed object
Check that it's state has changed to `connection_issue`
Go back into the bank account in the FA app and check that the bank feed is no longer enabled.
It will display an 'enable feed' button but don't worry about this for now. Another PR will address this.
def stop!
raise hammertime
end
def polymorphicable_path(polymorphicable, action: '')
url_for(
controller: polymorphicable.class.name.tableize,
action: action,
id: polymorphicable.id,
only_path: true
)
end
module SpreeOdoo
class StockMovementPush
attr_reader :spree_variant, :stats, :gateway, :reference, :qty
def initialize(ooor, spree_variant, qty, reference, opts = {})
@gateway = ooor
@stats = { total: 0, found: 0, adjusted: 0, errors: [] }
@spree_variant = spree_variant
@reference = reference
@qty = qty
@djgraham
djgraham / copy_translations_to_parent_models.psql
Last active January 29, 2016 10:39
Postgres queries top copy translation table data into their main parent model fields in Spree (When you want to remove the spree_i18n gem)
update spree_option_types set name = t1.name, presentation = t1.presentation from spree_option_type_translations as t1 where spree_option_types.id = t1.spree_option_type_id AND t1.locale = 'en';
update spree_option_values set name = t1.name, presentation = t1.presentation from spree_option_value_translations as t1 where spree_option_values.id = t1.spree_option_value_id AND t1.locale = 'en';
update spree_products set name = t1.name, description = t1.description, meta_description = t1.meta_description, meta_keywords = t1.meta_keywords, slug = t1.slug from spree_product_translations as t1 where spree_products.id = t1.spree_product_id and t1.locale = 'en';
update spree_promotions set name = t1.name, description = t1.description from spree_promotion_translations as t1 where spree_promotions.id = t1.spree_promotion_id AND t1.locale = 'en';
update spree_properties set name = t1.name, presentation = t1.presentation from spree_property_translations as t1 where spree_properties.id = t1.spree_property_id AND t1.lo
@djgraham
djgraham / popup.js
Created June 1, 2015 16:48
torii / popup.js fix for IE11
// IE11 version hack fix...
var ieversion = 0;
var ua = window.navigator.userAgent;
if (ua.indexOf('Trident/') != -1) {
ieversion = ua.substring(ua.indexOf('rv:') + 3);
ieversion = parseInt('' + ieversion, 10);
}
// in IE11 window.attachEvent was removed.
// if IE11 *or* window.attachEvent
if (window.attachEvent || ieversion >= 11) {
@djgraham
djgraham / extend_numeric_rounding.rb
Created February 29, 2012 07:36
Swedish Rounding module - Extends Numeric to allow you to do "swedish rounding" - see http://en.wikipedia.org/wiki/Swedish_rounding
# this module adds rounding to the nearest decimal number.
# by default it rounds to the nearest 10 pence
# but you can also round to the nearest 50 / 1000 or whatever..
#
module ExtendNumericRounding
def roundup( nearest=10 )
self % nearest == 0 ? self : self + nearest - ( self % nearest )
end
@djgraham
djgraham / comments_controller.rb
Created February 2, 2012 16:04
Really hacky way of assigning a "belongs_to" event with an attribute on the event that is allowed to change on create or update of a comment :/
def create
@event.update_attribute(:status_id, params[:comment][:event_attributes][:status_id])
params[:comment].delete(:event_attributes) # = nil # = {:id => params[:event_id]}
@comment = @event.comments.new(params[:comment])
if @comment.save
redirect_to admin_event_comments_path(@event), :flash => { :info => "Comment created" }
else
render :action => :edit
end
end
@djgraham
djgraham / payment.rb
Created January 10, 2012 13:45
payment.rb
# the wrong way..
class Payment < ActiveRecord::Base
belongs_to :booking
after_save :update_booking
def update_booking
@djgraham
djgraham / battery_info.sh
Created December 5, 2011 13:45
Bash script for linux to show you how worn your battery is
#!/bin/bash
bats=`ls /proc/acpi/battery/`;
for bat in $bats;do
remain=`cat /proc/acpi/battery/$bat/{info,state}|grep remaining|grep -o "[0-9]\+"`
full=`cat /proc/acpi/battery/$bat/{info,state}|grep full |grep -o "[0-9]\+"`
descap=`cat /proc/acpi/battery/$bat/{info,state}|grep "design capacity:" |grep -o "[0-9]\+"`
rate=`cat /proc/acpi/battery/$bat/{info,state}|grep "present rate:" |grep -o "[0-9]\+"`
state=`cat /proc/acpi/battery/$bat/{info,state}|grep "charging state:" |grep -o "[a-z]\+$"`
echo $state;
lostcap=$((((descap-full)*100)/descap));