Skip to content

Instantly share code, notes, and snippets.

View ababkov's full-sized avatar

Alex Babkov ababkov

View GitHub Profile
@ababkov
ababkov / _.md
Created February 6, 2016 07:24
reddit base
@ababkov
ababkov / _.md
Created February 6, 2016 07:23
reddit base
@ababkov
ababkov / php-expanded-glob
Created September 3, 2015 20:57
Expand /**/ in a php glob expression to simulate nested folder expressions (which otherwise aren't supported for some reason)
function expandExpression($path,$depth=3,$marker="/**/"){
$e_path = explode($marker,$path);
if( count($e_path) > 2 ){
throw new \InvalidArgumentException("Only one instance of '{$marker}' is supported per expression.");
} elseif( count($e_path) < 2 ){
return $e_path;
}
$base_path = $e_path[0];
$sub_path = $e_path[1];
@ababkov
ababkov / monolog-timezone-hack.php
Last active August 29, 2015 14:12
Force the Monolog Logger to use non default timezone
<?php
use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
$example_timezone = "Australia/Brisbane";
$logger = new Logger($name);
@ababkov
ababkov / reaxml-read-current-listing-addresses.php
Created May 3, 2014 08:54
REAXML - Read current listing addresses
<?php
$xml_file_path = dirname(__FILE__)."/reaxml.xml";
$csv_file = dirname(__FILE__)."/current-listings.csv";
$xmlr = new XMLReader();
$opened = $xmlr->open($xml_file_path);
if( !$opened ){
throw new Exception("WARN: Could not open XML file '{$xml_file_path}'. Please check it exists and is valid.");
}
@ababkov
ababkov / json-to-csv.php
Last active August 29, 2015 14:00
Convert JSON file to CSV
<?php
$json = json_decode(file_get_contents("source.json"),true);
$fh = fopen("target.csv","w+");
fputcsv($fh,array_keys(current($json)));
foreach($json as $row){
fputcsv($fh,$row);
}