Skip to content

Instantly share code, notes, and snippets.

/**
* Reference and translate HTTP Status Codes
* Modified from: https://github.com/prettymuchbryce/node-http-status/blob/master/index.js
* Implemented according to:
* - http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
* - https://httpstatuses.com/
* - https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
* - http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpStatus.html
*
* @returns {Object} - HTTP Status Code constants and a method to translate status codes to a description
@Flygenring
Flygenring / sm-annotated.html
Created October 13, 2015 11:16 — forked from hdragomir/sm-annotated.html
The deferred font loading logic for Smashing Magazine. http://www.smashingmagazine.com/
<script type="text/javascript">
(function () {
"use strict";
// once cached, the css file is stored on the client forever unless
// the URL below is changed. Any change will invalidate the cache
var css_href = './index_files/web-fonts.css';
// a simple event handler wrapper
function on(el, ev, callback) {
if (el.addEventListener) {
el.addEventListener(ev, callback, false);
@Flygenring
Flygenring / MeTube.js
Created August 14, 2015 14:11
Script for a slightly improved full screen YouTube (prefix with 'javascript:' and it works as a magical bookmarklet)
url = window.location.href.replace(/(>|<)/gi,'').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/); if(url[2] !== undefined) { id = url[2].split(/[^0-9a-z_\-]/i)[0]; el = document.getElementsByTagName('html')[0]; el.style.height = "100%"; el.innerHTML = '<body style="width:100%;height:100%;padding:0;margin:0;"><iframe width="100%" height="100%" src="https://www.youtube.com/embed/' + id + '" frameborder="0" allowfullscreen></iframe></body>'; } else { alert('No video was found'); }
@Flygenring
Flygenring / apache_request_headers.php
Created November 26, 2014 18:07
A proper drop-in replacement for apache_request_headers() when that's not available
<?php
if(!function_exists('apache_request_headers')) {
///
function apache_request_headers() {
// Based on: http://www.iana.org/assignments/message-headers/message-headers.xml#perm-headers
$arrCasedHeaders = array(
// HTTP
'Dasl' => 'DASL',
'Dav' => 'DAV',
var id = window.setTimeout(function() {}, 0);
while(id--) {
window.clearTimeout(id);
};
var delay = 1000, // delay in ms
correction_24 = 255 / 24,
correction_60 = 255 / 60;
refreshData = function() {
var d = new Date()
@Flygenring
Flygenring / view-source.php
Last active December 24, 2015 01:59
Allowing view-source for a file on GET requests using a view-source parameter in the query string
<?php
// Allowing view-source on GET requests using a view-source parameter in the query string
if('GET' == $_SERVER['REQUEST_METHOD'] && array_key_exists('view-source', $_GET)) {
highlight_file(__FILE__);
die();
}
// Rest of the code...
@Flygenring
Flygenring / fibonacci.js
Created June 12, 2013 11:31
Just a quick thought on generating Fibonacci numbers
for(var f=[0,1], i=0; i<20; f[i+2]=f[i++]+f[i]);
@Flygenring
Flygenring / toResourceField.snippet.php
Last active March 28, 2022 21:47
MODX Snippet to get a field from a resource based on a supplied resource id, meant to be used as an output filter.
<?php
/**
* Gets a field from a resource based on a supplied resource id, meant to be used as an output filter.
*
* Based on a resource ID a field can be retrieved. This can be standard fields as 'pagetitle' or 'alias',
* but a few custom fields are also available; 'siblingNextId', 'childrenFirstId', and 'childrenCount'.
* Only resources that are not marked as 'deleted' or 'hidemenu', and that is marked as 'published' are returned.
* Examples:
* [[*id:toResourceField]] => returns the resource pagetitle
* [[*id:toResourceField=`alias`]] => returns the resource alias