Skip to content

Instantly share code, notes, and snippets.

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / index.php
Last active Apr 6, 2020
Simple PHP / jQuery CSRF Protection
View index.php
<?php
// See: http://blog.ircmaxell.com/2013/02/preventing-csrf-attacks.html
// Start a session (which should use cookies over HTTP only).
session_start();
// Create a new CSRF token.
if (! isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = base64_encode(openssl_random_pseudo_bytes(32));
}
@ziadoz
ziadoz / bootstrap.php
Created Aug 25, 2012
PHP Settings Bootstrap
View bootstrap.php
<?php
// Mode.
define('MODE', isset($_SERVER['MODE']) ? $_SERVER['MODE'] : 'development');
// Character Set.
ini_set('default_charset', 'UTF-8');
mb_internal_encoding('UTF-8');
mb_regex_encoding('UTF-8');
mb_http_input('UTF-8');
mb_http_output('UTF-8');
@ziadoz
ziadoz / composer.json
Created Aug 29, 2012
Advanced Composer Examples (PHPMailer from zip, local repository)
View composer.json
{
"require": {
"phpmailer/phpmailer": "5.2.1"
},
"repositories": [
{
"type": "package",
"package": {
"name": "phpmailer/phpmailer",
"version": "5.2.1",
@ziadoz
ziadoz / .bash_profile
Last active Oct 9, 2015
Web Development Setup (Bash, SSH, Ruby)
View .bash_profile
# 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 / console.php
Created Sep 4, 2012
Symfony Console Component Example
View console.php
#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Finder\Finder;
@ziadoz
ziadoz / FooController.php
Created Sep 5, 2012 — forked from igorw/FooController.php
Silex convention-based controllers
View FooController.php
<?php
// src/Foobar/Controller/FooController.php
namespace Foobar\Controller;
class FooController
{
public function helloAction($request)
{
@ziadoz
ziadoz / index.php
Created Sep 10, 2012
PHP and Apache Environment Configuration
View index.php
<?php
define('ENV', getenv('ENV') !== false ? getenv('ENV') : 'development');
/* OR */
define('ENV', isset($_SERVER['ENV']) ? $_SERVER['ENV'] : 'development');
@ziadoz
ziadoz / mobile.js
Created Sep 10, 2012
jQuery Mobile User Agent Detection
View mobile.js
$.extend({
isMobile: function() {
return navigator.userAgent.match(/Android|webOS|iPhone|iPod|iPad|BlackBerry/i) !== null;
}
});
@ziadoz
ziadoz / gist:3692801
Created Sep 10, 2012
Bash Users with Different Primary Group
View gist:3692801
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 / highlighting.js
Last active Jun 28, 2018 — forked from jlong/uri.js
URI Parsing with Javascript/jQuery
View highlighting.js
(function($) {
$(document).ready(function() {
// Highlight Navigation
var url = $.parseUrl(document.location);
$('a').each(function() {
var link = $.parseUrl(this.href);
if (link.pathname !== '' && link.pathname === url.pathname) {
$(this).siblings().removeClass('active');
$(this).addClass('active');
}
You can’t perform that action at this time.