Skip to content

Instantly share code, notes, and snippets.

View LichP's full-sized avatar

Phil Stewart LichP

View GitHub Profile
@LichP
LichP / dotorg_shop_default.theme
Last active December 8, 2020 16:13
Rendering product and variation images for a Drupal Commerce product gallery
<?php
/**
* Implements template_preprocess_commerce_product().
*/
function dotorg_shop_default_preprocess_commerce_product(&$variables) {
if (isset($variables['elements']['#commerce_product'])) {
// Get view mode & assign variable.
$view_mode = $variables['elements']['#view_mode'];
$variables['view_mode'] = $view_mode;
@LichP
LichP / OrderFulfillmentSubscriber.php
Created July 10, 2020 09:34
A Drupal Commerce event subscriber for automatic order fulfillment
<?php
namespace Drupal\commerce_icu_post_checkout\EventSubscriber;
use Drupal\commerce_icu_post_checkout\AutoFulfillmentManagerInterface;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\state_machine\Event\WorkflowTransitionEvent;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@LichP
LichP / email-grep.rb
Created July 28, 2013 20:35
email-grep.rb: Pipe it a file system image and it'll spit out emails. And false positives. Assumes a filesystem with 4k blocks, and mails stored in sequential blocks (not unreasonable for most text mails which only span a few blocks).
#!/usr/bin/env ruby
#
# Email grepper: Read stuff from STDIN in 4k chunks, look for anything
# resembling an email, dump results to recovery directory
RECOVERY_DIR = '/enter/a/recovery/directory/here'.freeze
EMAIL_REGEX = /Received: |Subject: |Return-path: |Return-Path: /
NULL_BYTE = "\000".freeze
OUT_FILE_PREFIX = 'chunk-'.freeze
MODE = "w".freeze
@LichP
LichP / ohm-namespace-orig.rb
Created September 29, 2011 07:32
Ohm::Model.const_missing using eval instead of const_get
#!/usr/bin/env ruby
require 'ohm'
module SomeNamespace
class Post < Ohm::Model
attribute :title
attribute :body
collection :comments, Comment
end