Skip to content

Instantly share code, notes, and snippets.

View sleroux's full-sized avatar
:shipit:
on the loose

Stephan Leroux sleroux

:shipit:
on the loose
  • Shopify
  • Toronto, ON, Canada
View GitHub Profile
var data2xml = require("data2xml"),
key = 'splashScreen',
xmlObject = {},
imgPath = "dummyImage.png";
xmlObject[key] = {},
xmlObject[key]['image'] = [];
// Push 2 different images for each localization
xmlObject[key]["image"].push({
@sleroux
sleroux / gist:4568466
Created January 18, 2013 20:58
Using Fibers to write linear callback code
require 'eventmachine'
require 'em-http'
require 'fiber'
# Borrowed from http://www.igvita.com/2010/03/22/untangling-evented-code-with-ruby-fibers/
def async_fetch(url)
# Grab a reference to which fiber I am
f = Fiber.current
@sleroux
sleroux / gist:5143923
Created March 12, 2013 15:36
iOS web debugginator
#!/bin/bash
# Open iPhone Simulator on default location for XCode 4.3 if found
[[ -d /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/ ]] &&
open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app
# Open iPhone Simulator on default location for XCode 4.2 if found
[[ -d /Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/ ]] &&
open /Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app
@sleroux
sleroux / gist:eb82bbbfb41e92747b09
Created May 21, 2015 17:55
To be lazy or not to be...
lazy var myLabel: UILabel = {
var temporaryLabel : UILabel = UILabel()
return temporaryLabel
}()
let testLabel: UILabel {
if !_testLabel {
_testLabel = UILabel()
}
return _testLabel!
func testFaviconTable() {
let files = MockFiles()
let db = BrowserDB(files: files)
let history = SQLiteHistory(db: db)
let bookmarks = SQLiteBookmarks(db: db, favicons: history)
let expectation = self.expectationWithDescription("First.")
func done() -> Success {
expectation.fulfill()
return succeed()
enum moz_sizeClass {
case Unknown
case XSmall
case Small
case Medium
case Large
case XLarge
case XXLarge
case XXXLarge
@sleroux
sleroux / gist:f5f47b8d17da0d4f87b2
Created June 15, 2015 19:12
TLD Parsing code from Gecko
// Finds the base domain for a host, with requested number of additional parts.
// This will fail, generating an error, if the host is an IPv4/IPv6 address,
// if more subdomain parts are requested than are available, or if the hostname
// includes characters that are not valid in a URL. Normalization is performed
// on the host string and the result will be in UTF8.
nsresult
nsEffectiveTLDService::GetBaseDomainInternal(nsCString &aHostname,
int32_t aAdditionalParts,
nsACString &aBaseDomain)
{
Storage!_TFFC7Storage12BrowserTable11updateTableFS0_FTCS_18SQLiteDBConnection4fromSi2toSi_SbU_FCS_5SDRowSS + 0x108
fp = 0x000000016fdfc850 lr = 0x00000001005b11f4
sp = 0x000000016fdfc840 pc = 0x00000001005c4c14
Found by: previous frame's frame pointer
11 Storage!_TTRXFo_oC7Storage5SDRow_oSS_XFo_oS0__iSS_ + 0x1c
fp = 0x000000016fdfcb00 lr = 0x000000010059a828
sp = 0x000000016fdfc860 pc = 0x00000001005b11f4
Found by: previous frame's frame pointer
12 Storage!_TZFC7StorageP33_3F4389F18684E136A114953F0C3F855C18FilledSQLiteCursor9getValuesU__fMGS0_Q__FTCS_P33_3F4389F18684E136A114953F0C3F855C17SQLiteDBStatement7factoryFCS_5SDRowQ_6statusROS_12CursorStatus13statusMessageRSS_GSaQ__ + 0x4e4
fp = 0x000000016fdfcbe0 lr = 0x000000010059a2a4
@sleroux
sleroux / frecency.md
Last active October 14, 2015 19:57
Frecency/Top Sites Optimization

The frecency query [1] we're making for our search recommendations/top sites is painfully slow. The query can up to a few seconds before completing. This is noticeable in places such as Top Sites where we run this query every time the user visits the panel. The items in Top Sites don’t render until the query completes. When taking a closer look at the query we're running to determine frecency, there are a number of factors which are causing it to be slow. Unlike desktop, frecency on mobile is calculated in real time instead of being pre-calculated. This results in a complex query that touches various tables with inner joins and computationally expensive ORDER/COALESCE operations. The query is then run on a potentially large data set since it touches the history table. In cases where a user has attached their FxA account, their desktop history will also be part of this.

After some discussion, there are 2 approaches we can take to optimize the way we handle frecency:

  1. Tweak/modify the existing query. Th