Firefox, Input (type=button), and Line-Height
I recently discovered a discrepancy in the way Firefox treats inputs with a line-height style defined and how other browsers handle the same styling rule. Specifically, Firefox completely ignores it.
This behavior seemed odd enough to me that I did some Googling to determine if this was recently introduced, a long standing issue, or something I was just doing wrong. I found some interesting discussions on the issue. Several of the search results used the word “bug” in the title though it appears to be more of a deliberate (though possibly outdated) “feature” instead. Along with the discussions, I also came across a couple of suggestions for a solution.
First of all, I was able to locate a simple enough explanation of what’s causing the behavior. As Rob Glazebrook explains:
Basically, Firefox is setting the line-height to “normal” on buttons and is enforcing this decision with an !important declaration.” and, “browser-defined !important rules cannot be over-ruled by author-defined !important rules. This rule cannot be overruled by a CSS file, an inline style—anything.
Good news is I can stop experimenting hoping for different results.
I also located a Bugzilla ticket opened in …
browsers
Piggybak: Upgrade to Rails 4.1.0
Piggybak and gems available in the demo (piggybak_variants, piggybak_giftcerts, piggybak_coupons, piggybak_bundle_discounts, piggybak_taxonomy) have been updated to Rails 4.1.0, Ruby 2.1.1 via Piggybak version gem 0.7.1. Interested in the technical details of the upgrade? Here are some fine points:
- Dependencies were refactored so that the parent Rails app controls the Rails dependency only. There was a bit of redundancy in the various plugin gemspec dependencies. This has been cleaned up so the parent Rails app shall be the canonical reference to the Rails version used in the application.
- Modified use of assets which require “//= require piggybak/piggybak-application” to be added to the assets moving forward. There have been several observed issues with precompling and asset behavior, so I simplified this by requiring this require to be added to the main Rails application.js for now. The engine file is supposed to have a way around this, but it has not behaved as expected, specifically on unique deployment architectures (e.g. Heroku). Patches welcome to address this.
- Tables migrated to namespaced tables, e.g. “orders” migrated to “piggybak_orders”. This is how namespaced engine …
piggybak rails ecommerce
jQuery Content Replacement with AJAX
This is not a huge breakthrough, but it colored in some gaps in my knowledge so I thought I would share.
Let’s say you have a product flypage for a widget that comes in several colors. Other than some of the descriptive text, and maybe a hidden field for use in ordering one color instead of another, all the pages look the same. So your page looks like this (extremely simplified):
... a lot of boilerplate ...
<form id="order_item">
<input name="sku" type="hidden" value="WDGT-001-RED"/>
<input type="hidden"/>
</form>
... a lot more boilerplate ...Probably the page is generated into a template based on a parameter or path segment:
http://.../app/product/WDGT-001-REDWhat we’re going to add is a quick-and-dirty way of having your page rewrite itself on the fly with just the bits that change when you select a different version (or variant) of the same product. E.g.,
<select name="sku">
<option value="WDGT-001-RED">Cinnamon Surprise</option>
<option value="WDGT-002-BLK">Midnight Delight</option>
<option value="WDGT-003-YLW">Banana Rama</option> …javascript jquery html
SPF, DKIM and DMARC brief explanation and best practices
Spam mail messages have been a plague since the Internet became popular and they kept growing more and more as the number of devices and people connected grew. Despite the numerous attempts of creation of anti-spam tools, there’s still a fairly high number of unwanted messages sent every day.
Luckily it seems that lately something is changing with the adoption of three (relatively) new tools which are starting to be widely used: SPF, DKIM and DMARC. Let’s have a quick look at each of these tools and what they achieve.
What are SPF, DKIM and DMARC
SPF (Sender Policy Framework) is a DNS text entry which shows a list of servers that should be considered allowed to send mail for a specific domain. Incidentally the fact that SPF is a DNS entry can also considered a way to enforce the fact that the list is authoritative for the domain, since the owners/administrators are the only people allowed to add/change that main domain zone.
DKIM (DomainKeys Identified Mail) should be instead considered a method to verify that the messages’ content are trustworthy, meaning that they weren’t changed from the moment the message left the initial mail server. This additional layer of trustability is …
Speeding Up Saving Millions of ORM Objects in PostgreSQL
The Problem
Sometimes you need to generate sample data, like random data for tests. Sometimes you need to generate it with huge amount of code you have in your ORM mappings, just because an architect decided that all the logic needs to be stored in the ORM, and the database should be just a dummy data container. The real reason is not important—the problem is: let’s generate lots of, millions of rows, for a sample table from ORM mappings.
Sometimes the data is read from a file, but due to business logic kept in ORM, you need to load the data from file to ORM and then save the millions of ORM objects to database.
This can be done in many different ways, but here I will concentrate on making that as fast as possible.
I will use PostgreSQL and SQLAlchemy (with psycopg2) for ORM, so all the code will be implemented in Python. I will create a couple of functions, each implementing another solution for saving the data to the database, and I will test them using 10k and 100k of generated ORM objects.
Sample Table
The table I used is quite simple, just a simplified blog post:
CREATE TABLE posts (
id SERIAL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT NOT NULL,
payload TEXT NOT NULL …performance postgres python
Sanity, thy name is not MySQL
Probably old news, but I hit this MySQL oddity today after a long day dealing with unrelated crazy stuff and it just made me go cross-eyed:
CREATE TABLE foo (id integer, val enum('','1'));
INSERT INTO foo VALUES (1, '');
INSERT INTO foo VALUES (2, '1');
SELECT * FROM foo WHERE val = 1;What row do you get? I’ll wait while you second- and third-guess yourself.
It turns out that the “enum” datatype in MySQL just translates to a set of unique integer values. In our case, that means:
- ’’ == 1
- ‘1’ == 2
So you get the row with (1,’’). Now, if that doesn’t confuse readers of your code, I don’t know what will.
mysql
Filling Gaps in Cumulative Sum in Postgres
I found an interesting problem. There was a table with some data, among which there was a date and an integer value. The problem was to get cumulative sum for all the dates, however including dates for which we don’t have entries. In case of such dates we should use the last calculated sum.
Example Data
I will use an example table:
# CREATE TABLE test (d DATE, v INTEGER);with sample data:
# INSERT INTO test(d,v)
VALUES('2014-02-01', 10),
('2014-02-02', 30),
('2014-02-05', 10),
('2014-02-10', 3);Then the data in the table looks like:
# SELECT * FROM test;
d | v
------------+----
2014-02-01 | 10
2014-02-02 | 30
2014-02-05 | 10
2014-02-10 | 3
(4 rows)What I want is to have a cumulative sum for each day. Cumulative sum is a sum for all the earlier numbers, so for the above data I want to get:
d | v
------------+----
2014-02-01 | 10
2014-02-02 | 40
2014-02-05 | 50
2014-02-10 | 53
(4 rows)The simple query for getting the data set like shown above is:
SELECT DISTINCT d, SUM(v) OVER (ORDER BY d) v
FROM test
ORDER BY d ASC;Filling The Gaps
The query calculates the cumulative sum for each row. …
postgres
Open Source: Challenges of Modularity and Extensibility
While I was at the I Annotate 2014 conference last week, I spoke with a couple developers about the challenges of working in open source. Specifically, the Annotator JavaScript library that we are using for H2O is getting a bit of a push from the community to decouple (or make more modular) some components as well as improve the extensibility. Similarly, Spree, an open source Ruby on Rails platform that End Point has sponsored in the past and continued to work with, made a shift from a monolithic platform to a modular (via Ruby gems) approach, and Piggybak started out as a modular and extensible ecommerce solution. I like doodling, so here’s a diagram that represents the ecosystem of building out an open source tool with a supplemental explanation below:
Here are some questions I consider on these topics:
-
What is the cost of extensibility?
- code complexity
- code maintenance (indirectly, as code complexity increases)
- harder learning curve for new developers (indirectly, as code complexity increases)
- performance implications (possibly, indirectly, as code complexity increases)
- difficulty in testing code (possibly)
-
What is the cost of modularity?
- same as cost of extensibility …
open-source