Skip to content

Instantly share code, notes, and snippets.

<?php
$suffixes = array('');
// ...
foreach ($suffixes as $suffix) {
foreach ($dirs as $dir) {
if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && (defined('PHP_WINDOWS_VERSION_BUILD') || is_executable($file))) {
return $file;
}
}
@code-poel
code-poel / laravel_table_schema.php
Last active December 18, 2024 17:01
Get schema metadata on Laravel tables or columns...
<?php
// https://stackoverflow.com/questions/18562684/how-to-get-database-field-type-in-laravel/18563159#18563159
/* @var $schema \Doctrine\DBAL\Schema\AbstractSchemaManager */
$schema = DB::getDoctrineSchemaManager();
$columns = $schema->listTableColumns('cities');
dd($columns);
/*
@code-poel
code-poel / json_decode.php
Created August 25, 2015 11:32
Guzzle's method for "validating" JSON
<?php
/**
* Wrapper for JSON decode that implements error detection with helpful error
* messages.
*
* @param string $json JSON data to parse
* @param bool $assoc When true, returned objects will be converted into
* associative arrays.
* @param int $depth User specified recursion depth.
@code-poel
code-poel / gist:ade9a020b977ae1813a6
Created September 9, 2015 18:40
Regular expression to validate an HTML ID.
^[a-zA-Z][\w:.-]*$
@code-poel
code-poel / composer.json
Last active September 12, 2015 05:50 — forked from spekkionu/composer.json
Standalone validation using laravel validation component
{
"name": "spakkionu/validate",
"description": "Validation Test",
"require": {
"illuminate/validation": "~4.2.9"
},
"license": "MIT",
"authors": [
{
"name": "Jonathan Bernardi",
ini_set('error_reporting', E_ERROR);
register_shutdown_function("fatal_handler");
function fatal_handler() {
$error = error_get_last();
echo("<pre>");
print_r($error);
}
@code-poel
code-poel / magento.json
Last active April 27, 2024 11:35
lnav Magento 1 Log Format
#! /usr/bin/env lnav -i
{
"magento_log" : {
"title" : "Magento Log Format",
"description" : "Log format used in Magento 1.",
"url" : "https://gist.github.com/chrisvanderpoel/e19dcab8ce69bc9806a3",
"regex" : {
"basic" : {
"pattern" : "^(?<timestamp>[0-9]{4}\\-[0-9]{2}\\-[0-9]{2}\\T[0-9]{2}\\:[0-9]{2}\\:[0-9]{2}\\+[0-9]{2}\\:[0-9]{2})\\s(?<level>\\w+)\\s(?<component>\\(\\w+\\))\\:\\s(?<body>.*)$"
}
@code-poel
code-poel / Mview.php
Created January 22, 2016 16:58
Check if an Mview index is up-to-date
<?php
// Check if an Mview index is up-to-date
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$sub = $connection->select()->from(['cl' => $table], ['version_id'])->order('version_id DESC')->limit(1);
$select = $connection->select()
->from(['m' => 'enterprise_mview_metadata'], ['version_id', 'latest_id' => $sub, 'status'])
->where('changelog_name = ?', $table)
->limit(1);
$status = $connection->fetchRow($select);
@code-poel
code-poel / Bypass.php
Created March 4, 2016 15:38
Bypass the Magento Flat Catalog Settings
<?php
// Notice this is NOT SAVING the setting...
Mage::app()->getStore()->setConfig(Mage_Catalog_Helper_Product_Flat::XML_PATH_USE_PRODUCT_FLAT, '0');
// Build your collection here...
@code-poel
code-poel / AttributeUpdate.php
Created March 16, 2016 21:27
How to update attributes in bulk.
<?php
// http://magento.stackexchange.com/questions/43917/fastest-way-to-update-an-attribute-in-all-products
$product->setData('something', true);
$product->getResource()->saveAttribute($product, 'something');
// OR
\Mage_Catalog_Model_Resource_Product_Action::updateAttributes