Skip to content

Instantly share code, notes, and snippets.

Renan Martins nbkhope

Block or report user

Report or block nbkhope

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nbkhope
nbkhope / grails-unit-testing-controller.groovy
Created Jan 20, 2017
Grails 3 Unit Testing (Controller)
View grails-unit-testing-controller.groovy
// Given the controller
class DemoController {
def hello() {
render "greetings!"
}
def greet() {
redirect action: 'hello'
}
}
View grailsFileUpload.groovy
// In your controller, use the following code
// Single file
def file = request.getFile("identifier_name_in_html_tag_attribute")
// Useful information
file.empty
file.class // => class org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile
file.name // the name attribute value you used above (comes from html input tag)
file.originalFilename
@nbkhope
nbkhope / app.js
Created Mar 16, 2018 — forked from nulltask/app.js
Output CSV in Express
View app.js
/**
* Module dependencies.
*/
var express = require('express')
, app = module.exports = express.createServer();
// Configuration
app.use(app.router);
@nbkhope
nbkhope / git-branch-name-in-bash-prompt.sh
Last active Jan 15, 2018
Current Git Branch Name in Bash Prompt
View git-branch-name-in-bash-prompt.sh
# 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 / git-push-origin-branch-name.sh
Last active Jan 15, 2018
Push the current branch to origin with the `gp` command
View git-push-origin-branch-name.sh
gp() {
if [ -d ".git" ]
then
BRANCH_NAME="$(git branch | grep '*' | cut -d' ' -f2)"
git push origin "$BRANCH_NAME"
fi
}
@nbkhope
nbkhope / EfficientJDBCPreparedStatementBatch.java
Created Dec 13, 2017
Efficient JDBC Multiple Queries using PreparedStatement Batch
View EfficientJDBCPreparedStatementBatch.java
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-commit-message-with-issue-number.sh
Created Dec 6, 2017
Make a git commit including the issue number in the message
View git-commit-message-with-issue-number.sh
# 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 / sails-blueprint-rest.md
Last active Oct 20, 2017
Sails 0.12 Blueprint Actions
View sails-blueprint-rest.md

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 / request-promise-error-offline.json
Last active Jun 22, 2017
request-promise's error object properties (online vs offline output comparison)
View request-promise-error-offline.json
{
"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 / factorial.rb
Last active Jul 7, 2016
Introduction to RSpec and Test-Driven Development using Factorial
View factorial.rb
# 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
You can’t perform that action at this time.