Skip to content

Instantly share code, notes, and snippets.

@salcabar
salcabar / __file.js
Created November 9, 2016 12:04
__file.js
/**
* MAGIC GLOBALS
* https://github.com/gavinengel/magic-globals
*/
/** begin setting magic properties into global (required for other functions) */
Object.defineProperty(global, '__stack', {
get: function() {
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function(_, stack) {
@salcabar
salcabar / performance-timing.js
Created August 29, 2016 02:31
performance-timing
/*
* performance-timing.js 0.2
* https://github.com/tjuking/performance-timing
*/
(function (global, factory) {
"use strict";
if (typeof define === "function" && define.amd) {
.flex {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.flex.flex--reverse {
-webkit-box-orient: horizontal;
@salcabar
salcabar / naf.js
Created July 27, 2016 02:32 — forked from ThisIsMissEm/naf.js
requestNextAnimationFrame() and cancelNextAnimationFrame()
// requires raf.js (polyfil)
(function(){
var ids = {};
function requestId(){
var id;
while (!id || ids.hasOwnProperty(id)){
id = Math.floor(Math.random() * 1E9);
};
@salcabar
salcabar / 0_reuse_code.js
Created April 1, 2016 01:57
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@salcabar
salcabar / fake-autoplay-audio-ios-safari.html
Created December 23, 2015 04:40 — forked from ufologist/fake-autoplay-audio-ios-safari.html
Fake auto play html audio in iOS Safari the right way
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>Fake auto play html audio in iOS Safari the right way</title>
</head>
<body>
<h1>在 iOS Safari 中假装自动播放 HTML5 audio(音乐) 的正确方式</h1>
<p>核心原理: 通过一个用户交互事件来主动 play 一下 audio</p>
@salcabar
salcabar / autoplay-audio-ios.html
Created December 23, 2015 04:40 — forked from ufologist/autoplay-audio-ios.html
在 iOS 微信浏览器中自动播放 HTML5 audio(音乐) 的正确方式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>Auto play html audio in iOS WeChat InAppBrowser the right way</title>
</head>
<body>
<h1>在 iOS 微信浏览器中自动播放 HTML5 audio(音乐) 的正确方式</h1>
<p>核心原理: 在微信的JS-API 中 play 一下 audio 即可达到自动播放的目的(应该是微信自己做了处理)</p>
@salcabar
salcabar / consoleLine.js
Created October 9, 2015 07:04
打印行号
(function () {
if (Error.captureStackTrace && Object.defineProperty) {
var global = window;
Object.defineProperty(global, '__STACK__', {
get: function () {
var old = Error.prepareStackTrace;
Error.prepareStackTrace = function (error, stack) {
return stack;
function parseURL(url) {
var a = document.createElement('a');
a.href = url;
return {
source: url,
protocol: a.protocol.replace(':',''),
host: a.hostname,
port: a.port,
query: a.search,
params: (function(){
@salcabar
salcabar / protips.js
Last active August 29, 2015 14:24 — forked from nolanlawson/protips.js
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");