Skip to content

Instantly share code, notes, and snippets.

@stepheneyer
stepheneyer / cucumber-rails.md
Last active March 8, 2024 19:51
BDD testing using Cucumber, Capybara, and Rails

#Cucumber and Capybara - Behavior Driven Development

##Overview

Cucumber allows software developers to describe how software should behave in plain text. The text is written in a business-readable, domain-specific language. This allows non-programmers to write specific feature requests that can be turned into automated tests that drive development of the project.

Capybara is the largest rodent known to man.

@stepheneyer
stepheneyer / require ffaker
Created June 8, 2015 23:39
use ffaker to populate database with fake data
# Use the Great Faker Cheatsheet as a reference
# http://ricostacruz.com/cheatsheets/ffaker.html
require 'ffaker'
require 'pg'
conn = PG.connect(dbname: "shopper_app")
conn.exec("INSERT INTO shoppers
(first_name, last_name, email, address)
//Requirements
var express = require("express"),
bodyParser = require("body-parser"),
path = require("path");
var app = express();
app.get("/", function (req, res){
res.send("Hello World!");
@stepheneyer
stepheneyer / jQuery script
Created May 6, 2015 16:45
script to call jQuery in html
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<title></title>
</head>
<body>
</body>
</html>
@stepheneyer
stepheneyer / var.concat();
Created May 1, 2015 16:21
Combine two arrays into one, then sort
//Assign a new variable for each array
var myFriends = ["Rickon", "Meera", "Hodor", "Jojen", "Osha", "Rickard", "Maester", "Rodrik", "Jory", "Septa", "Jon"]
var yourFriends = ["Bilbo", "Boromir", "Elrond", "Faramir", "Frodo", "Gandalf", "Legolas", "Pippin"]
//Combine the two arrays using the .concat() method
var combinedFriends = myFriends.concat(yourFriends);
combinedFriends.sort();
//=> [ 'Bilbo',
// 'Boromir',
@stepheneyer
stepheneyer / string.split()
Created May 1, 2015 16:14
Change from String to Array using .split(), then sort
//Create a variable with a string separated by commas
var friends = "Moe,Larry,Curly,Jane,Emma,Elizabeth,Elinor,Mary,Darcy,Grey,Lydia,Harriet";
//Create a new array of the string using the .split() method
//The split method needs the separator such as a comma or space ==> str.split([separator[, limit]])
var newFriends = friends.split([',']);
console.log(newFriends);
//Sort the new array
newFriends.sort();
@stepheneyer
stepheneyer / stack.push();
Created May 1, 2015 16:03
create a new stack from a user prompt
//Create a new array or queue of people using the user prompt
//Set the max number of people in the line (or loops)
var max = 5;
var stack = [];
for (i = 0; i <= max; i++) {
var newName = prompt("Enter your name.");
stack.push(newName);
}
console.log(stack);
@stepheneyer
stepheneyer / reverse(string)
Created May 1, 2015 15:52
reverse a string using a for loop
function reverse(string) {
var rev = '';
for (var i = string.length - 1; i >= 0; i--)
rev += string[i];
return rev;
}
reverse("Hello");
//=> returns "olleH"
@stepheneyer
stepheneyer / querySelectorAll
Created May 1, 2015 15:48
querySelectorAll with tags/classes
window.addEventListener("load", function (){
alert("Loaded!");
//.querySelectorAll - with tags
var listItems = document.querySelectorAll ("li");
//Becomes an array-like object, check that contains contents with .length
//listItems.length;
for (i = 0; i < listItems.length; i++) {
listItems[i].style.borderBottom = "2px solid black";
@stepheneyer
stepheneyer / addEventListener
Last active August 29, 2015 14:20
addEventListener and querySelector
window.addEventListener("load", function (){
alert("Loaded!");
var clicker = document.querySelector("#clicker");
clicker.addEventListener("click", function (event) {
alert("Yes, the button was clicked!");
});
});