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 / eventListener.js
Last active August 29, 2015 13:55
native js event listener
(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;
String.prototype.toCapitalize = function() {
return this.toLowerCase().replace(/^\.|\s\S/g, function(a) {
return a.toUpperCase();
});
};
fileList="
FILE 1 URL
FILE 2 URL
FILE 3 URL
ETC
"
for fileName in $fileList
do
echo "$fileName"
@c3ry5
c3ry5 / getMediaQuery.css
Created March 17, 2014 09:13
How to get the media query of your page
body #currentMediaQuery {
display: none;
}
@media only screen and max-width 479px {
body #currentMediaQuery {
font-family: xxs;
}
}
@c3ry5
c3ry5 / combineMediaQueriesAndSelectors.rb
Created March 31, 2014 21:27
compass callback to restructure css files on stylesheet saved
require 'fileutils'
on_stylesheet_saved do |filename|
fileContents = File.read filename
File.open(filename, 'w+') do |f|
mediaQueryObject = {}
regexMedia = /@media([^{]*){((?:(?!}\s*}).)*}.*?)}/xoim
regexSelector = /\s*([^{]*){(.*?)}/xoim
regexSpace = /\n+|\r+/xoim
bodyContents = fileContents.gsub(regexMedia,'')
mediaQueryArray = fileContents.scan(regexMedia)
@c3ry5
c3ry5 / cq.triggercallback.js
Last active August 29, 2015 14:10
An exjs trigger callback xtype for AEM/CQ
var triggerCallback = CQ.Ext.extend(CQ.Ext.form.TriggerField, {
initComponent: function() {
triggerCallback.superclass.initComponent.call(this)
},
triggerClass: "x-form-search-trigger",
onTriggerClick: function() {
if(this.callback) {
this.callback.call(this);
}
},
@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)
@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 / 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 / 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
};