Skip to content

Instantly share code, notes, and snippets.

View dazza-codes's full-sized avatar

Darren Weber dazza-codes

View GitHub Profile
@dazza-codes
dazza-codes / tmux-cheatsheet.markdown
Created March 30, 2019 15:52 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@dazza-codes
dazza-codes / argparse_date_datetime_custom_types.py
Created September 7, 2018 01:22 — forked from monkut/argparse_date_datetime_custom_types.py
Custom date/datetime type validators for python's argparse module
def valid_date_type(arg_date_str):
"""custom argparse *date* type for user dates values given from the command line"""
try:
return datetime.datetime.strptime(arg_date_str, "%Y-%m-%d")
except ValueError:
msg = "Given Date ({0}) not valid! Expected format, YYYY-MM-DD!".format(arg_date_str)
raise argparse.ArgumentTypeError(msg)
def valid_datetime_type(arg_datetime_str):
"""custom argparse type for user datetime values given from the command line"""
@dazza-codes
dazza-codes / rspec_rails_cheetsheet.rb
Created January 12, 2016 04:52 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
#!/bin/bash
# Create the directory structure
mkdir -p features/step_definitions
mkdir -p features/support
# Create a placeholder for the step_definitions folder
touch features/step_definitions/"$(basename `pwd`)_steps.rb"
# Create the environment file
# First attempting to use Capybara directly, you will run into issues when trying to set HTTP headers; e.g.
# using Basic HTTP Authentication requires setting the header.
# Also we need to set the Content-Type and Accept headers to ensure that our API negotiates content types correctly.
# When using Rack, Capybara delegates request and response handling down to Rack::Test.
# So use Rack::Test directly in step definitions, and it works.
# Rack::Test has a module called Rack::Test::Methods that can be mixed into a class to provide it
# with methods for get, post, put, delete as well as last_request, last_response, header and more.
# The Rack::Test::Methods can be mixed into the Cucumber world at the top of our API steps file like so:
##############################
@dazza-codes
dazza-codes / base.rb
Last active August 29, 2015 14:08 — forked from bensie/base.rb
require "sinatra/base"
require "sinatra/namespace"
require "multi_json"
require "api/authentication"
require "api/error_handling"
require "api/pagination"
module Api
class Base < ::Sinatra::Base