Skip to content

Instantly share code, notes, and snippets.

View ziadoz's full-sized avatar

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / composer.json
Created August 29, 2012 16:13
Advanced Composer Examples (PHPMailer from zip, local repository)
{
"require": {
"phpmailer/phpmailer": "5.2.1"
},
"repositories": [
{
"type": "package",
"package": {
"name": "phpmailer/phpmailer",
"version": "5.2.1",
@ziadoz
ziadoz / .bash_profile
Last active October 9, 2015 18:48
Web Development Setup (Bash, SSH, Ruby)
# Bash Profile
# File: ~/.bash_profile
# Set $WEB_DIR and $SCRIPTS_DIR to the appropriate directories.
export PATH="./vendor/bin:$PATH"
export EDITOR=nano
export WEB_DIR="/var/www/vhosts"
export SCRIPTS_DIR="~/.web"
@ziadoz
ziadoz / FooController.php
Created September 5, 2012 22:25 — forked from igorw/FooController.php
Silex convention-based controllers
<?php
// src/Foobar/Controller/FooController.php
namespace Foobar\Controller;
class FooController
{
public function helloAction($request)
{
@ziadoz
ziadoz / mobile.js
Created September 10, 2012 17:18
jQuery Mobile User Agent Detection
$.extend({
isMobile: function() {
return navigator.userAgent.match(/Android|webOS|iPhone|iPod|iPad|BlackBerry/i) !== null;
}
});
@ziadoz
ziadoz / gist:3692801
Created September 10, 2012 18:36
Bash Users with Different Primary Group
sudo useradd -m -d /home/<username> -s /bin/bash -k /etc/skel -g <primarygroup> -G sudo <username>
sudo passwd <username>
sudo deluser <username>
chsh -s /bin/bash <username>
@ziadoz
ziadoz / chromcast-bgs.js
Last active October 12, 2015 15:19
Download Google ChromeCast Backgrounds with CasperJS
/**
* Command: casperjs chomecast-bgs.js [DIR] [START] [END]
* Examples: casperjs chomecast-bgs.js ~/Downloads/Chromecast
* casperjs chomecast-bgs.js ~/Downloads/Chromecast 25
* casperjs chomecast-bgs.js ~/Downloads/Chromecast 25 35
*
* Note: [DIR] (Required) The directory to download. This must exist, it won't be created.
* [START] (Optional) Start is the image number to start from, incase the script fails and needs to be restarted.
* [END] (Optional) End is the image number to finish at, if you only want a specific range of images.
*/
@ziadoz
ziadoz / fizzbuzz.php
Last active December 10, 2015 05:48
The Fizz Buzz problem solved in PHP.
<?php
// http://content.codersdojo.org/code-kata-catalogue/fizz-buzz/
foreach (range(1, 100) as $i) {
$x = '';
$x .= ($i % 3 === 0 ? 'Fizz' : '');
$x .= ($i % 5 === 0 ? 'Buzz' : '');
echo $i . ' ' . (empty($x) ? $i : $x) . "\n";
}
@ziadoz
ziadoz / checklist.class.php
Last active December 11, 2015 03:58
Perch Checkbox List Field Type
<?php
/**
* Checklist Field Type.
*
* File: PERCH_PATH/addons/fieldtypes/checklist/checklist.class.php
* Usage: <perch:content id="features" type="checklist" label="Features" options="Feature 1, Feature 2, Feature 3" />
* @author Jamie York
**/
class PerchFieldType_checklist extends PerchAPI_FieldType
{
@ziadoz
ziadoz / ternary.php
Last active December 11, 2015 23:28
PHP Ternary (Left/Right Associative)
#!/usr/bin/env php
<?php
// Left associative ternary.
// Output: T
echo (true ? 'True' : false ? 'T' : 'F') . "\n";
// This is essentially the same as above.
// Output: T
echo ((true ? 'True' : false) ? 'T' : 'F') . "\n";
@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;
}