Skip to content

Instantly share code, notes, and snippets.

@ccac
ccac / back_forward.js
Created September 4, 2018 07:59 — forked from sstephenson/back_forward.js
How to detect whether a hash change came from the Back or Forward button
var detectBackOrForward = function(onBack, onForward) {
hashHistory = [window.location.hash];
historyLength = window.history.length;
return function() {
var hash = window.location.hash, length = window.history.length;
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
hashHistory = hashHistory.slice(0, -1);
onBack();
@ccac
ccac / .block
Created March 13, 2018 02:51 — forked from nbremer/.block
D3.js - Radar Chart or Spider Chart - Adjusted from radar-chart-d3
height: 650
license: mit
@ccac
ccac / gist:6e12fcaff000acdb9fdd05fa887afebb
Created February 2, 2018 12:35 — forked from musubu/gist:2596655
Java Regex for ISO8601
^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$
// Match
2009-12T12:34
2009
2009-05-19
2009-05-19
20090519
2009123
@ccac
ccac / disableBodyScroll.js
Created January 11, 2018 06:11 — forked from thuijssoon/disableBodyScroll.js
iOS disable body scroll
/**
* Prevent body scroll and overscroll.
* Tested on mac, iOS chrome / Safari, Android Chrome.
*
* Based on: https://benfrain.com/preventing-body-scroll-for-modals-in-ios/
* https://stackoverflow.com/a/41601290
*
* Use in combination with:
* html, body {overflow: hidden;}
*
@ccac
ccac / ImageTools.es6
Created September 7, 2017 07:54 — forked from dcollien/ImageTools.es6
Resize Images in the Browser
let hasBlobConstructor = typeof(Blob) !== 'undefined' && (function () {
try {
return Boolean(new Blob());
} catch (e) {
return false;
}
}());
let hasArrayBufferViewSupport = hasBlobConstructor && typeof(Uint8Array) !== 'undefined' && (function () {
try {
@ccac
ccac / ImageTools.es6
Created September 7, 2017 07:54 — forked from dcollien/ImageTools.es6
Resize Images in the Browser
let hasBlobConstructor = typeof(Blob) !== 'undefined' && (function () {
try {
return Boolean(new Blob());
} catch (e) {
return false;
}
}());
let hasArrayBufferViewSupport = hasBlobConstructor && typeof(Uint8Array) !== 'undefined' && (function () {
try {
@ccac
ccac / Enhance.js
Created June 26, 2017 10:30 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@ccac
ccac / blogServiceWorker.js
Created June 6, 2017 12:00 — forked from adactio/blogServiceWorker.js
A Service Worker to progressively enhance a blog by storing assets in a cache, and keeping limited caches of pages and images for offline browsing.
'use strict';
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function() {
// A cache for core files like CSS and JavaScript
var staticCacheName = 'static';
// A cache for pages to store for offline
@ccac
ccac / nginx_init_script_centos.sh
Created April 7, 2017 07:26 — forked from elvuel/nginx_init_script_centos.sh
nginx init script on centos
#!/bin/sh
# => /etc/init.d/nginx
# => sudo chmod +x /etc/init.d/nginx
# => make it start when the server run: /sbin/chkconfig nginx on
# => to check it: /sbin/chkconfig --list nginx
# nginx - this script starts and stops the nginx daemin
# Taken from http://www.hikaro.com
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
@ccac
ccac / bin2string.js
Created July 14, 2016 06:24 — forked from taterbase/bin2string.js
Convert bytes to string Javascript
function bin2string(array){
var result = "";
for(var i = 0; i < array.length; ++i){
result+= (String.fromCharCode(array[i]));
}
return result;
}