How to Dynamically Update A Spree Product’s Price Based on Volume Pricing
I was recently working on a Spree Commerce site that utilizes Spree’s Volume Pricing extension. For those who may not be familiar, the Spree Commerce Volume Pricing extension allows a user to offer a variety of ‘price ranges’. These price ranges represent discounted prices per unit for larger quantity orders. For example (we will use this t-shirt pricing table for the remainder of the post) from the Spree Volume Pricing Github
Variant Name Range Amount Position
-------------------------------------------------------------------------------
Rails T-Shirt 1-5 (1..5) 19.99 1
Rails T-Shirt 6-9 (6...10) 18.99 2
Rails T-Shirt 10 or more (10+) 17.99 3
I would like to mention that these ranges, although resembling traditional ranges, are expressed as Strings as this will become more important later. Again from the Spree Volume Pricing project page at Github,
“All ranges need to be expressed as Strings and must include parentheses. ‘(1..10)’ is considered to be a valid range. ‘1..10’ is not considered to be a valid range …
ecommerce javascript ruby rails spree
IE7 “Enhances” href Attributes of Links Added via innerHTML
I ran into this issue the other day while testing a new feature for a client site. The code worked well in Chrome, Firefox, Safari and IE (8-11) but it blew up in IE7. The page was fairly straightforward—I was using jQuery and the excellent doT.js templating library to build up some HTML and add it to the page after the DOM had loaded. This content included several links like so:
<a href="#panel1">More Info</a>
<a href="#panel2">More Info</a>
<a href="#panel3">More Info</a>
Each of the links pointed to their corresponding counterparts which had also been added to the page. The JavaScript code in question responded to clicks on the “More Info” links and used their href attribute as a jQuery selector:
$('.my-links').on('click', function(e) {
e.preventDefault();
var sel = $(this).attr('href');
...
});
Links “Enhanced” By IE7
As I debugged in IE7, I determined that it was adding the fully qualified domain name to the links. Instead of “#panel2” the href attributes were set to “http://example.com/#panel2” which broke things—especially my jQuery selectors. Fixing the …
browsers javascript jquery tips
Install Pentaho BI Server 4.8 Community Edition with PostgreSQL Repository
Pentaho BI server community edition can be installed through an archive file available from SourceForge.
Prerequisites
- Java 6
- PostgreSQL
Download Pentaho BI Server installation file (biserver-ce-4.8.0-stable.zip) from SourceForge: http://sourceforge.net/projects/pentaho/files/Business%20Intelligence%20Server/4.8.0-stable
Unzip the archive file and navigate inside biserver-ce to set sh files to executable mode:
$ unzip biserver-ce-4.8.0-stable.zip
$ cd biserver-ce
$ find . -type f -iname '*.sh' -exec chmod a+x {} \;
Pentaho community edition uses hsql database as default. Need to create two databases in Postgres for Pentaho. Find the SQL files to create databases under biserver-ce/data/postgresql. database_name, user_name and password are configurable through SQL files. Fix two errors before creating database using SQL files. Comment two lines in below files tables as commented.
- create_quartz_postgresql.sql
ALTER TABLE qrtz_fired_triggers
ALTER TRIGGER_NAME TYPE VARCHAR(200),
ALTER TRIGGER_GROUP TYPE VARCHAR(200),
ALTER INSTANCE_NAME TYPE VARCHAR(200),
ALTER JOB_NAME TYPE VARCHAR(200),
ALTER JOB_GROUP TYPE VARCHAR(200),
ADD COLUMN …
analytics pentaho postgres casepointer
Install Pentaho BI Server 5 Enterprise Edition with PostgreSQL repository
Pentaho provides different ways to install Pentaho BI server. Each method has its own flexibility in installation.
-
Installer mode—Easy to install BA & DI server & tools in one flow with default PostgreSQL repo & default Tomcat server. (New Postgres installed on port 5432.)
-
Archive mode—BA server installed with own BA repository & default Tomcat server. Necessary tools need to be installed manually.
-
Manual mode—BA server installed with own BA repository & own application server (Tomcat or JBoss). Necessary tools need to installed manually.
We have a Postgres instance running on our server and are good with Tomcat as application server so Archive mode of installation is suitable for us. Pentaho installation requires two things be installed before starting with Pentaho installation.
- Java 7
- PostgreSQL
Archive mode installation files can be accessible only to license purchased users. Download biserver-ee-5.x-dist.zip from Pentaho customer portal with account credentials here: https://support.pentaho.com/forums/20413716-Downloads
Unzip the archive file and you can see the installation files inside extracted directory.
$ unzip biserver-ee-5.x-dist.zip
$ cd …
analytics pentaho postgres casepointer
Specify versions for your dependencies in your Gemfiles
How often have you been too lazy to put a version spec for gems you depended on in your projects? Do you fear updating the gems your app uses in production?
Here is an elusive-obvious tip for you: Always specify version numbers for your dependencies in your app’s Gemfile.
Version specs should:
-
be strict numbers for very fragile gems like Rails
-
use the pessimistic operator for others (with ~>)
Updating apps with versionless Gemfiles is painful
Newer gem versions often break compatibility. That makes updating a disaster if you don’t have any restrictions in place for your dependencies.
We should coin a new term in the field of psychology: Update Anxiety.
That’s precisely the state the vast majority of us is in when proceeding to update dependencies in our projects.
In Rails, having a versionless Gemfile makes clean updates impossible.
Fearing the update makes your app susceptible to bugs
Newer versions of gems are there, not only for delivering new features. The history of changes between different versions mostly show changes related to bug fixes. If you see a gem which mostly delivers new features without fixing bugs—stay away from it!
If you do not update the gem set out …
ruby rails
Installing CentOS 5 on a 3 TB Drive
In collaboration with Spencer Christensen and Lele Calo.
The everyday problem: Set up a remotely-hosted machine with a 3 TB drive.
The bigger problem: It must be CentOS 5.
While this would be a trivial task with a newer OS, CentOS 5 only supports MBR style partitioning, which itself only supports drives less than 2 TB in size; well let us be clear, the installer and GRUB shipped with the installation disk only support MBR normally, the kernel supports the GPT format. GPT is a newer partition format that was introduced by EFI standard, which can support booting from large devices. From various documents and postings on the internet it seemed possible to still use MBR with more than 2TB, but in practice this turned out to be completely unsuccessful. So we moved on with a plan to use GPT.
Since the CentOS 5 installer cannot work with GPT partition tables, we needed to use something else to create the partitions we wanted. We did this by using a rescue CD, like SystemRescue CD from here http://www.sysresccd.org/Download.
-
Boot into the rescue CD
-
Use gdisk to first delete the old partition table to make sure you start cleanly.
- gdisk, then x (for extended commands), then z to delete. …
redhat devops
Slony Migration experience version 1.2 to version 2.2
We recently had a client who upgraded from Slony 1.2 to Slony 2.2, and I want to take this opportunity to report on our experiences with the migration process.
A little background: This client has a fairly large database (300GB) replicated across 5 database nodes, with the slon daemons running on a single shared box. We wanted to upgrade to the latest Slony 2 version for stability and to resolve some known and unresolvable issues with the 1.2 branch of Slony when replication lags a specific amount.
As is usual for any large migration projects such as this, we had to deal with a set of tradeoffs:
-
Firstly, minimize any necessary downtime.
-
Secondly, allow for rollback due to any discovered issues.
-
Thirdly, ensure that we have sufficient redundancy/capacity whichever final state we were to end up in (i.e., successful migration to Slony 2 or reversion to Slony 1.2).
We of course tested the process several times in order to ensure that the processes we came up with would work and that we would be well-equipped to handle issues were they to arrive.
The upgrade from Slony 1.2 to Slony 2.2 necessarily requires that we uninstall the Slony 1.2 system and triggers from the indicated …
postgres replication
SELinux and the need of talking about problems
It’s known common sense that when there’s a problem you should talk about it
Well sometimes it seems like SELinux doesn’t agree, so that it quietly blocks your software and silently fail.
In this case the issue with SELinux is that since it’s usually a very talkative type of software (through /var/log/audit/auditd.log and sometimes /var/log/messages), the poor busy system administrator would kinda take it for granted that when there will be a problem SELinux will shout it out as usual.
Unfortunately that’s not the case if the permission/property involved has the dontaudit setting applied.
So a quick solution is to temporarily set SELinux to “permissive” so to check that it is actually causing the problem; basically if your script works after setting SELinux to permissive and stops again when resetting to enforce, then you’re on the good path to find your solution.
The next step would be to temporarily disable dontaudit settings with
semodule -DB
And then start to manually collect all the failing rules related to your problem and crafting a new custom SELinux module with these.
After finishing creating your module, follow your usual SELinux pluggable module management workflow and …
redhat selinux