Shopify Python API Undocumented

This was frustrating. Both pyactiveresource and Shopify Python API are undocumented, and looking at the source is frustrating as it’s all so dynamic. Had to go all the way to activeresource.
To query a record which relies on another one, pass the class constructor an argument called `prefix_options`. In it must be a dict which corresponds to arguments in the URL (look at source) denoted by source_prefix.

In my case, source_prefix contained $product_id, so my call looked like this:

image = shopify.Image(prefix_options={‘product_id’: product.id})

Use Viewport Relative Units

I just learned about viewport relative units, vh, vw, vmax, vmin.

Amazing. Finally an easy way to do full height elements via 100vh == 100% viewport height.

Only problem? It blows up explosively on IOS devices.

I love the concept though, so I just created a simple coffeescript class which can be invoked directly or via data tags to trigger widths and heights correctly by converting an inline data attribute to explicit calculations on resize.

Parsing CSS for these new units was too much overhead.

https://gist.github.com/yuchant/8610909

Usage:
<div data-viewport-styles="width: 100vh; height: 50vw;"></div>

class root.utils.ViewportHeight
‘The VH unit is not well supported. Use data-tags instead.
data-viewport-unit="line-height: 100vh; height: 100vh;’
constructor: ({@element, @styles}={}) ->
@$element = $ @element
@$window = $ window
@_bindHandlers()

_getStyles: ->
# get styles as array
if not @_styles
styles = {}
for style in _.filter(@styles.split(‘;’), Boolean)
[key, value] = style.split(‘:’)
styles[key.trim()] = @_getValue(value)
self._styles = styles
return self._styles

_bindHandlers: ->
$(window).resize _.debounce(@onResize, 50)

_getValue: (value) ->
# given a unit like 400vw or 400vh, set it to absolute pixel values
# map viewport units to viewport unit conversion functions
viewportUnitMap = {
‘vh’: @_vh,
‘vw’: @_vw,
‘vmax’: null,
‘vmin’: null,
}
value = value.replace(‘;’, ”).trim()
for unit, func of viewportUnitMap
if unit.substr(value)
return func(parseInt(value))

_vh: (value) =>
@$window.height() * value/100

_vw: (value) =>
@$window.width() * value/100

_vmax: (value) =>
return Math.max @_vh(value), @_vw(value)

_vmin: (value) =>
return Math.min @_vh(value), @_vw(value)

onResize: =>
# window has been resized. update CSS values of vh/vw equivalents
@$element.css @_getStyles()

$("[data-viewport-styles]").each (index, el) ->
new root.utils.ViewportHeight
element: el
styles: $(el).data(‘viewport-styles’)

Use native SQLAlchemy in Flask-DebugToolbar

Flask-DebugToolbar only works with Flask-SQLAlchemy.

If you’re using native sqlalchemy, it turns out it’s pretty simple to activate. Instantiate the class below with your sqlalchemy DB engine and flask app.

from flask.ext.sqlalchemy import _EngineDebuggingSignalEvents
_EngineDebuggingSignalEvents(engine, app.import_name).register()

Installing psycopg2 on OSX Mavericks

There are a ton of posts on this subject… with 100 different fixes.

You need Xcode / command line tools / GCC etc. of course.

Most importantly the piece that solved my issue was described here
http://stackoverflow.com/questions/18667916/installing-psycopg2-has-it-stuck-between-xcrun-and-lipo

 ln /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/lipo /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo 
 xcrun -k lipo

How to cross fade elements with variable heights: Responsive Design’s Dirty Little Secret

John Albin Wilkins article on responsive design’s dirty little secret is extremely useful.
http://www.palantir.net/blog/responsive-design-s-dirty-little-secret

The core theory is floating elements with margin-right: -100%;

Your "grid" elements are all floated, with margin-left: X%, and margin-right: -100%.

At first, i didn’t really know what to make of it.. now it’s a critical part of my toolbox.

What this lets you do is stack elements on top of each other, positioning purely by the margin-left attribute. The negative margin right allows you to use what almost looks like absolute positioning, but while still keeping the elements "in the flow" vertically.

That’s right.. with this trick, you can still have vertical flow while giving up horizontal flow.

Every time you’ve used absolute positioning to achieve a cross fade, but had to hard code the height value, you could have just used this instead.

Give it a shot!

TL;DR: the dirty little secret allows you to retain vertical page flow, while removing elements from horizontal page flow. Oh my goodness. This should be CSS 101.

OSX Web Development: Install Dash and Sublime Integration

This is ridiculous.

If you develop on a mac, you must download dash, now.

http://kapeli.com/

It allows you to keep an offline copy of docs, and makes them all searchable from the same interface (very fast).

You can even integrate with Sublime, and push CNTRL+H over a word to look it up in dash.

50% of development is looking up docs. This is a game changer.

I just installed offline docs for..

  • html
  • compass
  • sass
  • jquery
  • javascript
  • underscore
  • coffeescript
  • vagrant
  • postgresql
  • python
  • django
  • flask
  • php

All from one interface. Really awesome.