This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
function Interval(listener, duration, speed) { | |
var self = this; | |
self.duration = duration; | |
self.listener = listener; | |
self.speed = speed; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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--) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
|-------------------------------------------------------------------------- | |
| Return a Collection of Objects | |
|-------------------------------------------------------------------------- | |
*/ | |
// collection of all users | |
$sql = "select * from users"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 + '[^&]*'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class TimeoutException extends RuntimeException {} | |
class Timeout | |
{ | |
private $active; | |
public function set($seconds) | |
{ |