Skip to content

Instantly share code, notes, and snippets.

@jerilevine
jerilevine / make_ubuntu.sh
Last active December 11, 2024 22:24
Create Ubuntu VM on Mac OS X with Apple Silicon (ARM)
#!/bin/bash
# adapted from https://gist.github.com/citruz/9896cd6fb63288ac95f81716756cb9aa
# See also https://www.qemu.org/docs/master/system/invocation.html
# highmem must be off with Apple M1 and this limits the memory unfortunately
qemu-img create -f qcow2 ubuntu-24.qcow2 10G
dd if=/dev/zero conv=sync bs=1m count=64 of=ovmf_vars.fd
qemu-system-aarch64 \
@jerilevine
jerilevine / test_console.rb
Created March 1, 2018 21:37
Instantiate a Capybara browser from your Rails console
require 'capybara/dsl'
module TestConsole
if(defined?(Rails) && Rails.env.test?)
whitelist = %w(chrome firefox)
print "Browser [#{whitelist.join('|')}] (enter to skip): "
browser = gets.strip
if whitelist.include?(browser)
@jerilevine
jerilevine / fetch_all_jira_tests.rb
Created April 24, 2017 20:14
Ruby script to grab all the tests from JIRA via the REST API. Includes pagination
#!/usr/bin/ruby
################################################################################
# A quick script to grab all the tests from JIRA via the REST API.
# Docs are here: https://docs.atlassian.com/jira/REST/cloud/
#
@jerilevine
jerilevine / acceptance_helper.rb
Last active April 24, 2017 20:16
Stepwise logging for Turnip
LOG_DIR = Rails.root.join('log')
LOG = Logger.new(File.join(LOG_DIR, "turnip_#{Time.now.strftime("%Y%m%d%H%M")}.log"))
LOG.level = Logger::DEBUG
RSpec.configure do |config|
config.before(:each) do | scenario |
LOG.info("========================================")
LOG.info("Starting test #{scenario.example_group.description}")
end
def reload_page
page.evaluate_script("window.location.reload()")
end
# Reload the page until either you hit the timeout, or the selector appears
# For use in places where the basic page.has_selector? wait won't work without
# reloading the whole page
#
# Accepts the same options as Capybara::Node::Matchers#has_selector?
def reload_until(*selector_args)
@jerilevine
jerilevine / db_fixtures_dump.rake
Created August 15, 2016 17:07 — forked from iiska/db_fixtures_dump.rake
Dump Rails db to fixtures
# Original from http://snippets.dzone.com/posts/show/4468 by MichaelBoutros
#
# Optimized version which uses to_yaml for content creation and checks
# that models are ActiveRecord::Base models before trying to fetch
# them from database.
namespace :db do
namespace :fixtures do
desc 'Dumps all models into fixtures.'
task :dump => :environment do
models = Dir.glob(RAILS_ROOT + '/app/models/**.rb').map do |s|
@jerilevine
jerilevine / InChi.js
Created January 9, 2013 16:09 — forked from lsauer/InChi.js
// International Chemical Identifier Regex, by lo sauer - lsauer.com
// Morphine InchI:
var x="InChI=1S/C17H19NO3/c1-18-7-6-17-10-3-5-13(20)16(17)21-15-12(19)4-2-9(14(15)17)8-11(10)18/h2-5,10-11,13,16,19-20H,6-8H2,1H3/t10-,11+,13-,16-,17-/m0/s1"
// applying an organic character-subset
// we could check for the length property, but in case of 0 matches 'null' is returned -> hence !!.. \ generally equal to Boolean(..)
!!x.trim().match(/^((InChI=)?[^J][0-9BCOHNSOPrIFla+\-\(\)\\\/,pqbtmsih]{6,})$/ig)
>true
//generic:
x.trim().match(/^((InChI=)?[^J][0-9a-z+\-\(\)\\\/,]+)$/ig)