Skip to content

Instantly share code, notes, and snippets.

View ryanve's full-sized avatar
📶
stay free

deepskyblue ryanve

📶
stay free
View GitHub Profile
@ryanve
ryanve / self-source.php
Created March 18, 2013 20:42
Show source of a PHP file its .txt extension if it exists.
<?php
# Show source of this file in .txt extension if it exists
call_user_func(function() {
$txt = __FILE__ . '.txt';
if ( ! file_exists($txt))
return;
# update (cache at least 5-min)
if (300 < time() - filemtime($txt))
file_put_contents($txt, file_get_contents(__FILE__));
@ryanve
ryanve / untabulate.css
Created April 25, 2013 05:41
Use .untabulate as a state helper for converting tables to a mobile-friendlier view.
table.untabulate,
.untabulate table,
.untabulate thead,
.untabulate tbody,
.untabulate tfoot,
.untabulate th,
.untabulate td,
.untabulate tr { display:block; }
.untabulate tr + tr { margin-top:1em; }
@ryanve
ryanve / data.php
Created May 24, 2013 19:29
PHP data function to get/set data stored in private static hash.
<?php
namespace demo;
/**
* Get or set data.
* @param mixed $key
* @param mixed $val
* @return mixed
*/
function data($key = null, $val = null) {
@ryanve
ryanve / a.current.js
Last active December 7, 2016 11:58
Add `.current` class to anchors that link to the current URL.
//gist.github.com/ryanve/6153436
(function(anchors, url, i, a) {
while ((a = anchors[i++]) && a.classList)
a.href === url && a.classList.add('current');
}(document.getElementsByTagName('a'), location.href, 0));
@ryanve
ryanve / show-jumps.css
Created August 12, 2013 15:24
Use this CSS to display the target of jumps in figures. It is designed for use with images wrapped in jump anchors.
figure[id] > a[href^="#"]:after {
content:attr(href); display:table;
position:relative; top:-1.4em; bottom:-1.4em;
font-weight:bold; text-decoration:none;
line-height:1; padding:.2em; margin-bottom:-1.4em;
background:#fff; color:#222;
}
@ryanve
ryanve / placeholder.css
Created November 21, 2013 13:08
CSS rules to style [placeholder] text
::-webkit-input-placeholder { color:inherit; }
:-moz-placeholder { color:inherit; } /* FF 4-18 */
::-moz-placeholder { color:inherit; } /* FF 19+ */
:-ms-input-placeholder { color:inherit; } /* IE 10+ */
@ryanve
ryanve / breakpoint.js
Last active January 17, 2020 17:20
JavaScript: Get the current media query breakpoint for a CSS feature.
(function(root, name, make) {
if (typeof module != 'undefined' && module['exports']) module['exports'] = make();
else root[name] = make();
}(this, 'breakpoint', function() {
/**
* @link http://gist.github.com/ryanve/7924792
* @param {string} feature range feature name e.g. "width"
* @param {string=} unit CSS unit for feature e.g. "em"
* @param {number=} init initial guess
@ryanve
ryanve / solo.js
Last active August 29, 2015 13:55
Play only one track at a time. When one track plays, pause the rest.
// gist.github.com/ryanve/8703402
// Play only one track at a time.
(function(doc, tags) {
var listen = 'addEventListener', some = tags.some, pause = function(e) {
this !== e && !this.ended && !this.paused && !e.ended && !e.paused && e.pause();
};
some && listen in doc && tags.some(function(tag) {
var live = doc.getElementsByTagName(tag), solo = function() {
some.call(live, pause, this);
};
@ryanve
ryanve / .gitconfig
Last active May 11, 2022 09:17
git aliases
[alias]
co = checkout
ci = commit
ca = commit --amend
cia = commit -a
can = commit --amend --no-edit
com = checkout master
st = status
s = status --short
b = branch
@ryanve
ryanve / log-tab-focus.js
Last active May 24, 2019 21:50
Log :focus element each time tab key is pressed
document.addEventListener('keyup', function(e) {
9 != e.keyCode || e.metaKey || e.ctrlKey || console.log(document.activeElement)
}, false)