Skip to content

Instantly share code, notes, and snippets.

View dmolesUC's full-sized avatar

David Moles dmolesUC

View GitHub Profile
@dmolesUC
dmolesUC / LICENSE.md
Last active February 2, 2022 16:56
Quick and dirty Sprockets wrapper fror https://github.com/ntkme/sass-embedded-host-ruby

The MIT License (MIT)

Copyright © 2021 The Regents of the University of California

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

@dmolesUC
dmolesUC / encoding-problems.sh
Created August 5, 2021 19:36
Grep command to locate possible Windows 1252 <-> UTF-8 encoding problems
# After https://www.i18nqa.com/debug/utf8-debug.html
#
# A more sophisticated version of this would grep for suspicious sequences-of-sequences;
# if the file legit contains accented characters, this will show it as a false positive
find . -name marc.xml -exec env LANG=LC_ALL grep -Pl '(\xc2|\xc3|\xc5|\xc6|\xcb|\xe2)' {} \;
@dmolesUC
dmolesUC / escape-uris.rb
Last active November 12, 2020 22:05
Escaping URIs in Ruby
#!/usr/bin/env ruby
# coding: utf-8
require 'addressable'
require 'cgi'
require 'erb'
require 'uri'
# base_url = 'https://user:password !$&' + "'" + '()*+,;=@host.domain/path:?#@-.+_~/ path!$&' + "'" + '()*+,;=.cgi'
# query = 'query1.-_~ *+,;=value1.-_~ *+'
getent passwd | cut -f1 -d: | while read user; do crontab=$(sudo crontab -u $user -l 2>/dev/null) && echo -e "\n$user:\n$crontab"; done
@dmolesUC
dmolesUC / entrypoint.sh
Created October 21, 2020 18:12
Start and terminate multiple sevices
# ########################################
# Start server and manager in background
/start-server.sh &
SERVER_PID=$!
/start-manager.sh &
MANAGER_PID=$!
# ########################################
@dmolesUC
dmolesUC / rake-task-monkey-patch.rb
Last active October 16, 2020 23:45
Monkey-patch Rake::Task to show all task invocations
# In your Rakefile (after Rails.application.load_tasks, in a Rails project):
module TaskExtensions
def invoke
(@logger ||= Logger.new($stderr)).tap do |logger|
logger.info("invoke #{self.name}") # note: you can also dump environment variables etc. here
end
super
end
end
@dmolesUC
dmolesUC / ruby-1.8.7-catalina.md
Created August 27, 2020 16:45
Installing Ruby 1.8.7 on macOS Catalina with Homebrew and 0penSSL 1.0

Cf. this StackOverflow answer:

brew install rbenv/tap/openssl@1.0

rvm reinstall 1.8.7-head --with-openssl-dir='/usr/local/Cellar/openssl@1.0/1.0.2t' \
  --with-openssl-lib='/usr/local/Cellar/openssl@1.0/1.0.2t/lib' \
  --with-openssl-include=/usr/local/Cellar/openssl@1.0/1.0.2t/include

rvm use 1.8.7
@dmolesUC
dmolesUC / sqlite3-pcre.md
Last active July 9, 2020 23:41
Installing sqlite3-pcre on macOS
  1. Decide where you're going to put the compiled library, e.g. ~/lib. We'll call this <target-dir> below.

  2. Clone ralight/sqlite3-pcre

  3. Ensure pcre is installed (brew install pcre).

  4. In the sqlite3-pcre directory, compile with:

    cc \
      -shared \

-o /sqlite3-pcre.so \

@dmolesUC
dmolesUC / seed_dump-standalone.md
Created February 12, 2020 17:42
Using the seed_dump gem with StandaloneMigrations

The seed-dump gem generates db/seeds.rb for a Rails project from an existing database. It also works outside of Rails with standalone-migrations, but you need to jump through a couple of hoops to set up the Rake task and give it access to your model classes.

In your Gemfile:

gem 'seed_dump'
@dmolesUC
dmolesUC / aws_credentials_timeout.go
Last active January 7, 2019 21:13
Demonstration of AWS credentials timeout issue (https://github.com/aws/aws-sdk-go/issues/2392)
package main
import (
"fmt"
"io/ioutil"
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"