Skip to content

Instantly share code, notes, and snippets.

@fidothe
fidothe / pdfx.rb
Last active October 10, 2023 15:57
Worked example for creating a PDF/X-1a:2003 document with Prawn
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
@chrisjacob
chrisjacob / Gemfile
Last active February 6, 2020 08:26
Simple guide to integrating Pages v1.0.0 with Rails v4.1.1
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'
@masonjm
masonjm / zpl armband
Created May 23, 2014 19:52
Example of printing an armband to a ZPL printer.
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
@tashian
tashian / README.md
Last active December 4, 2020 17:52
Just-in-time label printing on the Zebra ZP450 using node.js + Easypost + Pusher + cups

This is the script we use at yerdle to print labels from our Rails backend to our Zebra ZP450 printer.

the Zebra

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
@sepastian
sepastian / zebra.rb
Last active January 15, 2018 07:28
Print a label on a Zebra TLP 2844 in Ruby. The printer is EPL/2 capable and connected via USB.
# 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.
@michaelfeathers
michaelfeathers / dentdetect.rb
Last active December 16, 2015 07:08
Attempt to discern number of spaces used for an indent across a set of source files.
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
@skwp
skwp / watch_listing.rb
Last active December 15, 2015 18:09
Hexagonal extraction of a controller action from reverb.com, showing reuse between controller and Grape/Roar based API. This is sample code stripped down to the essentials and is not guaranteed to work as-is :)
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
@henrik
henrik / rules.md
Last active May 23, 2022 12:31
Sandi Metz' four rules from Ruby Rogues episode 87. Listen or read the transcript: http://rubyrogues.com/087-rr-book-clubpractical-object-oriented-design-in-ruby-with-sandi-metz/
  1. Your class can be no longer than 100 lines of code.
  2. Your methods can be no longer than five lines of code.
  3. You can pass no more than four parameters and you can’t just make it one big hash.
  4. When a call comes into your Rails controller, you can only instantiate one object to do whatever it is that needs to be done. And your view can only know about one instance variable.

You can break these rules if you can talk your pair into agreeing with you.

@joakimk
joakimk / functional_core_imperative_shell.rb
Last active October 14, 2015 00:27
An example of "functional core, imperative shell" as far as I understand it. For more info about this concept, see https://www.destroyallsoftware.com/screencasts/catalog/functional-core-imperative-shell.
# 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