Skip to content

Instantly share code, notes, and snippets.

@Sleavely
Sleavely / form.php
Last active January 3, 2016 03:08
Drupal 7 form file processing
<?php
function mymodule_form($form, &$form_state) {
// [...]
$form['attachment'] = array(
'#type' => 'file',
'#title' => t('Attachment'),
);
[role=navigation] {
margin-bottom: 1px;
}
[role=main] > div {
background-color: white;
border-left: 1px solid #d1d1d1;
border-right: 1px solid #d1d1d1;
box-sizing: border-box;
margin: 0 auto;
padding: 1em;
@Sleavely
Sleavely / first-and-subsequent-within-month.sql
Last active November 2, 2016 19:01
First time customers in Magento, and subsequent purchases within that period
/* New customers and all their orders within that month */
SELECT
p.increment_id,
p.store_id,
p.created_at,
p.state,
p.customer_firstname,
p.customer_lastname,
p.customer_email,
(p.base_subtotal + p.base_shipping_amount) AS grandtotal_minus_tax,
@Sleavely
Sleavely / POT.patch
Last active August 29, 2015 14:02
POT Minimap patch
From 3ec96e871d2e561faeef82524ed91bb98698f6a1 Mon Sep 17 00:00:00 2001
From: Joakim Hedlund
Date: Thu, 12 Jun 2014 18:44:52 +0200
Subject: [PATCH] Parse and tuck away minimap colors
---
app/libraries/POT/OTS_ItemsList.php | 68 ++++++++++++++++++++++++++++++++-----
1 file changed, 59 insertions(+), 9 deletions(-)
diff --git a/app/libraries/POT/OTS_ItemsList.php b/app/libraries/POT/OTS_ItemsList.php
@Sleavely
Sleavely / arrayFromHTMLInput.php
Last active August 29, 2015 14:10
Dealing with dynamic amounts of fields in HTML forms usually means you get your data in a very foreach-unfriendly manner. This helper function is meant to address that. Input and output are presented in JSON because I like it better. Actual results are PHP. YMMV
<?php
/**
* Helper function to reformat arrays.
* @see https://gist.github.com/Sleavely/2c1aa7ba13da80dfeb43
*
* @param array $source
* The multidimensional array where each input field is an array
* @param array $arrays
* A list of which keys to include in the output
<?php
$errand = foo();
$order = bar();
// Email the customer a receipt
$mail = Mail::send('returns.emails.approved', array('data' => 'to', 'the' => 'view'), function($message) use ($errand, $order)
{
// The "use" keyword allows us to access external variables in our anonymous function
@Sleavely
Sleavely / apply-price-rules.php
Last active November 22, 2018 16:34
Programmatically apply catalog price rules in Magento
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
// Bootstrap Magento
require '../magento/app/Mage.php';
Mage::app('admin', 'store');
try{
$catalogPriceRule = Mage::getModel('catalogrule/rule');
@Sleavely
Sleavely / deploy.sh
Last active August 29, 2015 14:21
Simple Magento deployment
#!/bin/sh
cd ~/www/magento
# Pull main repo
git pull --no-edit origin master
# Update submodules
git submodule update --recursive
git submodule update --init --recursive
@Sleavely
Sleavely / eu-pvp3.md
Last active April 27, 2016 07:23
Naval Action Liaisons

Non-exhaustive list of liaisons and prominent figures from the clans and nationalities on Naval Action EU PVP Mirror 3.

Denmark-Norway

*crickets*

France

EFC

  • Rakk
<?php
use Carbon\Carbon;
class ApiV1Controller extends BaseController {
public $endpoints = array(
'items' => 'https://storage.googleapis.com/nacleanopenworldprodshards/ItemTemplates_cleanopenworldprodeu2.json',
'nations' => 'https://storage.googleapis.com/nacleanopenworldprodshards/Nations_cleanopenworldprodeu2.json',
'ports' => 'https://storage.googleapis.com/nacleanopenworldprodshards/Ports_cleanopenworldprodeu2.json',
'shops' => 'https://storage.googleapis.com/nacleanopenworldprodshards/Shops_cleanopenworldprodeu2.json',