Skip to content

Instantly share code, notes, and snippets.

View dmolesUC's full-sized avatar

David Moles dmolesUC

View GitHub Profile
@dmolesUC
dmolesUC / TableHeightDemo.java
Created December 19, 2017 19:08
Showing only populated rows in a JavaFx TableView
import javafx.application.Application;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.skin.TableHeaderRow;
import javafx.stage.Stage;
@dmolesUC
dmolesUC / webfonts-to-local.rb
Created July 31, 2018 17:18
Script for downloading webfont files from Google Web Fonts CSS and converting CSS to point to local copies
#!/usr/bin/env ruby
require 'pathname'
infile = ARGV[0]
fonts_dir = ARGV[1]
unless infile && fonts_dir
puts "Usage: webfonts-to-local.rb <INPUT-CSS> <FONTS-DIR>"
exit(1)
@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"
@dmolesUC
dmolesUC / hide-network-questions.js
Last active July 9, 2019 20:00
Tampermonkey script for hiding certain StackExchange sites from the "Hot Network Questions" section
// ==UserScript==
// @name Hide Hot Network Questions
// @namespace GreaseMonkeyStackOverflow
// @description Hides certain Hot Network Questions on Stack Overflow
// @include http://*.stackexchange.com/*
// @include http://stackoverflow.com/*
// @include http://*.stackoverflow.com/*
// @include http://*.askubuntu.com/*
// @include http://*.mathoverflow.com/*
// @include http://*.serverfault.com/*
@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 / 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 / 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 / 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
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 / 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.-_~ *+'