Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / mediaquery.js
Created February 6, 2018 21:21 — forked from jonathantneal/mediaquery.js
Media Queries for everybody
(function () {
var
documentElement = document.documentElement,
viewportFontSize, viewportHeight, viewportIsPortrait, viewportMax, viewportMin, viewportWidth;
function getViewportFontSize() {
var
body = documentElement.appendChild(document.createElement('body')),
iframe = document.createElement('iframe'),
iframeDocument;
@arsonus
arsonus / Object.create.js
Created February 6, 2018 21:21 — forked from jonathantneal/Object.create.js
Object.create: useless extras edition
// Object.create
Object.create = function create(prototype, properties) {
var
isFunction = typeof prototype === 'function',
name = isFunction && Function.prototype.toString.call(prototype).match(/^function\s+(\w*)/)[1] || 'Object',
object;
if (!isFunction && typeof prototype !== 'object') {
throw new Error('Object prototype may only be an Object or null');
}
@arsonus
arsonus / scrollTop.js
Created November 24, 2017 01:17 — forked from alizhdanov/scrollTop.js
pure javascript scrollTop function
function scrollTo(element, to, duration) {
if (duration < 0) return;
var difference = to - element.scrollTop;
var perTick = difference / duration * 2;
setTimeout(function() {
element.scrollTop = element.scrollTop + perTick;
scrollTo(element, to, duration - 2);
}, 10);
}
// takes the form field value and returns true on valid number
function valid_credit_card(value) {
// accept only digits, dashes or spaces
if (/[^0-9-\s]+/.test(value)) return false;
// The Luhn Algorithm. It's so pretty.
var nCheck = 0, nDigit = 0, bEven = false;
value = value.replace(/\D/g, "");
for (var n = value.length - 1; n >= 0; n--) {
<?php
/*
|--------------------------------------------------------------------------
| Return a Collection of Objects
|--------------------------------------------------------------------------
*/
// collection of all users
$sql = "select * from users";
@arsonus
arsonus / gist:7724667345d1b26aa17bb7e906803494
Created November 1, 2017 00:55 — forked from BastinRobin/gist:0cca0e267408e361062a8681d0cc556d
Javacript: Set or Update a URL/QueryString Parameter, and update URL using HTML history.replaceState()
// Explicitly save/update a url parameter using HTML5's replaceState().
function updateQueryStringParam(param, value) {
baseUrl = [location.protocol, '//', location.host, location.pathname].join('');
urlQueryString = document.location.search;
var newParam = key + '=' + value,
params = '?' + newParam;
// If the "search" string exists, then build params from it
if (urlQueryString) {
keyRegex = new RegExp('([\?&])' + key + '[^&]*');
@arsonus
arsonus / create-cluster
Created April 14, 2017 01:38 — forked from diegopacheco/create-cluster
Redis Create Cluster
#!/bin/bash
# Settings
PORT=30000
TIMEOUT=2000
NODES=3
REPLICAS=2
# You may want to put the above config parameters into config.sh in order to
# override the defaults without modifying this script.
@arsonus
arsonus / timeout.php
Created April 9, 2017 11:06 — forked from avalanche123/timeout.php
timeouts in php
<?php
class TimeoutException extends RuntimeException {}
class Timeout
{
private $active;
public function set($seconds)
{