Skip to content

Instantly share code, notes, and snippets.

@ajbonner
ajbonner / strace-fpm.sh
Created April 11, 2017 14:13
Strace all running php-fpm processes to file with timestamps and pid
sudo strace -f -tt -o /tmp/php.trace -s1024 -p `pgrep -f php-fpm | tr '\n' ','`
@ajbonner
ajbonner / Fix-GH-10218-DateTimeZone-Parse-ETC-php82.patch
Created January 17, 2023 11:47
Fix PHP GH Issue 10218 < PHP 8.2.1 DateTimeZone cannot parse + abbreviation in Timezones
diff -ruN php-8.2.1/ext/date/lib/parse_date.c php-8.2.1-gh10218/ext/date/lib/parse_date.c
--- php-8.2.1/ext/date/lib/parse_date.c 2023-01-03 13:40:55.000000000 -0500
+++ php-8.2.1-gh10218/ext/date/lib/parse_date.c 2023-01-17 06:37:01.121532677 -0500
@@ -787,7 +787,7 @@
(**ptr >= 'A' && **ptr <= 'Z') ||
(**ptr >= 'a' && **ptr <= 'z') ||
(**ptr >= '0' && **ptr <= '9') ||
- **ptr == '/' || **ptr == '_' || **ptr == '-'
+ **ptr == '/' || **ptr == '_' || **ptr == '-' || **ptr == '+'
) {
@ajbonner
ajbonner / application_controller.rb
Created October 15, 2012 10:38
How not to rescue_from exceptions
class ApplicationController < ActionController::Base
# Catch all exceptions at a stretch
rescue_from Exception, :with => :handle_exceptions
private
# Handle exceptions
def handle_exceptions(e)
case e
@ajbonner
ajbonner / rename_tags.sh
Last active August 7, 2017 19:43
Rename old git tags and copy annotations
#!/bin/bash
for tag in $(git tag | grep '^2017'); do
git tag -a $(echo $tag | sed 's/^2017/17/') $tag -m "$(git tag -n $tag | sed -E 's/2017\.[0-9]{2}\.[0-9]{2}\.[0-9]{2}\s*//')"
git tag -d $tag
git push origin :refs/tags/$tag
done
@ajbonner
ajbonner / php-fpm-fcgi-status.sh
Last active August 2, 2017 14:54
PHP-FPM Status from CLI
sudo -u www-data \
SCRIPT_NAME=/status \
SCRIPT_FILENAME=/status \
REQUEST_METHOD=GET \
QUERY_STRING=full \
cgi-fcgi -bind -connect /var/run/php/php7.0-fpm.sock
# see https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/
# core
brew install coreutils
# key commands
brew install binutils
brew install diffutils
brew install ed --default-names
brew install findutils --with-default-names
@ajbonner
ajbonner / ImageController.php
Last active July 8, 2016 18:46
Fix tiresome headers already sent bug in Magento 1.x
<?php
/**
* Generate image thumbnail on the fly
*/
public function thumbnailAction()
{
$file = $this->getRequest()->getParam('file');
$file = Mage::helper('cms/wysiwyg_images')->idDecode($file);
$thumb = $this->getStorage()->resizeOnTheFly($file);
if ($thumb !== false) {
@ajbonner
ajbonner / event_dispatch_check.php
Last active February 5, 2016 19:52
Quick and dirty way to test if an observer responds to a given event in Magento 1 using MageTest
<?php
class SomeTestTest extends MageTest_PHPUnit_Framework_TestCase
{
/**
* @param string $observerName e.g. mymodulens_mymodule_does_something_on_order_place
* @param string $eventName e.g. a dispatched event e.g. sales_order_place_after
* @param string $area e.g. global/frontend/admin/adminhtml
*/
public function assertObserverReceivesEvent($observerName, $eventName, $area)
@ajbonner
ajbonner / customer_address_query.php
Last active January 1, 2016 04:59
Adding an attribute to a magento customer collection
$commonwealthSubscribers = Mage::getModel('customer/customer')
->getCollection()
->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing')
->addAttributeToFilter('billing_country_id', array('in' => 'AU', 'CA', 'GB'))
@ajbonner
ajbonner / str_putcsv.php
Last active December 26, 2015 11:18
A version of putcsv that returns a string rather than writes to a file
<?php
/**
* @param array $data
* @return string
*/
public function str_putcsv($data)
{
$fh = fopen('php://memory', 'rwb');