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
###
# 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 / 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
@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 / 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 / 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'

Capybara Cheat Sheet

Navigating

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

Clicking Links and Buttons

@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'
@lee-dohm
lee-dohm / frame.el
Last active December 28, 2015 11:08 — forked from ieure/tiling
;; Functions to work with frames
(provide 'ime-frame)
(defun screen-usable-height (&optional display)
"Return the usable height of the display.
Some window-systems have portions of the screen which Emacs
cannot address. This function should return the height of the
screen, minus anything which is not usable."
@lee-dohm
lee-dohm / screen_share.rb
Created February 23, 2014 18:41
Ruby "screen sharing" server
require 'socket'
require 'base64'
Refresh = 1 # seconds to refresh image on server
screen_capture_command = 'screencapture -C -x tmp.png'
image = ''
latest = Time.now
server = TCPServer.new 3000
loop do
var exec = require('child_process').spawn;
var node = exec('node', process.argv.splice(2), {stdio: 'inherit'});