Skip to content

Instantly share code, notes, and snippets.

View ankr's full-sized avatar
🎯
Focusing

Andreas ankr

🎯
Focusing
View GitHub Profile
/*
* Contenteditable placeholder
* -----------------------------------
* Emulates the behavior of the standerd implementation
* of the input placeholder="text", but can be used on any
* html element that supports focus.
* http://stackoverflow.com/questions/1599660/which-html-elements-can-receive-focus
*/
[contenteditable="true"]:before {
@addyosmani
addyosmani / README.md
Last active September 4, 2024 11:40 — forked from 140bytes/LICENSE.txt
108 byte CSS Layout Debugger

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

@ankr
ankr / debug.php
Created June 13, 2014 08:03 — forked from kimegede/debug.php
<?php
function debug($data) {
$bt = debug_backtrace();
$bt = array_shift($bt);
$data = print_r($data, true);
$html = <<<HTML
<div class="debug-output">
%s
@edwingsm
edwingsm / cd.json
Created April 29, 2014 04:52
Dummy Json sample
{
"CATALOG": {
"CD": [
{
"TITLE": "Empire Burlesque",
"ARTIST": "Bob Dylan",
"COUNTRY": "USA",
"COMPANY": "Columbia",
"PRICE": "10.90",
"YEAR": "1985"
@antonmedv
antonmedv / Flyspeck.js
Last active November 26, 2019 07:01
Simple and Small Dependency Injection Container inspired by Pimple.
/*
* Flyspeck is Dependency Injection Container.
*
* Copyright (c) 2014 Anton Medvedev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
@ankr
ankr / .editorconfig
Last active December 3, 2020 12:50
Base editorconfig for new projects
# Base editorconfig for new projects
root = true
[*]
end_of_line = lf
indent_style = space
tab_width = 4
charset = utf-8
trim_trailing_whitespace = true
<?php
/**
* Custom redis client class to be able to set a custom prefix for every key
*
* @see https://github.com/nicolasff/phpredis
**/
class RedisClient extends Redis {
/**
* Default prefix
@nikic
nikic / objects_arrays.md
Last active September 5, 2024 01:36
Post explaining why objects often use less memory than arrays (in PHP)

Why objects (usually) use less memory than arrays in PHP

This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)

The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array part of it away. So how does that work?

The key here is that objects usually have a predefined set of keys, whereas arrays don't:

@sgmurphy
sgmurphy / url_slug.js
Created July 12, 2012 02:05
URL Slugs in Javascript (with UTF-8 and Transliteration Support)
/**
* Create a web friendly URL slug from a string.
*
* Requires XRegExp (http://xregexp.com) with unicode add-ons for UTF-8 support.
*
* Although supported, transliteration is discouraged because
* 1) most web browsers support UTF-8 characters in URLs
* 2) transliteration causes a loss of information
*
* @author Sean Murphy <sean@iamseanmurphy.com>
@canton7
canton7 / 0main.md
Last active November 7, 2023 08:16
Local versions of tracked config files

How to have local versions of tracked config files in git

This is a fairly common question, and there isn't a One True Answer.

These are the most common techniques:

If you can modify your application