Skip to content

Instantly share code, notes, and snippets.

View c3ry5's full-sized avatar

Cerys Williams c3ry5

  • London, United Kingdom
View GitHub Profile
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 / 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 / getVideoId.js
Last active November 3, 2020 10:53
Regex Map/loop for getting the video id from youtube, vimeo, vine and instagram
getVideoId = {
siteMap : {
"youtube" : {
r : /(youtu\.be\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v)\/))([^\?&"'>]+)/,
id : 5
},
"vimeo" : {
r : /https?:\/\/(?:www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)/,
id : 3
},
body {
background: #000;
}
.countdown {
background: #000;
color: #fff;
display: table;
margin: 0 auto;
text-align: center;
font-family: arial;
@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 / 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 / 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 / aem.cq.getRequest.js
Last active March 15, 2023 04:39
Get request using the AEM sightly Javascript use api
"use strict";
use(function() {
var url = this.api,
getRequest = new org.apache.commons.httpclient.methods.GetMethod(url),
client = new org.apache.commons.httpclient.HttpClient(),
status = new org.apache.commons.httpclient.HttpStatus(),
inputStream;
console.log("Retrieving data from " + url);
try {
var statusCode = client.executeMethod(getRequest);