Skip to content

Instantly share code, notes, and snippets.

View josephdpurcell's full-sized avatar

Joseph D. Purcell josephdpurcell

View GitHub Profile
@josephdpurcell
josephdpurcell / attaching-closures-to-objects-in-php.php
Created January 3, 2013 15:58
Attaching PHP Closures/Anonymous Functions a Class/Object
<?php
/**
* references:
* http://www.murraypicton.com/2010/09/extending-objects-using-anonymous-functions-in-php/
* http://php.net/manual/en/functions.anonymous.php
* http://php.net/manual/en/function.is-callable.php
*/
class Foo {
public $bar;
@josephdpurcell
josephdpurcell / bootstrap-modal.js
Created May 20, 2013 13:40
The "bootstrap-modal.js" includes a fix for the modal pull request https://github.com/twitter/bootstrap/pull/6793. However, that was a fix for the code as it was 3 months ago. The "modal.js" file includes the same code, but is adapted for the latest 3.0.0-wip (5/20/13).
/* =========================================================
* bootstrap-modal.js v3.0.0
* http://twitter.github.com/bootstrap/javascript.html#modals
* =========================================================
* Copyright 2012 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
@josephdpurcell
josephdpurcell / mysqlbup.cron
Created February 20, 2014 13:55
Rotating Daily and Weekly MySQL Dump Cron
# mysqlbup.cron by josephdpurcell
#
# This cron will export all databases every day at 4am. Those exports are
# automatically rotating from servername.com.day0 to servername.com.day6 so you
# always have a bup of the last 7 days of backups.
#
# Also, this cron will export all databases every week for the last 4 weeks at
# 2am on Sunday. Those exports are automatically rotating from
# servername.com.week0 to servername.com.week3 so you always have a bup of the
# last 4 weeks of backups.
@josephdpurcell
josephdpurcell / iptables-setup.sh
Last active September 23, 2021 07:48
iptables setup
#!/bin/bash
# This is my script for setting up firewall rules. It's a work in progress and
# I'm not 100% convinced this is the best setup for me. But, it's a start.
# Also, many thanks to Digital Ocean from which I drew a few hints:
# https://www.digitalocean.com/community/articles/how-to-setup-a-basic-ip-tables-configuration-on-centos-6
#
# I don't like the idea of anything on the machine being able to use a port
# that isn't an application port I explicitly allow. For example, I know that I
# only want mail, DNS, HTTP(S), and SSH. But, alas! I had to allow ports
# sourced from the machine (see b) and default output policy to accept (see i)
@josephdpurcell
josephdpurcell / prepare-commit-msg
Last active August 29, 2015 14:07 — forked from aczietlow/prepare-commit-msg
Make Mac friendly
#!/bin/sh
#
# An example hook script to prepare the commit log message.
# Called by "git commit" with the name of the file that has the
# commit message, followed by the description of the commit
# message's source. The hook's purpose is to edit the commit
# message file. If the hook fails with a non-zero status,
# the commit is aborted.
#
# To enable this hook, rename this file to "prepare-commit-msg" and
@josephdpurcell
josephdpurcell / commit-54d285f083563faef6a56818454bdd560352b490.patch
Created January 26, 2016 23:10
RESTful patch: Do not take the anon user as a valid authentication
diff --git a/src/Authentication/AuthenticationManager.php b/src/Authentication/AuthenticationManager.php
index 460815c..2f0e059 100644
--- a/src/Authentication/AuthenticationManager.php
+++ b/src/Authentication/AuthenticationManager.php
@@ -96,13 +96,13 @@ class AuthenticationManager implements AuthenticationManagerInterface {
$account = NULL;
foreach ($this->plugins as $provider) {
/* @var \Drupal\restful\Plugin\authentication\AuthenticationInterface $provider */
- if ($provider->applies($request) && $account = $provider->authenticate($request)) {
+ if ($provider->applies($request) && ($account = $provider->authenticate($request)) && $account->uid) {
@josephdpurcell
josephdpurcell / 819-access-token-hyphen.patch
Last active January 27, 2016 20:21
Ref 833 Hotfix for hyphen/dash auth headers issue
diff --git a/modules/restful_token_auth/src/Plugin/authentication/TokenAuthentication.php b/modules/restful_token_auth/src/Plugin/authentication/TokenAuthentication.php
index 331281a..9d33d7a 100644
--- a/modules/restful_token_auth/src/Plugin/authentication/TokenAuthentication.php
+++ b/modules/restful_token_auth/src/Plugin/authentication/TokenAuthentication.php
@@ -93,7 +93,7 @@ class TokenAuthentication extends Authentication {
// If we don't have a $key_name on either the URL or the in the headers,
// then check again using a hyphen instead of an underscore. This is due to
// new versions of Apache not accepting headers with underscores.
- if (empty($input[$key_name]) && $request->getHeaders()->get($key_name)->getValueString()) {
+ if (!$input[$key_name] && !$request->getHeaders()->get($key_name)->getValueString()) {
@josephdpurcell
josephdpurcell / disable-cookie-for-login-token.patch
Created February 23, 2016 23:02
Disable cookie auth on login token for RESTful 2.x
@josephdpurcell
josephdpurcell / disable-cookie-for-login-token-example.module
Created February 23, 2016 23:07
Disable cookie auth on login token for RESTful 1.x
@josephdpurcell
josephdpurcell / phpmd_drupal_ruleset.xml
Created March 3, 2016 21:32
PHP Mess Detector Ruleset for Drupal.
<?xml version="1.0"?>
<ruleset
name="PMD Ruleset for Drupal"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"
>
<rule ref="rulesets/unusedcode.xml" />
<rule ref="rulesets/codesize.xml">
<exclude name="ExcessiveMethodLength" />