Skip to content

Instantly share code, notes, and snippets.

Cerys Williams c3ry5

  • London, United Kingdom
Block or report user

Report or block c3ry5

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@c3ry5
c3ry5 / detect-webapp.js
Last active Nov 4, 2018
detect if the website has been saved as a webapp
View detect-webapp.js
const webappDetect = () => ("standalone" in window.navigator) && window.navigator.standalone;
@c3ry5
c3ry5 / ga-error-tracking.js
Last active Nov 4, 2018
crossbrowser tracking js errors using google analytics
View ga-error-tracking.js
window.onerror = (message, filename, lineno, colno, error) => {
function stack() {
return (`${(error.stack).replace(/(\r\n|\n|\r)/gm," ")} in ${navigator.userAgent}`)
}
function nostack() {
return (`${message} on line ${lineno} for ${filename} in ${navigator.userAgent}`)
}
@c3ry5
c3ry5 / detect-touch.js
Created Jun 18, 2013
To detect if i device supports touch events with a jquery scroll function
View detect-touch.js
var isTouch = function () {
return 'ontouchend' in document;
}
@c3ry5
c3ry5 / mixins.sass
Last active Dec 19, 2015
Retina sprite generation using sass
View mixins.sass
@mixin sprite-background($name)
background-repeat: no-repeat
background-image: $standardImg
background-position: sprite-position($sprites, $name)
height: image-height(sprite-file($sprites, $name))
width: image-width(sprite-file($sprites, $name))
@media (-webkit-min-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-device-pixel-ratio: 1.5)
background-image: $retinaImg
background-position: 0 round(nth(sprite-position($sprites2x, $name), 2) / 2)
height: round(image-height(sprite-file($sprites2x, $name)) / 2)
@c3ry5
c3ry5 / backbone.replaceHash.js
Created Jul 5, 2013
override backbone.js _updateHash to replace location.replace for old devices with window.history.replaceState
View backbone.replaceHash.js
var oldBrowser = (reContainsAll([/mozilla\/5.0/i, /android/i, /applewebkit/i], navigator.userAgent)
|| reContainsAll([/mozilla\/5.0/i, /iphone os (5|4|3|2|1){1}/i, /applewebkit/i], navigator.userAgent))
&& !reContainsAll([/chrome/i], navigator.userAgent);
Backbone.History.prototype._updateHash = function(location, fragment, replace) {
var base = location.toString().replace(/(javascript:|#).*$/, '') + '#';
if (replace) {
if (oldBrowser) {
window.history.replaceState({}, document.title, base + fragment);
} else {
@c3ry5
c3ry5 / read.cookie.js
Last active Nov 4, 2018
Read and write cookies
View read.cookie.js
@c3ry5
c3ry5 / web.sql.js
Last active Dec 19, 2015
Web sql setup using underscore js
View web.sql.js
(function () {
db = {};
db.map = {
'jobs': {
'create': {
'sql': 'CREATE TABLE "jobs" (id unique, json)'
},
'insert': {
'sql': 'INSERT INTO "jobs" (id, json) VALUES (?,?)'
@c3ry5
c3ry5 / mergeObjects.es6.js
Last active Nov 4, 2018
Merging two js objects without jquery
View mergeObjects.es6.js
Object.prototype.assign = Object.assign || function(obj1, obj2) {
var obj3 = obj1;
for (var attrname in obj2) {
if (typeof(obj2[attrname]) !== 'function') {
obj3[attrname] = obj2[attrname];
}
}
return obj3;
@c3ry5
c3ry5 / eventListener.js
Last active Aug 29, 2015
native js event listener
View eventListener.js
(function () {
'use strict';
var fo = window.fo = window.fo || {},
eventHandler = fo.eventHandler = fo.eventHandler || {};
eventHandler.events = {};
eventHandler.publish = function (event, data) {
var events = event.split(' '),
key, func;
View Capitalize.js
String.prototype.toCapitalize = function() {
return this.toLowerCase().replace(/^\.|\s\S/g, function(a) {
return a.toUpperCase();
});
};
You can’t perform that action at this time.