(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| # https://coderwall.com/p/qp2aha/ruby-pbcopy-and-pbpaste | |
| def pbcopy(input) | |
| str = input.to_s | |
| IO.popen('pbcopy', 'w') { |f| f << str } | |
| str | |
| end |
| # gem install benchmark-ips | |
| require "benchmark/ips" | |
| path = "lib/rubycritic/cli/options.rb" | |
| Benchmark.ips do |x| | |
| x.report("read + each_line") { File.read(path).each_line.count } | |
| x.report("open + each_line") { File.open(path, "r").each_line.count } |
| # Exponential backoff in Ruby | |
| begin | |
| make_request | |
| rescue RequestError => e | |
| if retries <= max_retries | |
| retries += 1 | |
| sleep 2 ** retries | |
| retry | |
| else | |
| raise "Timeout: #{e.message}" |
| See question on stack overflow: http://stackoverflow.com/questions/28595636/rails-4-how-to-give-alias-names-to-includes-and-joins-in-active-record-que | |
| - Model Student and model Teacher are both STI models with super class model User | |
| - Model Story is a STI model with super class model Task | |
| - includes() and joins(), both fails | |
| Rails alias naming convention (includes() and joins()) | |
| - One model as parameter | |
| - is base model (includes(:users)) |
| function getHightlightCoords() { | |
| var pageIndex = PDFViewerApplication.pdfViewer.currentPageNumber - 1; | |
| var page = PDFViewerApplication.pdfViewer.getPageView(pageIndex); | |
| var pageRect = page.canvas.getClientRects()[0]; | |
| var selectionRects = window.getSelection().getRangeAt(0).getClientRects(); | |
| var viewport = page.viewport; | |
| var selected = selectionRects.map(function (r) { | |
| return viewport.convertToPdfPoint(r.left - pageRect.x, r.top - pageRect.y).concat( | |
| viewport.convertToPdfPoint(r.right - pageRect.x, r.bottom - pageRect.y)); | |
| }); |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
For reference: http://postgis.net/install
The most reliable way to get PostGIS on OSX is to download and install Postgres.app. Great for development and testing. Do not mix with other installations. Select the extension when prompted.
Note: This guide works with Ruby 2.6+ through Ruby 3.x, with modern Ruby 3.x features highlighted where applicable. Core metaprogramming concepts remain consistent across Ruby versions.
This document has been collaboratively updated and modernized through an interactive process with Claude Code, revised with examples, visual diagrams, and Ruby 3.x compatibility.
| bryan: | |
| email: clarkbw@example.com | |
| encrypted_password: <%= User.new.send(:password_digest, '1234567890') %> | |
| confirmed_at: <%= Time.zone.now - 1.hour %> | |
| confirmation_sent_at: <%= Time.zone.now - 2.hours %> |