Skip to content

Instantly share code, notes, and snippets.

@matesnippets
matesnippets / font-loader.js
Created May 27, 2015 06:30
JavaScript, Fonts, Loads font's asynchronously and saves them to local storage
/**
* Loads fonts asynchronously
*
* NOTE: needs love.
*
* @link https://github.com/filamentgroup/woff2-feature-test/blob/master/woff2.js
* @link http://bdadam.com/blog/loading-webfonts-with-high-performance.html
*/
'use strict';
@matesnippets
matesnippets / .editorconfig
Created May 25, 2015 09:30
Editorconfig, Sublime Text, my .editorconfig file
; EditorConfig is awesome: http://EditorConfig.org
# editorconfig.org
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
@matesnippets
matesnippets / .eslintrc
Last active December 12, 2015 16:07
JavaScript, Link, My curret ESLint settings
env:
browser: true
rules:
brace-style: [2, "stroustrup", { "allowSingleLine": true }]
comma-style: [2, "last"]
default-case: 2
# func-style: [2, "expression"]
guard-for-in: 2
indent: [2, 4, {"SwitchCase": 1}]
@matesnippets
matesnippets / is-child.php
Created May 7, 2015 08:11
Check if page is a child of, takes a page ID
/**
* Check if a a page is child of a given ID
*
* @link(_blank, http://bavotasan.com/2011/is_child-conditional-function-for-wordpress/)
* @param int $page_id The parent page id to check
* @return bool
*/
function n26_is_child($page_id) {
global $post;
if (is_page() && ($post->post_parent == $page_id)) {
@matesnippets
matesnippets / description-tag.php
Last active August 29, 2015 14:17
PHP, WordPress, make nice content to description tag
/**
* Put some nice content into a description meta tag
*
* Usage:
* <meta name="description" content="<?php echo ud_site_desc(); ?>">
*
* @return string 200 characters long descrption tag
*/
function ud_site_desc()
{
@matesnippets
matesnippets / body_class_prefix.php
Created March 10, 2015 16:59
PHP, WordPress, Prepend a namespace in WordPress body_class() function, so that it won't clash with other class names. E.g. `root--`.
/**
* Prepend a namespace in WordPress body_class() function
* @param string $prefix The desired prefix
* @param string $classes Additional classes separated by single space
* @return string Single space separated list of classes
*/
function body_class_prefix($prefix, $classes = '')
{
global $wp_query;
$output = '';
@matesnippets
matesnippets / strip-newlines
Created March 9, 2015 15:46
PHP, Regex, Strip newlines from a string
$string = trim(preg_replace('/\s+/', ' ', $string));
@matesnippets
matesnippets / class_excerpt.php
Created March 9, 2015 15:29
PHP, WordPress, With this you can give excerpt a custom class, nice when BEMming.
/**
* Adds a custom class to excerpt `p` tah
* @param string $class The wanted new class
* @return string `p` tag with a class and the content of the excerpt
*/
function cm_excerpt($class)
{
$excerpt = strip_tags(get_the_excerpt());
echo '<p class="' . $class . '">' . $excerpt . '</p>';
}
@matesnippets
matesnippets / printr_func.php
Created March 9, 2015 15:27
PHP, print_r() helper function. Prints arrays out in a nice, formatted, human readable way.
/**
* Prints out array in human readable form, just a helper function
* @param array $arr The wanted array to be printed
* @return array The array in human readable form
*/
function printr_func($arr)
{
echo "<pre class='printr'><code>";
print_r($arr);
echo "</code></pre>";
@matesnippets
matesnippets / cm_svg_get.php
Created March 9, 2015 15:24
PHP, WordPress, SVG image getter, embed SVG straight to the page, no img tag needed and keeps templated nice and tidy.
/**
* Get SVG file as raw SVG, not img tag
* @param string $path Path to images direcotry
* @param string $file The filename, file extension (.svg) can be omitted
* @return string The contents of the wanted SVG file
*/
function cm_svg_get($path = 'images', $file = '')
{
// $file = $file.".svg";
$svg = ".svg";