Skip to content

Instantly share code, notes, and snippets.

@roberthopman
roberthopman / bidi-example.rb
Created May 5, 2025 06:59 — forked from dieter-medium/bidi-example.rb
This proof of concept demonstrates how to generate a PDF from a local HTML file using plain Ruby and WebDriver BiDi. The script starts Chromedriver in headless mode, creates a new browsing context via BiDi, navigates to the specified local file (using a placeholder for the file path), and prints the page as a PDF over a WebSocket connection. No …
#!/usr/bin/env ruby
# see:
# https://w3c.github.io/webdriver-bidi/#command-browsingContext-print
# https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF
# https://github.com/GoogleChromeLabs/chromium-bidi/blob/main/examples/print_example.py
# https://github.com/GoogleChromeLabs/chromium-bidi/blob/main/examples/_helpers.py
require 'net/http'
@roberthopman
roberthopman / routes_to_csv.rb
Last active March 25, 2025 19:19 — forked from adamdullenty/routes_csv.rake
copy paste rails routes to csv
# Add as Rake task or Rails console
class CSVFormatter
def initialize
@buffer = []
end
def result
@buffer.join("\n")
end
@roberthopman
roberthopman / system-wide-clipboard.zsh
Created May 5, 2024 15:58 — forked from welldan97/system-wide-clipboard.zsh
Zsh copy & paste system wide for OS X, like in emacs
pb-kill-line () {
zle kill-line
echo -n $CUTBUFFER | pbcopy
}
pb-kill-whole-line () {
zle kill-whole-line
echo -n $CUTBUFFER | pbcopy
}
  • Dynamic Dispatch
  • Dynamic Method
  • Ghost Methods
  • Dynamic Proxies
  • Blank Slate
  • Kernel Method
  • Flattening the Scope (aka Nested Lexical Scopes)
  • Context Probe
  • Class Eval (not really a 'spell' more just a demonstration of its usage)
  • Class Macros

Step 1: add a migration, assuming usage of ActsAsTaggableOn - though any Tag model would work.

Adding :archived_at as bonus...

# frozen_string_literal: true

class CreateTagSettings < ActiveRecord::Migration[6.1]
  def change
 create_table :tag_settings do |t|
@roberthopman
roberthopman / script.sh
Created June 11, 2023 09:29 — forked from vielhuber/script.sh
PostgreSQL: Backup and restore export import pg_dump with password on command line #sql
# best practice: linux
nano ~/.pgpass
*:5432:*:username:password
chmod 0600 ~/.pgpass
# best practice: windows
edit %APPDATA%\postgresql\pgpass.conf
*:5432:*:username:password
# linux
// optimized for rails
document.addEventListener("turbolinks:load", () => {
$('[data-toggle="tooltip"]').tooltip()
$('[data-toggle="popover"]').popover()
if (document.querySelector('#target-btn')) {
// start of the actual copy paste action
document.querySelector('#target-btn').addEventListener("click", (event) => {
var el = document.getElementById("target-table");
var body = document.body, range, sel;
@roberthopman
roberthopman / Selenium Cheat Sheet.md
Created February 7, 2021 16:42 — forked from kenrett/Selenium Cheat Sheet.md
Selenium Cheat Sheet - Ruby

#Getting Started

##Webpage:

<html>
<head>
    <title>Testing with Ruby and Selenium WebDriver</title>
</head>
 
<body bgcolor="antiquewhite">
@roberthopman
roberthopman / capybara cheat sheet
Created November 4, 2020 10:33 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
require 'csv'
namespace :csv do
desc "generates a migration file from column names from the CSV headers"
task create_migration: :environment do
def headers_from_CSV (filename)
csv_header_array = CSV.read(filename, headers: true).headers
return csv_header_array.map { |col_a| col_a.strip.downcase.gsub(' ', '_').gsub('.', '_') }
end