Skip to content

Instantly share code, notes, and snippets.

View ziadoz's full-sized avatar

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / index.php
Last active June 2, 2023 23:08
Simple PHP / jQuery CSRF Protection
<?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 August 25, 2012 03:38
PHP Settings Bootstrap
<?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 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 / console.php
Created September 4, 2012 22:45
Symfony Console Component Example
#!/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 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 / index.php
Created September 10, 2012 16:35
PHP and Apache Environment Configuration
<?php
define('ENV', getenv('ENV') !== false ? getenv('ENV') : 'development');
/* OR */
define('ENV', isset($_SERVER['ENV']) ? $_SERVER['ENV'] : 'development');
@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 / highlighting.js
Last active March 16, 2023 13:21 — forked from jlong/uri.js
URI Parsing with Javascript/jQuery
(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');
}