Skip to content

Instantly share code, notes, and snippets.

<!-- inputs -->
<input type="hidden" name="funding" value="85" data-caption="Funding" />
<input type="hidden" name="completion" value="25" data-caption="Completion" />
<!-- non-inputs -->
<div class="meter" data-value="67%" data-caption="Funding"></div>
<div class="meter" data-value="43%" data-caption="Completion"></div>
<script src="jquery.js"></script>
<script src="meter.js"></script>
@jehoshua02
jehoshua02 / prevent_sql_injection.md
Last active December 21, 2015 15:09
Examples of how to protect against sql injection.

There are two implementations of a query() function, demonstrating how to prevent sql injection. One uses the mysql functions. The other uses PDO.

To use this function is simple. First, you set up your sql string and values. Notice the placeholders match the array keys:

$sql = 'SELECT * FROM someTable WHERE someValue = :someValue AND anotherValue = :anotherValue';
$values = array(
    'someValue' => 'Hello',
    'anotherValue' => 'World',
);
@jehoshua02
jehoshua02 / Banana.php
Last active December 23, 2015 19:09
Testing whether class and function definitions are loaded even when the included file has a return.
<?php
return;
class Banana
{
}
@jehoshua02
jehoshua02 / Hookable.php
Last active December 23, 2015 20:49
Hooks ... maybe good for caching or logging errors?
<?php
/*
* @todo I wish there was a way to hook before and after a method without explicitly calling the hooks in the method.
* In other words, the method would be ignorant of any hooks. This would allow you to hook into any existing methods
* without even touching those methods. There's only two ways I can think of doing this: extending PHP to provide the
* hookable interface on every object, or to put the object in a hookable container.
*/
@jehoshua02
jehoshua02 / README.md
Created October 16, 2013 08:16
Hastle free PHP debugging with !

In the xdebug docs, I found a list of debugging clients!

I chose a standalone called MacGDBp.

I also widdled the xdebug configs down to the bare minimum for hastle free debugging:

zend_extension=/usr/lib/php5/20090626/xdebug.so

xdebug.remote_enable = 1 
@jehoshua02
jehoshua02 / _composer_phpunit.md
Last active December 25, 2015 20:49
Barebones Composer and PHPUnit configuration.

It's really easy to set up PHPUnit with Composer. Just drop composer.json and phpunit.xml.dist in your project root. Then you need to tell Composer to install:

composer install

Then you can run tests:

vendor/bin/phpunit
@jehoshua02
jehoshua02 / Preferences.sublime-settings
Created October 18, 2013 19:20
My sublime configs
{
"color_scheme": "Packages/User/Github.tmTheme",
"ignored_packages":
[
"Vintage"
],
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"ensure_newline_at_eof_on_save": false,
"draw_white_space": "all",
@jehoshua02
jehoshua02 / .bash_pull_request
Created October 25, 2013 16:54
Simple bash function to submit pull request
alias github_url="git ls-remote --get-url | cut -d '@' -f 2 | sed 's/:/\//' | sed 's/^/http:\/\//' | cut -d\. -f 1 -f 2"
alias current_branch="git rev-parse --abbrev-ref HEAD"
function pull_request() {
git push origin $(current_branch)
open $(github_url)/compare/$1...$(current_branch)

My 3 Rules of TDD (Experimental)

Here is my experimental version of the 3 rules of TDD:

  1. You are not allowed to write any production code unless it is to make a failing unit test pass. (No modification here)
  2. You are not allowed to write any more of a unit test than is sufficient to sufficiently test a single method. (Instead of just enough to get a failure)
  3. You are not allowed to write any more production code than is sufficient to pass all tests for the one method. (To match the new Rule #2)

Reasons for Changes

@jehoshua02
jehoshua02 / .gitconfig_alias_pr
Last active December 27, 2015 19:49
Git alias to open pull request on Github
[alias]
# returns url for remote
url = ls-remote --get-url
# returns http url for github
ghurl = !git url | cut -d '@' -f 2 | sed 's/:/\\//' | sed 's/^/http:\\/\\//' | cut -d\\. -f 1 -f 2
# returns current branch
which = rev-parse --abbrev-ref HEAD