Skip to content

Instantly share code, notes, and snippets.

View ziadoz's full-sized avatar

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / stripe-checkout.html
Last active November 19, 2022 05:59
Custom Stripe Checkout Button
<form action="." method="post">
<noscript>You must <a href="http://www.enable-javascript.com" target="_blank">enable JavaScript</a> in your web browser in order to pay via Stripe.</noscript>
<input
type="submit"
value="Pay with Card"
data-key="PUBLISHABLE STRIPE KEY"
data-amount="500"
data-currency="cad"
data-name="Example Company Inc"
@ziadoz
ziadoz / primes.php
Last active December 15, 2015 05:29
PHP Memoize and Benchmark Primes
<?php
$prime = function($num) {
if ($num === 1) {
return false;
}
if ($num === 2) {
return true;
}
@ziadoz
ziadoz / halt_compiler.php
Last active April 23, 2024 17:55
Using PHP Halt Compiler
<?php
/**
* The __halt_compiler() function will stop the PHP compiler when called.
* You can then use the __COMPILER_HALT_OFFSET__ constant to grab the contents of the PHP file after the halt.
* In this example a PHP template is stored after the halt, to allow simple separation of logic from templating.
* The template is stored in a temporary file so it can be included and parsed.
*
* See: https://github.com/bobthecow/mustache.php/blob/dev/src/Mustache/Loader/InlineLoader.php
* http://php.net/manual/en/function.halt-compiler.php
*/
@ziadoz
ziadoz / debug.conf
Last active October 4, 2018 14:23
Debugging Apache Virtualhosts
<VirtualHost *:80>
ServerName example.dev
DocumentRoot /var/www/vhosts/www.example.com/public
# Enable Rewrite Log Debugging (Apache 2.2)
RewriteLog /var/www/vhosts/www.example.com/rewrite.log
RewriteLogLevel 6
# Enable Rewrite Log Debugging (Apache 2.4)
# LogLevel alert rewrite:trace6
@ziadoz
ziadoz / embed.php
Last active December 16, 2015 07:19
Parsing YouTube Embed Markup Using DOMDocument
<?php
function parse_youtube_embed($embed) {
if (empty($embed)) {
return false;
}
$dom = new DOMDocument;
if (! $dom->loadHTML($embed)) {
return false;
}
@ziadoz
ziadoz / operators.php
Created April 16, 2013 21:13
PHP Operator Precedence '&&' vs 'AND', '||' vs 'OR'
<?php
// See: http://stackoverflow.com/questions/2803321/and-vs-as-operator
// http://www.php.net/manual/en/language.operators.precedence.php
$foo = true;
$bar = false;
$truthiness = $foo && $bar;
echo ($truthiness ? 'TRUE' : 'FALSE'); // FALSE
@ziadoz
ziadoz / _form.html.twig
Last active March 20, 2016 08:32
Symfony Form Twig Theme
{# Form Theme #}
{# See: https://github.com/symfony/symfony/blob/2.0/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig #}
{# See: http://stackoverflow.com/questions/10043251/how-to-add-a-css-class-on-a-form-row-in-twig-template #}
{% form_theme form _self %}
{# Field Row #}
{# - Add 'error' class to form widgets. #}
{# - Display errors below widgets. #}
{% block field_row %}
@ziadoz
ziadoz / ContainsHtml.php
Last active December 16, 2015 08:59
Symfony Custom Form Basic Spam Validators
<?php
namespace Ziadoz\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class ContainsHtml extends Constraint
{
@ziadoz
ziadoz / extends.js
Created April 23, 2013 19:25
jQuery Extends
$.fn.extend({
// ---- HTML Comments ---- //
comments: function() {
return $(this).contents()
.filter(function() {
return this.nodeType == 8;
});
},
// ---- Outer HTML ---- //
@ziadoz
ziadoz / eloquent.php
Last active November 28, 2018 14:40
Laravel 4 Eloquent ORM Standalone (Observers, Query Logging).
<?php
class Post
{
protected $table = 'posts';
/**
* You can define your own custom boot method.
*
* @return void
**/