Skip to content

Instantly share code, notes, and snippets.

@MeyCry
MeyCry / ObjectArray.js
Last active October 15, 2018 15:59
ObjectArray =))
class ObjectArray extends Object {
/**
* @param {Object} obj
*/
constructor(obj = {}) {
super();
this.length = 0;
const keys = Object.keys(obj);
keys.forEach((key) => {
this.length += 1;
@MeyCry
MeyCry / js
Created August 17, 2018 17:09
time in millisecond
// time const in millisecond
export const SECOND = 1000;
export const MINUTE = 60 * SECOND; // 60 000
export const HOUR = 60 * MINUTE; // 3 600 000
export const DAY = 24 * HOUR; // 86 400 000
export const WEEK = 7 * DAY; // 604 800 000
// export const YEAR = 365 * DAY; // 31 536 000 000
export const YEAR = 365.25 * DAY; // 31 557 600 000
@MeyCry
MeyCry / getUrlParameter.js
Last active August 10, 2018 15:00
get get param from url
function getUrlParameter(param) {
var pageUrl = decodeURIComponent(window.location.search.substring(1)),
urlVariables = pageUrl.split('&'),
parameterName,
i;
for (i = 0; i < urlVariables.length; i++) {
parameterName = urlVariables[i].split('=');
if (parameterName[0] === param) {
/**
* @example for (let {key, val} of listeners) { console.log("2", key, val); }
*/
const listeners = {};
listeners[Symbol.iterator] = function () {
const keys = Object.keys(this);
const self = this;
var current = 0;
var last = keys.length;
var OnScroll = (function () {
function OnScroll(config) {
if (!config) {
config = {}
}
this.listeners = [];
this.timeout = config.timeout || 300;
var handler = _scrollHandler.bind(this);
if (window.addEventListener) {
@MeyCry
MeyCry / schema-org-structured-data-markup-using-microdata.html
Created April 24, 2018 11:13 — forked from milanaryal/schema-org-structured-data-markup-using-microdata.html
An example of how to mark up a HTML5 webpage using the schema.org schemas and microdata.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Site Title</title>
<link rel="stylesheet" href="/assets/css/style.min.css">
// https://stackoverflow.com/questions/9260501/html5-video-background-on-ipad-iphone
var cvpHandlers = {
canvasClickHandler: null,
videoTimeUpdateHandler: null,
videoCanPlayHandler: null,
windowResizeHandler: null
};
var CanvasVideoPlayer = function(options) {
var initialFirst = 0;
var initialLast = 1;
var index = 0;
var calcFib = function selfCall (num) {
if (num < 1) return;
index++;
var result = initialFirst + initialLast;
initialFirst = initialLast;
initialLast = result;
category = [
{id: "animals", parent: null}
{id: "mammals", parent: "animals"}
{id: "cats", parent: "mammals"}
{id: "dogs", parent: "mammals"}
{id: "alliance", parent: null}
{id: "labrador", parent: "dogs"}
{id: "chihuahua", parent: "dogs"}
{id: "siamese", parent: "cats"}
{id: "persian", parent: "cats"}
_appsHash = {}
_appsArr = []
getAll = -> _appsArr
getAppById = (appId) -> _appsHash[appId]
_fetch = (apps) ->
appsHash = {}
_appsArr = apps.map (item) ->
appsHash[item.id] = _appsHash[item.id] or assign({}, item)