Skip to content

Instantly share code, notes, and snippets.

View attitude's full-sized avatar

Martin Adamko attitude

View GitHub Profile
@attitude
attitude / composer.json
Last active August 29, 2015 13:57
Function to check if array is associative (key-value)
{
"name": "attitude/Functions/is_assoc_array",
"autoload": {
"files": ["function-is_assoc_array.php"]
}
}
@attitude
attitude / wp-json-api-post-meta.diff
Created February 12, 2014 20:13
Patch `lib/class-wp-json-posts.php` to support saving, updating and deleting post meta using WP REST API. #proposal #JSON #REST #WordPress
diff --git a/lib/class-wp-json-posts.php b/lib/class-wp-json-posts.php
index e440b25..59c6bfd 100644
--- a/lib/class-wp-json-posts.php
+++ b/lib/class-wp-json-posts.php
@@ -847,14 +847,57 @@ class WP_JSON_Posts {
return $can_insert;
}
- // Post meta
- // TODO: implement this
@attitude
attitude / closing-connection-early-page-load-speed-tip.md
Created September 23, 2013 13:08
Faster page loading by closing connection early and deferring processes to finish only after that

Page Speed Tip: Defer time consuming processes after sending the page output

Recently I have written a PHP class to try server analytics. But using the UAMP, script has to wait for response from Google's servers in order to close the connection. Even if the response took less than 100ms, still it's unnecessary time for client to wait and show loading spinner and block page render.

There is a space for optimisation: closing connection early and present the client with the response before the script finishes it's run.

@attitude
attitude / on-git-read-tree-and-dependencies.md
Created September 18, 2013 16:23
Reusing of single library component in your project with Git `read-tree`

Here is a quick tip on pulling dependencies in your project using git read-tree command.

The Problem

How to use a single component from some library (eg. Form from Symfony), but not the whole library (tried the git submodule ?).

  1. Init project:

    Create a new project and init Git:

@attitude
attitude / Runnig PHP v5.3 in MAMP.md
Created July 17, 2013 16:24
You can run current version of MAMP with PHP 5.4.4 or 5.2.17. How to run 5.3+

Introduction

Lately I needed to test some code against PHP version 5.3 wich is (hopefully not forever) the highest supported version on one of my clients hosting right now. To cut the story short, I develop and test on a local MAMP server, usualy for PHP v5.4+. The free version of MAMP will let you run either v5.4.4 or v5.2.17 of PHP. To run other version you need to purchase MAMP Pro. But I haven't read/heard a single person saing about MAMP Pro worth its price tag.

Setup

My MAMP installation comes with many PHP versions preinstalled. See /Applications/MAMP/conf (Cmd+G), but you can swich only between two: the lowest and the heighest version of PHP. No option between. There are these versions in my MAMP/conf folder:

@attitude
attitude / function-get_pagination_data.php
Created July 12, 2013 21:47
Generate {{mustache}} ready data for pagination
<?php
/**
* Returns {{mustache}} ready data for pagination
*
* Pagination array for `prev`, `next`, `start`, `end` and `jump`
* to direct pages
*
* @author Martin Adamko <@martin_adamko>
* @licence The MIT Licence <http://opensource.org/licenses/MIT>
@attitude
attitude / function-maybe_decode_json.php
Last active December 19, 2015 16:29
Decodes JSON string if needed
<?php
/**
* Decodes JSON string if needed
*
* @uses json_decode()
* @author Martin Adamko <@martin_adamko>
* @licence The MIT Licence <http://opensource.org/licenses/MIT>
*
* @param string $str String to decode if needed
@attitude
attitude / function-wp_get_attachment_meta.php
Last active December 19, 2015 13:49
Returns metadata for current WordPress attachment or array of attachments
<?php
/**
* Returns metadata for current WordPress attachment or array of attachments
*
* Reads all attachment metadata and expands it. URLs are rewritten with upload
* dir prepended, file size is calculated if function exists. By default url protocol
* is removed, use `add_filter()` to disable.
*
* @uses {@link apply_filters() http://codex.wordpress.org/Function_Reference/apply_filters}
@attitude
attitude / function-file_size_format.php
Last active December 19, 2015 13:49
Returns formatted file size
<?php
/**
* Returns formatted file size
*
* Inspired by {@link http://betterwp.net/wordpress-tips/size_format/}, modified
* to work outside of WordPress environment.
*
* @param int $bytes Size in bytes
* @param int $decimals Number of decimal places
@attitude
attitude / function-array_merge_for_sql.php
Last active December 19, 2015 10:58
Function to merge new SQL argument arrays (right) with defaults (left)
<?php
/**
* Merges new SQL argument arrays with defaults
*
* Differs from {@link array_merge()} and {@link array_merge_recursive()}:
*
* 1. Array of 'where', 'orderby', 'groupby' and 'join' keys should be
* appended and remain unique.
* 2. 'select', 'limit' should be overwritten, by new argument on right