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
@mamchenkov
mamchenkov / file-random-access.php
Last active December 19, 2015 21:48
Read file line-by-line from given byte offset. Handy for re-processing large logs files.
<?php
/**
* Read file line-by-line from given byte offset.
* Handy for re-processing large logs files.
*/
// Filename to use for temporary data
define('DATA_FILE', 'data.log');
// Create the data file on the fly
@mamchenkov
mamchenkov / chart_web_requests.sh
Created August 5, 2013 08:20
Chart total number of web requests per hour using Google Charts
#!/bin/bash
# Chart total number of web requests per hour using Google Charts
# Usage: chart_web_request.sh [DATE] [PATH]
#
# If DATE is not given, yesterday is used. Date should be in the format
# that your web server is using in access logs
#
# If PATH is not given /var/log/httpd/*-access_log is used.
#
@mamchenkov
mamchenkov / ini2json
Created August 8, 2013 15:26
Quick converter of INI files to JSON files written in PHP.
#!/usr/bin/php
<?php
$in = empty($argv[1]) ? '' : $argv[1];
$out = empty($argv[2]) ? '' : $argv[2];
if (empty($out)) {
$out = basename($in, '.ini') . '.json';
}
<?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
/**
* Quick proof of concept for feature management
*/
class Feature {
/**
* This is where we keep the list of features
*/
protected $features;
<?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(
@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");
}