Skip to content

Instantly share code, notes, and snippets.

View lee-dohm's full-sized avatar
😴
Taking some well-deserved naps

Lee Dohm lee-dohm

😴
Taking some well-deserved naps
View GitHub Profile
@lee-dohm
lee-dohm / confirm_dialog.js.coffee
Created November 4, 2013 02:30
Bootstrap 3-compatible Rails confirmation dialog
$.rails.allowAction = (element) ->
message = element.data('confirm')
return true unless message
proceed = element.data('confirm-proceed') ? 'Proceed'
cancel = element.data('confirm-cancel') ? 'Cancel'
title = element.data('confirm-title') ? 'Confirm'
cancel_button_class = element.data('confirm-cancel-class') ? 'btn-default'
proceed_button_class = element.data('confirm-proceed-class') ? 'btn-danger'

Capybara Cheat Sheet

Navigating

visit('/projects')
visit(post_comments_path(post))

Clicking Links and Buttons

@lee-dohm
lee-dohm / push_db_to_s3
Last active December 22, 2015 20:39 — forked from david-vo/push_db_to_s3
#!/usr/bin/env ruby
# Script to backup the Discourse postgres db and upload it to Amazon S3
require 'rubygems'
require 'yaml'
require 'fog'
require 'time'
require 'date'
require 'fileutils'
@lee-dohm
lee-dohm / relocate.fish
Last active December 21, 2015 16:59
Code for article 'Shells and Scripting'
set --local bin_index (contains --index /usr/bin $PATH)
set --local local_bin_index (contains --index /usr/local/bin $PATH)
if test $local_bin_index -gt $bin_index
set --erase $PATH[$local_bin_index]
set --local local_path ''
if test (math $bin_index - 1) -gt 0
set local_path $PATH[1..(math $bin_index - 1)]
end
@lee-dohm
lee-dohm / date_calculations.rb
Last active December 21, 2015 02:09
Stuff for David Vo
require 'date'
# Set the expriation to now plus 30 days
expriation = Time.now + (30 * 24 * 60 * 60)
# Output the filename in the desired format
puts expiration.strftime('discourse-%Y-%m-%d.dump')
# Or if you want the time too
puts expiration.strftime('discourse-%Y-%m-%d-%H-%M-%S.dump')
@lee-dohm
lee-dohm / block_example.rb
Last active December 20, 2015 12:29
Code snippets for "Adventures in Language Design" blog entry
# Explicitly opens and closes the file
def read_file1(filename)
file = nil
begin
file = File.open('somefile.txt')
return file.readlines
ensure
file.close
###
# Allowable
#
# A pattern for decomposing large/long conditional chains
# into readable, testable, and inspectable segments.
# Code coverage stats can help show you which conditions
# aren't getting test coverage, and printing/prying around
# the code can show you intermediary condition results.
#
# Effectively a block-syntax for the `or` operator: each `when?`
@lee-dohm
lee-dohm / test.rb
Last active December 18, 2015 07:10
Code samples for blog article: "Text File Line Endings"
Get-Content -Encoding byte test.rb
@lee-dohm
lee-dohm / documented.rb
Last active December 18, 2015 03:59
Code samples for blog article: "The Importance of Documenting Code"
# Indicates whether `color` is a valid SVG color string.
#
# [SVG color descriptions](http://www.w3.org/TR/SVG/types.html#DataTypeColor) are one of the following:
#
# * RGB values
# * `#rgb`
# * `#rrggbb`
# * `rgb(255, 0, 0)` - *not currently supported by KangaRuby*
# * `rgb(100%, 0%, 0%)` - *not currently supported by KangaRuby*
# * [Color names](http://www.w3.org/TR/SVG/types.html#ColorKeywords)
@lee-dohm
lee-dohm / class-a.java
Last active December 17, 2015 18:29
Code examples for "Dynamic Typing Makes for Testability" article
class A
{
private B b;
public A(B b)
{
this.b = b;
}
public void store()