Skip to content

Instantly share code, notes, and snippets.

@arsonus
arsonus / matchMedia.js
Created February 6, 2018 21:23 — forked from jonathantneal/matchMedia.js
window.matchMedia + addListener/removeListener for all browsers
if (!this.matchMedia) {
(function (WINDOW, LISTENER) {
function evalQuery(window, query) {
var
screen = window.screen,
screenHeight = screen.height,
screenWidth = screen.width,
documentElement = window.document.documentElement,
height = window.innerHeight || documentElement.clientHeight,
width = window.innerWidth || documentElement.clientWidth,
@arsonus
arsonus / Interval.js
Last active February 6, 2018 21:25 — forked from jonathantneal/Interval.js
A JavaScript Interval library that can play precisely timed intervals, and includes its own easing helpers.
(function () {
'use strict';
function Interval(listener, duration, speed) {
var self = this;
self.duration = duration;
self.listener = listener;
self.speed = speed;
@arsonus
arsonus / README.md
Created February 6, 2018 21:26 — forked from jonathantneal/README.md
Parsing Social Media URLs

Parsing Social URLs

Match a variety of social media urls, detect their medium, and collect their single-most important ID.

{
	dailymotion: /https?:\/\/(?:www\.)?dailymotion\.com\/(swf|video)\/([^\/?&]+)/,
	googlemaps: /(^https?\:\/\/maps\.google\.com.+)/,
	googleplus: /https?:\/\/(?:plus\.google\.com|gplus\.to)\/([^\/?&]+)/,
	flickr: /https?:\/\/(?:www\.)?flickr\.com\/(?:people|photos)\/(\d+@N\d+)/,
@arsonus
arsonus / Image.prototype.barcode.js
Created February 6, 2018 21:28 — forked from jonathantneal/Image.prototype.barcode.js
Read barcodes from an image
// Image.prototype.barcode
(function () {
'use strict';
var UPC_SET = {
'3211': '0',
'2221': '1',
'2122': '2',
'1411': '3',
'1132': '4',
@arsonus
arsonus / mimetypes.json
Created February 6, 2018 21:30 — forked from jonathantneal/mimetypes.json
Mime Types JSON
{
"audio/mp4": "m4a|f4a|f4b",
"audio/ogg": "oga|ogg",
"audio/&": "mid|midi|mp3|wav",
"application/javascript": "js|jsonp",
"application/json": "json",
"application/msword": "doc|dot",
"application/octet-stream": "bin",
"application/postscript": "ai",
"application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
@arsonus
arsonus / vendorlessStyle.js
Created February 6, 2018 21:53 — forked from jonathantneal/vendorlessStyle.js
vendorlessStyle // allows DOM elements to support vendorless properties
this.CSSStyleDeclaration && function (CSSStyleDeclarationPrototype, defaultStyles, defaultProperty, specialProperty) {
for (defaultProperty in defaultStyles) {
specialProperty = defaultProperty.match(/^(O|Moz|ms|webkit)([A-Z])(.*)$/);
specialProperty && function (defaultProperty, genericProperty) {
Object.defineProperty(CSSStyleDeclarationPrototype, genericProperty, {
get: function () {
return this[defaultProperty];
},
set: function (value) {
@arsonus
arsonus / Object.getClass.js
Created February 6, 2018 21:55 — forked from jonathantneal/Object.getClass.js
Object.getClass // returns the class name of an object
Object.getClass = function (object) {
return object === undefined ? "Undefined"
: object === null ? "Null"
: (String.toString.call(object.constructor || object).match(/\s\w+/) || [" Function"])[0].slice(1);
};
@arsonus
arsonus / matchMedia.js
Created February 6, 2018 22:01 — forked from jonathantneal/matchMedia.js
Match Media
(function (window, screen, documentElement) {
/* ======================================================================
Setup
====================================================================== */
var hasEventListener = ('addEventListener' in window);
var hasOrientation = ('orientation' in window);
var hasGetComputedStyle = ('getComputedStyle' in window);
var regexpTrim = /^\s+|\s+$/g;
@arsonus
arsonus / cross-browser-text-selection.js
Created February 6, 2018 22:02 — forked from jonathantneal/cross-browser-text-selection.js
cross-browser-text-selection.js
(function (win, doc) {
function getRangeAtCollapse(range, collapsed) {
// get range as item
if (range.item) {
var rangeItem = range.item(0);
// return the data
return { node: rangeItem };
}
// get range as text
var
@arsonus
arsonus / _magic-methods.md
Created June 9, 2018 01:54 — forked from loilo/magic-methods.js
PHP Magic Methods in JavaScript

JavaScript Magic Methods

This script implements some of PHP's magic methods for JavaScript classes, using a Proxy.

Example

You can use it like this:

const Foo = magicMethods(class Foo {
  constructor () {
    this.bar = 'Bar'
  }