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 / 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
# 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:
##############################
#!/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
#!/bin/bash
manifest_url='http://releases.ubuntu.com/releases/trusty/ubuntu-14.04.3-desktop-amd64.manifest'
manifest_file=$(echo $manifest_url | sed -e 's#.*/##g')
if [ ! -e $manifest_file ]; then
wget -q $manifest_url
fi
cat $manifest_file | cut -f1 | sort -u > default_installed.txt
aptitude search '~i !~M' -F '%p' --disable-columns | sort -u > currently_installed.txt
@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)
@dazza-codes
dazza-codes / git_utils.sh
Created August 31, 2016 17:30
Useful GIT Functions
#!/bin/bash
# Useful GIT Functions
#### Cutting a release with a log of recent pull requests merged to master
git_release_commits ()
{
git pull
git fetch -p
git log --oneline --decorate | grep 'Merge pull request' | head -n25
@dazza-codes
dazza-codes / marcConsole.scala
Created August 14, 2017 16:47
MARC21 -> MARC-XML in scala, using marc4j
// To run this script:
// scala -cp ~/.m2/repository/org/marc4j/marc4j/2.7.3/marc4j-2.7.3.jar marcConsole.scala
val beforeUsedMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
import java.io.ByteArrayOutputStream
import java.io.FileInputStream
import java.io.InputStream
import org.marc4j._
@dazza-codes
dazza-codes / basic_faraday_json_client.rb
Created February 13, 2016 21:13
Faraday JSON client
require 'faraday'
require 'faraday_middleware'
class Client
JSON_CONTENT = 'application/json'
attr_reader :conn
# Initialize a new client
def initialize
@base_uri = 'https://api.example.org'
@dazza-codes
dazza-codes / this.js
Created August 23, 2018 16:04
JS this
var fullname = 'John Doe';
var obj = {
fullname: 'Colin Ihrig',
prop: {
fullname: 'Aurelio De Rosa',
getFullname: function() {
return this.fullname;
}
}
};