Skip to content

Instantly share code, notes, and snippets.

View mamchenkov's full-sized avatar
🇨🇾
Working, one commit at a time.

Leonid Mamchenkov mamchenkov

🇨🇾
Working, one commit at a time.
View GitHub Profile
<?php
$data = array(
'Collections' => array(
'id' => 1,
'name' => 'Countries',
),
// sorted by group,name from the SQL
'CollectionItems' => array(
array( 'id' => 1, 'collection_id' => 1, 'name' => 'CountryName', 'value' => 'Cyprus', 'group' => 1,),
<?php
// Keep bumping up in powers of two
define('LANG_LIST_VISIBLE', 1);
define('LANG_LIST_HIDDEN', 2);
define('LANG_LIST_BOTH', 4);
print "\nBoth\n";
print_r(getSupportLanguages(LANG_LIST_BOTH));
@mamchenkov
mamchenkov / index.php
Created June 17, 2014 20:52
Facebook BigPipe, pagelets, and other parallel loading test
<?php
/*
* If we are being called as Ajax content provider, just print
* something out, based on passed parameters. Sleep for more
* obvious results.
*/
if (!empty($_REQUEST['widget']) && !empty($_REQUEST['id'])) {
$config = $_REQUEST['widget'] . '-' . $_REQUEST['id'];
switch($config) {
case 'text-one':
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
<?php
/**
* Quick proof of concept for feature management
*/
class Feature {
/**
* This is where we keep the list of features
*/
protected $features;
@mamchenkov
mamchenkov / ticketsSort.php
Last active August 29, 2015 14:03
Sorting multidimensional array
<?php
// Nested array to sort
$data = array(
'Guy' => array(
array('id' => 1, 'title' => 'This'),
array('id' => 7, 'title' => 'Boo'),
array('id' => 9, 'title' => 'Boo'),
array('id' => 3, 'title' => 'Broken'),
),
@mamchenkov
mamchenkov / parse_csv.php
Last active August 29, 2015 14:04
Quick and easy CSV parser into associative array
<?php
// Data CSV file
$fileName = 'data.csv';
// Try to open the CSV file
$fh = fopen($fileName, 'r');
if (!is_resource($fh)) {
die("Failed to open $fileName");
}
<?php
$obj = new FileFinder($argv[1]);
$obj->setFileType(array_slice($argv, 2));
$obj->setExcludingDirectories(array('test1'));
$pages = $obj->find();
print_r($pages);
class FileFinder {
@mamchenkov
mamchenkov / Article.php
Created August 26, 2014 06:51
Saving Article's draft in CakePHP 2
<?php
/* For this whole thing to work, you'll need at least these fields in your
* articles table:
*
* - id (article id)
* - parent_id (to link drafts to parent article)
* - slug (for friendly URLs usually)
* - title (obviously)
* - content (obviously)
@mamchenkov
mamchenkov / object-iframe-with-fallback.html
Last active August 29, 2015 14:07 — forked from paulirish/gist:616412
Object tag as an iframe, with fallbacks
<!-- so it turns out that the object tag can act like an iframe
but the cool thing is you can nest object tags inside eachother for a fallback path.
what this means is you can "objectframe" a site.. and if it fails.. (site down, offline, whatever).. it'll use the next one.
so you can objectframe the live site and fallback to a screenshot.
or something.
demo at : http://jsfiddle.net/paul/CY2FQ/1/
-->