Skip to content

Instantly share code, notes, and snippets.

# Example Code
# For blog entry about Ruby Arrays and Hashes
# Ruby Arrays #
# define an array with three elements
my_friends = ["James", "Ana", "David"]
# Displays the number of elements in the array (how many friends do I have?)
puts my_friends.length
@nbkhope
nbkhope / capybara cheat sheet
Created June 26, 2016 22:50 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@nbkhope
nbkhope / factorial.rb
Last active July 7, 2016 22:08
Introduction to RSpec and Test-Driven Development using Factorial
# Given an integer greater than or equal to zero
def factorial(n)
return 1 if n <= 1
product = 1
index = n
while index > 1
product *= index
index -= 1
@nbkhope
nbkhope / request-promise-error-offline.json
Last active June 22, 2017 22:13
request-promise's error object properties (online vs offline output comparison)
{
"error": {
"name": "RequestError",
"message": "Error: getaddrinfo ENOTFOUND somewhere.com somewhere.com:80",
"cause": {
"code": "ENOTFOUND",
"errno": "ENOTFOUND",
"syscall": "getaddrinfo",
"hostname": "somewhere.com",
"host": "somewhere.com",
@nbkhope
nbkhope / sails-blueprint-rest.md
Last active October 20, 2017 19:41
Sails 0.12 Blueprint Actions

These are automatically generated by the Blueprint API

RESTful Route Controller Action
GET /resource ResourceController.find
GET /resource/:resourceId ResourceController.findOne
POST /resource ResourceController.create
PUT /resource/:resourceId ResourceController.update
DELETE /resource/:resourceId ResourceController.destroy
GET /resource/:resourceId/:association ResourceController.populate
@nbkhope
nbkhope / git-commit-message-with-issue-number.sh
Created December 6, 2017 01:42
Make a git commit including the issue number in the message
# Add this code to your ~/.bashrc (Linux) or ~/.bash_profile (macOS)
# Given a branch named with the pattern `feature/123456-some-branch`,
# makes a commit with the message "refs #123456 whatever"
# if called like `gc 'whatever message you want'`
gc() {
if [ "$1" == "" ]
then
echo "You must provide a commit message."
@nbkhope
nbkhope / EfficientJDBCPreparedStatementBatch.java
Created December 13, 2017 02:15
Efficient JDBC Multiple Queries using PreparedStatement Batch
connection.setAutoCommit(false);
PreparedStatement preparedStatement = connection.prepareStatement(someQuery);
for (Record record : records) {
// do your stuff (e.g. preparedStatement.setString(1, name);
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
connection.commit();
@nbkhope
nbkhope / git-push-origin-branch-name.sh
Last active January 15, 2018 05:44
Push the current branch to origin with the `gp` command
gp() {
if [ -d ".git" ]
then
BRANCH_NAME="$(git branch | grep '*' | cut -d' ' -f2)"
git push origin "$BRANCH_NAME"
fi
}
@nbkhope
nbkhope / git-branch-name-in-bash-prompt.sh
Last active January 15, 2018 08:47
Current Git Branch Name in Bash Prompt
# Display the current branch name in your bash prompt
# If current directory is not under a git repository, displays an empty string
# Add this function to your .bashrc (or .bash_profile in macOS)
getGitBranch() {
[ -d ".git" ] && git branch | grep \* | cut -d" " -f2
}
# Include this in your PS1 definition
# Don't forget to include the backslash before $
@nbkhope
nbkhope / app.js
Created March 16, 2018 23:28 — forked from nulltask/app.js
Output CSV in Express
/**
* Module dependencies.
*/
var express = require('express')
, app = module.exports = express.createServer();
// Configuration
app.use(app.router);