Skip to content

Instantly share code, notes, and snippets.

View jameshalsall's full-sized avatar
🐍

James Halsall jameshalsall

🐍
View GitHub Profile
<?php
use Magento\Framework\Model\ResourceModel\IteratorFactory;
class HugeTableIterator
{
/** @var IteratorFactory */
private $iteratorFactory;
/** UnbufferedQueryConnectionFactory */
<?php
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\DB\Adapter\AdapterInterface;
class UnbufferedQueryConnectionFactory
{
/** @var ResourceConnection */
private $resourceConnection;
<?php
$pdo = new PDO("mysql:host=localhost;dbname=foo", 'user', 'pass');
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
$result = $pdo->query(/* SELECT ... */);
// $result is now unbuffered, and not loaded into memory until you ask for it
<?php
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Model\ResourceModel\IteratorFactory;
class HugeTableIterator
{
/** @var ResourceConnection */
private $resourceConnection;
@jameshalsall
jameshalsall / 0_reuse_code.js
Created January 22, 2014 13:05
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
<?php
// saveJSON: XML to JSON conversion/transformation
// The saveJSON method is implemented as a method of the example DOMDocumentExtended class, which
// extends DOMDocument. It will transform the currently loaded DOM into JSON using XSLT. Since
// there isn't a reliable automatic way of detecting if certain siblings nodes should be
// represented as arrays or not, a "forceArray" parameter can be passed to the saveJSON method.
// It should be noted that the forceArray functionality doesn't recognize namespaces. This is
// an easy enough fix, I just didn't need it at the time of writing (look for local-name() and
$button = $('get button selector');
$button.on(function() {
runFilters(addClassNoFilters);
});
function runFilters(callback) {
// do filters
@jameshalsall
jameshalsall / Subquery.php
Created April 17, 2012 09:13
Subquery example
<?php
function getAlternativeRoom()
{
$rooms = array();
$bookings = $this->getMeetingRoomBooking();
$locationId = $bookings[0]->getMeetingRoom()
->getMeetingRoomLocationId();
$query = Doctrine_Core::getTable('MeetingRoom')
->createQuery('r')