Skip to content

Instantly share code, notes, and snippets.

View craig-davis's full-sized avatar
👋

Craig Davis craig-davis

👋
View GitHub Profile
@craig-davis
craig-davis / complexity-if-else-with-returns.php
Last active April 15, 2017 17:25
Code with If/Else and Early Return
<?php
function calculateSalePrice($item, $discount = 0) {
if ($discount == 0) {
return $item->getPrice();
}
else {
return calculateDiscountedPrice($item->getPrice, $discount);
}
}
@craig-davis
craig-davis / complexity-traditional-if-else.php
Last active April 15, 2017 17:24
Reducing Complexity by Refactoring with Guard Clauses in PHP and JavaScript
<?php
function calculateSalePrice(Item $item, $discount = 0) : int
{
$price = 0;
if ($discount == 0) {
$price = $item->getPrice();
}
else {
@craig-davis
craig-davis / .ackrc
Last active May 25, 2016 15:19
Ack config
# Always color, even if piping to a another program
--color
# Show two lines around match
-C2
# Use "less −r" as my pager
# --pager
# less -r
@craig-davis
craig-davis / .jscsrc
Last active April 7, 2016 19:50
.jscsrc
{
"disallowEmptyBlocks": true,
"disallowImplicitTypeConversion": ["numeric", "boolean", "binary", "string"],
"disallowKeywords": ["with"],
"disallowLeftStickedOperators": ["?", "+", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
"disallowMixedSpacesAndTabs": true,
"disallowMultipleLineBreaks": true,
"disallowMultipleLineStrings": true,
"disallowQuotedKeysInObjects": true,
"disallowRightStickedOperators": ["?", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
@craig-davis
craig-davis / README.md
Last active September 8, 2015 22:21 — forked from mbbx6spp/README.md
Git hooks to enforce pull request on master workflow

Sanity checking Git Hook for pre-commit

Checks that you are trying to push to master (or other key branches) from your local repository.

Installation

Download the above raw file (edit it as you please) and place inside your Git repository under: $GITDIR/hooks/pre-commit where $GITDIR is typically .git under your project working directory. Then make sure you make it executable: chmod +x .git/hooks/pre-commit

@craig-davis
craig-davis / .grc.sql.conf
Last active September 29, 2017 21:41
Enable and tail the MySQL General Log
regexp=\'.+?\'
colours=bold yellow
count=more
=====
regexp=(FROM|INNER JOIN|WHERE|AND|LIMIT|ON|AS|WHERE)
colours=bold green
count=more
======
regexp=(START TRANSACTION|COMMIT)
colours=bold white on_green
@craig-davis
craig-davis / .jshintrc
Created January 26, 2015 21:59
.jshintrc, with some now deprecated options.
{
// --------------------------------------------------------------------
// JSHint Configuration, Strict Edition
// --------------------------------------------------------------------
//
// This is a options template for [JSHint][1], using [JSHint example][2]
// and [Ory Band's example][3] as basis and setting config values to
// be most strict:
//
// * set all enforcing options to true