This is the script we use at yerdle to print labels from our Rails backend to our Zebra ZP450 printer.
See this blog post for the whole story.
| require 'prawn' | |
| require 'prawn/measurements' | |
| # I have a small collection of links to the resources I used to figure all | |
| # this out: http://pinboard.in/u:fidothe/t:pdfx | |
| module PDFX | |
| class PageBox | |
| include Prawn::Measurements | |
| attr_reader :bleed_mm |
| gem 'rails', '4.1.1' | |
| # Use jquery as the JavaScript library | |
| gem 'jquery-rails' | |
| # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks | |
| gem 'turbolinks' | |
| gem 'jquery-turbolinks' | |
| # Gems for twitter LESS -> CSS and JS support | |
| gem 'execjs' |
| class Armband | |
| def initialize(encounter, options = {}) | |
| @encounter = encounter | |
| end | |
| def to_zpl(format) | |
| # Units are in dots | |
| zpl = "^XA" # ZPL Begin | |
| zpl << "^LH0,0" # Home position X, Y | |
| zpl << "^PON" # Print orientation normal |
This is the script we use at yerdle to print labels from our Rails backend to our Zebra ZP450 printer.
See this blog post for the whole story.
| #!/usr/bin/env ruby | |
| require "with_args" # TBA | |
| class User | |
| with_args String, | |
| def name=(name) | |
| @name = name | |
| end |
| # Print a label on a Zebra TLP 2844 in Ruby. | |
| # The printer is EPL/2 capable and connected via USB. | |
| # EPL/2 reference: http://www.zebra.com/apps/dlmanager?dlp=-227178c9720c025483893483886ea54a70963bb77ca94fcc1d65ce9394326ed960e43d023beba35831d5d9bfc1740296347157b5024977a&c=gb&l=en | |
| # https://github.com/larskanis/libusb | |
| require 'libusb' | |
| # Select the printer by vendor ID and product ID. | |
| # To get a list of connected devices, use 'lsusb'. | |
| # 0a5f:0x000a identifies the Zebra TLP 2844. |
| class Array | |
| def freq_by &block | |
| group_by(&block).map {|k,v| [k, v.count] }.sort_by(&:first) | |
| end | |
| def freq | |
| freq_by {|e| e } | |
| end | |
| end |
| class Reverb::Actions::WatchListing | |
| def self.watch(user, product, listener) | |
| if product.owner?(user) | |
| listener.failure(I18n.t('flash.watchlist.error_own')) | |
| else | |
| Reverb::Analytics.track(user, :watch_product) # FIXME, this doesn't belong here | |
| user.user_watch_products.create(:product_id => product.id) | |
| listener.success | |
| end | |
| end |
You can break these rules if you can talk your pair into agreeing with you.
| # Written for this gist, but inspired by production code (I haven't run this code). | |
| # Imperative shell | |
| class Timer | |
| def initialize(record) | |
| @record = record | |
| end | |
| def start | |
| save_changes clock.start |