Skip to content

Instantly share code, notes, and snippets.

View chrisroos's full-sized avatar

Chris Roos chrisroos

View GitHub Profile
@chrisroos
chrisroos / README.md
Last active March 20, 2016 23:38
Apache 2.4 on OS X Yosemite listening on ::1 and not 127.0.0.1

Apache appears to be listening on ::1 but not 127.0.0.1.

$ telnet localhost 80
Trying ::1...
Connected to localhost.
Escape character is '^]'.

$ telnet 127.0.0.1 80
Trying 127.0.0.1...
@chrisroos
chrisroos / README.md
Created April 17, 2015 11:21
Configuring Apache, Passenger and Dnsmasq of Mac OS X

Configure Dnsmasq to respond to *.dev

Assuming it's been installed using Homebrew.

Add the following to dnsmasq.conf (/usr/local/etc/dnsmasq.conf).

address=/dev/127.0.0.1

Stop and start the service:

@chrisroos
chrisroos / README.md
Last active November 11, 2018 15:50
Bookmarklet that allows me to add a link to more information for specific emails I receive

I receive a number of periodic emails that prompt me to do something (e.g. take an electricity meter reading). I wanted to be able to add information to those emails to remind me how to perform the task.

This JavaScript allows me to configure rules so that I can display a link to a web page when I'm viewing an email with a specific subject in Gmail.

I'm currently hosting the JavaScript and installer web page using rawgit.com.

Visit this page to install the bookmarklet.

@chrisroos
chrisroos / test-output.txt
Created April 29, 2015 13:11
The tests that fail in smart-answers when I run with seed 56021
Chriss-MacBook-Air-2:~/Code/alphagov/smart-answers$ rake test TESTOPTS="--seed=56021"
* DEFERRED: sequence of two questions a question raises an error should permit custom error messages per question.
Run options: --seed=56021
# Running:
.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
@chrisroos
chrisroos / README.md
Last active August 29, 2015 14:20
Smart Answer test failures caused by lack of Internet connection

I disabled my Internet connection and ran the tests in the Smart Answers project to see how many relied on being able to make connections to the outside world.

@chrisroos
chrisroos / README.md
Last active August 29, 2015 14:20
Comparing Smart Answer test output with and without memoized state

The current test set-up requires the use of contexts to move through the Smart Answer. We can avoid this by removing the memoization of @state in FlowTestHelper. I temporarily removed it and ran the tests to see how much longer they took and whether we'd have any failures.

def current_state
  # @state ||= begin
    @flow.process(@responses)
  # end
end
@chrisroos
chrisroos / Gemfile
Created May 1, 2015 14:30
Nokogiri nth-child problems with LibXML 2.9
source 'https://rubygems.org'
gem 'nokogiri', '1.5.11'
gem 'test-unit'
@chrisroos
chrisroos / README.md
Last active August 29, 2015 14:20
Exploring how to act on files that have changed in a directory

I've been using [FileWatcher][] to perform actions on new/changed files. I ran into problems where FileWatcher invokes the block before the file has finished copying and my code then fails.

My script runs using launchd so I considered investigating the WatchPaths launchd.plist directive. The man page for that directive says not to use it because of the some of the problems I've been having with FileWatcher.

Use of this key is highly discouraged, as filesystem event monitoring is highly race-prone, and it is entirely possible for modifications to be missed. When modifications are caught, there is no guarantee that the file will be in a consistent state when the job is launched.

The scripts in this gist are investigations into alternative approaches to only acting on files that have been created/changed.

In 'storing-a-hash-of-files.rb' I also compared the performance of Ruby's Digest::MD5 to the system md5 but there didn't seem to be any difference. The system md5 required me to use Shellwords t

@chrisroos
chrisroos / README.md
Created May 5, 2015 09:54
Illustration of the problem of precalculation blocks not being evaluated in the first question

Demonstration of the problem of precalculate blocks not being evaluated in the first question of a Smart Answer.

Assuming the flow lives in "lib/smart_answer_flows/" and the test lives in "test/integration/smart_answer_flows/", you can run the test with bundle exec ruby test/integration/smart_answer_flows/example_flow_test.rb.

Note the absence of "Q1 - precalculate" in output.txt.

@chrisroos
chrisroos / README.md
Last active August 29, 2015 14:20
Comparison of Smart Answer visualisation, using next_node_if and next_node with permitted_next_nodes

Comparison of the visualisation of two Smart Answers: one using next_node_if and one using a combination of next_node and permitted_next_nodes.

The Smart Answer using next_node_if can be visualised correctly while the one using next_node and permitted_next_nodes cannot. See the attached screenshots for both visualisations.