Skip to content

Instantly share code, notes, and snippets.

David Moles dmolesUC

Block or report user

Report or block dmolesUC

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dmolesUC
dmolesUC / seed_dump-standalone.md
Created Feb 12, 2020
Using the seed_dump gem with StandaloneMigrations
View seed_dump-standalone.md

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'
View aws_credentials_timeout.go
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 / webfonts-to-local.rb
Created Jul 31, 2018
Script for downloading webfont files from Google Web Fonts CSS and converting CSS to point to local copies
View webfonts-to-local.rb
#!/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 / wait-for-ajax.rb
Last active Jul 10, 2018
Capybara: wait for Ajax with Prototype.js
View wait-for-ajax.rb
# in spec/features_helper.rb
# adapted from https://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara
# for legacy Rails apps still using Prototype.js
def wait_for_ajax!
Timeout.timeout(Capybara.default_max_wait_time) do
# Error pages etc. may not have Ajax defined
loop until page.evaluate_script("(typeof Ajax === 'undefined') ? 0 : Ajax.activeRequestCount").zero?
end
end
@dmolesUC
dmolesUC / combine.py
Last active Mar 26, 2018
Python script implementing "Combining Multiple Averaged Data Points and Their Errors" by Ken Tatebe
View combine.py
from typing import Tuple, List
"""A 'bin' of observations in the form (average, error, # of observations)"""
Bin = Tuple[float, float, int]
"""Based on http://isi.ssl.berkeley.edu/~tatebe/whitepapers/Combining%20Errors.pdf"""
def combine(a: Bin, b: Bin) -> Bin:
a_avg, a_err, n_a = a
b_avg, b_err, n_b = b
n = n_a + n_b
@dmolesUC
dmolesUC / fold-and-reduce.md
Created Jan 25, 2018
foldLeft(), Stream.reduce(), and Observable.reduce()
View fold-and-reduce.md

Vavr List:

List<String> str = List.of("A", "B", "C");
HashSet<String> res = str.foldLeft(
  HashSet.empty(), 
  (set, s) -> set.add(s)
);
@dmolesUC
dmolesUC / Arguments.java
Created Jan 3, 2018
Argument assertions
View Arguments.java
public class Arguments {
// ------------------------------------------------------------
// Checks
public static <T> T require(T argument, Predicate<T> condition, Supplier<String> msgSupplier) {
return require(argument, () -> condition.test(argument), msgSupplier);
}
public static <T> T requireNot(T argument, Predicate<T> condition, Supplier<String> msgSupplier) {
@dmolesUC
dmolesUC / jruby-openssl-x509-storeerror.txt
Created Jan 3, 2018
Stack trace: "OpenSSL::X509::StoreError: setting default path failed: No password supplied for PKCS#12 KeyStore"
View jruby-openssl-x509-storeerror.txt
$ ./gradlew check
> Configure project :buildSrc
2018-01-03 10:41:04.718:INFO::Daemon worker Thread 10: Logging initialized @6632166ms
2018-01-03 10:41:04.763:INFO:oejs.Server:Daemon worker Thread 10: jetty-9.2.12.v20150709
OpenSSL::X509::StoreError: setting default path failed: No password supplied for PKCS#12 KeyStore.
set_default_paths at org/jruby/ext/openssl/X509Store.java:165
SSLContext at uri:classloader:/META-INF/jruby.home/lib/ruby/shared/jopenssl19/openssl/ssl-internal.rb:31
SSL at uri:classloader:/META-INF/jruby.home/lib/ruby/shared/jopenssl19/openssl/ssl-internal.rb:22
@dmolesUC
dmolesUC / IndexColumnDemo.java
Created Dec 19, 2017
Displaying JavaFX TableView row number in a column
View IndexColumnDemo.java
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.ObjectBinding;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TableCell;
@dmolesUC
dmolesUC / TableHeightDemo.java
Created Dec 19, 2017
Showing only populated rows in a JavaFx TableView
View TableHeightDemo.java
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;
You can’t perform that action at this time.