Skip to content

Instantly share code, notes, and snippets.

View c3ry5's full-sized avatar

Cerys Williams c3ry5

  • London, United Kingdom
View GitHub Profile
@c3ry5
c3ry5 / mergeObjects.es6.js
Last active November 4, 2018 11:24
Merging two js objects without jquery
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 / serialize.es6.js
Last active November 4, 2018 11:07
A script to serialize a form using native js - https://codepen.io/anon/pen/VVwopj
window.serialize = {
simple(form) {
const formel = document.querySelectorAll(form);
const inputs = formel[0].querySelectorAll("input, select, textarea");
const obj = {};
let key;
for (key in inputs) {
if (inputs[key].tagName) {
if (inputs[key].type === "checkbox") {
obj[inputs[key].name] = inputs[key].checked === true ? inputs[key].value : false;
@c3ry5
c3ry5 / gitflow-breakdown.md
Created December 8, 2017 13:36 — forked from JamesMGreene/gitflow-breakdown.md
A comparison of using `git flow` commands versus raw `git` commands.

Initialize

gitflow git
git flow init git init
  git commit --allow-empty -m "Initial commit"
  git checkout -b develop master

Connect to the remote repository

@c3ry5
c3ry5 / remove-geometrixx.sh
Created October 5, 2016 12:19 — forked from funkman/remove-geometrixx.sh
Remove all geometrixx (and other sample content) from AEM 6.2
#!/bin/sh
# UNINSTALL PACKAGES
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/adobe/aem6/sample/we.retail.download-1.0.8.zip?cmd=uninstall
sleep 2
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/adobe/aem6/sample/we.retail.download-1.0.8.zip?cmd=delete
sleep 2
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/aemfd/cq-geometrixx-gov-pkg-3.0.6.zip?cmd=uninstall
sleep 2
@c3ry5
c3ry5 / json.fix.js
Created August 5, 2015 12:12
A fix for malformed json
JSON.fix = function(obj) {
return obj.replace(/(['"])?([a-zA-Z0-9_]+)(['"])?:/g, '"$2": ');
};
@c3ry5
c3ry5 / detect-touch.js
Created June 18, 2013 15:18
To detect if i device supports touch events with a jquery scroll function
var isTouch = function () {
return 'ontouchend' in document;
}
@c3ry5
c3ry5 / helpers.checkUrl.js
Last active January 12, 2016 16:40
Url Validation
var checkUrl = function(url) {
var regex = new RegExp("(https?://(?:www.|(?!www))[^s.]+.[^s]{2,}|www.[^s]+.[^s]{2,})");
return url.match(regex) ? !0 : !1
};
@c3ry5
c3ry5 / web.sql.js
Last active December 19, 2015 19:49
Web sql setup using underscore js
(function () {
db = {};
db.map = {
'jobs': {
'create': {
'sql': 'CREATE TABLE "jobs" (id unique, json)'
},
'insert': {
'sql': 'INSERT INTO "jobs" (id, json) VALUES (?,?)'
@c3ry5
c3ry5 / backbone.replaceHash.js
Created July 5, 2013 10:25
override backbone.js _updateHash to replace location.replace for old devices with window.history.replaceState
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 / mixins.sass
Last active December 19, 2015 04:58
Retina sprite generation using 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)