Skip to content

Instantly share code, notes, and snippets.

View attitude's full-sized avatar

Martin Adamko attitude

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / composer.json
Last active May 7, 2021 18:48
Function to generate a slug (a normalized URL sanitized string)
{
"name": "attitude/generate_slug",
"autoload": {
"files": ["function-generate_slug.php"]
}
}
@attitude
attitude / content.yaml
Created May 1, 2014 01:31
First site contnt data for example usage of Macaw together with Publisher
---
################################################################################
#
# COLLECTIONS
#
################################################################################
_id: homepage
_type: collection
route: /
template: homepage
@attitude
attitude / officeOfHelena.js
Created November 18, 2014 11:08
Description for my my friend's IT colleagues to explain them how to leave door open/closed properly.
/*! Closing the Door by Martin Adamko (c) 2014, MIT Licence */
var officeOfHelena = {
person: {
name: "Helena",
surname: "Székhelyi"
}
};
(function(office) {
@attitude
attitude / responsive-github-com.css
Created July 31, 2015 12:13
Responsive github.com CSS. Use e.g Control Freak Chrome extension to inject this CSS.
.wrapper .header,
.site-footer {
min-width: auto;
padding: 10px;
}
body .container {
max-width: 980px;
width: auto;
}