How to force line breaks in markdown

I always forget this.
I don't know why, because my editor shows big nasty red blotches whenever I have trailing spaces.
To force a line break in markdown, end your line with two spaces.

A limerick

A couple of dev with nice Macs
Thought up some quite clever hacks
They opened PRs
Approved them too fast
Now production is being rolled back

How to output the current RSpec example

Here's a snippet you can add to your rspec config to print out the name of the method being run:

config.before do |example|
24 puts "----- state ----"
25 puts example.metadata[:full_description]
26 puts "inline: #{Sidekiq::Testing.inline?}"
27 puts "fake: #{Sidekiq::Testing.fake?}"
28 puts "----------------"
29 puts
30 end

Why on earth would you wan to do this? Sometimes you are working with something like Sidekiq where state can bleed between tests (for example changing from inline to fake); this little snippet helps you figure out where it's happening without having to investigate all your test files.

Generating mongoid config in rails hangs

If setting up a new Rails project with Mongoid and trying to run rails g mongoid:config hangs, try

spring stop
spring start

Not In queries in Rails with MongoDB and Mongoid

Sometimes you want a quick "not in" or "not equal" query in Rails, but you're running Mongo. ActiveRecord allows us to write where.not against relational databases, but this doesn't work when using Mongoid. Instead, you can use nin or it's alias not_in

Book.not_in(title: "Of mice and men")

The method is also chainable, so this is valid:

Book.where(author: "Steinbeck").not_in(title: "Of mice and men")

If you prefer not to chain your methods, you can also write the query by sending nin to a symbolised version of your model's property and then using the old hashrocket syntax to specify the value:

Book.where(author: "Steinbeck", :title.nin => ["Of mice and men"])

Module not found: Error: Can't resolve 'fs' using webpack and Electron

Module not found: Error: Can't resolve 'fs'

If you've set up webpack with an Electron application and you hit this strange error when trying to bundle your project, you've probably forgotten to include the target in your webpack config. This is easily fixed by editing webpack.config.js to include the target, something like this:

const path = require('path');

module.exports = {
entry: './app.js',
output: {
filename: 'bundle.js'
target: 'electron'

Fixing a broken npm tha errors with "cannot find module 'process-nextick-args’"

Following along with Free Code Camp's Node course, I was playing with how-to-npm from Node School, I followed the first exercise and ran how-no-npm verify. My npm version was out of date and following the prompt, I ran npm install npm -g. That seemed to complet successfully, however, running how-to-npm verify subsequently gave me a lovely string of errors, the top one being

Error: Cannot find module 'process-nextick-args’

Running any npm command seemed to result in something similar.

To fix this, I did the following - first upgrade Node itself with nvm:

Step 1 - upgrade node itself with nvm:

nvm install v8.9.3

Step 2 - install how-to-npm again:

npm install how-to-npm -g`

Step 3 - upgrade npm

npm i -g npm

Now I can run how-to-npm verify again and everything works

Add non blog pages to a middleman blog

Having set middleman up to be a static blog, you might find yourself wanting to add some static pages outside of the blog structure. For example, if you install any analytics on your site, you often need to include a static file with an authentication code to your analytics provider. These pages are often barebones, with no common header or footer and no styling and you almost certainly do not need them to be processed from markdown. In other words, you want to create a page that does not use the layouts that the rest of your site uses.

To set these up, create the html page and then edit your config.rb to include something like the following:

page "my_barebones_page.html", directory_index: false, layout:false

Using layout: false is reasonably self-explanatory; you are instructing middleman to forego any layout for this page. The inclusion of directory_index: false makes sure that the page is accessible with the .html suffix. This is especially useful if you are using pretty urls for your blog.

How to show hidden rake tasks

Rake tasks are easily listed from the command line with rake -T. However if you've written a rake task and neglected to provide a description for it with the desc as the first line, the task will not show up with the usual rake -T. These are essentially hidden rake tasks!

To display them, append -A to your normal rake command; so:

rake -T -A

and hey presto, your hidden tasks are visible.

Renaming a local git branch

The simplest way to rename a branch in git is first to checkout that branch and then do something like this:

git branch -m new-branch-name
Next Page