Skip to content

Instantly share code, notes, and snippets.

View ahmed-musallam's full-sized avatar

Ahmed Musallam ahmed-musallam

View GitHub Profile
ahmed-musallam / extractAEMGraniteUIwidget doc .js
Created July 20, 2017 02:45
A snippet to extract AEM Granite UI widget doc as json
View extractAEMGraniteUIwidget doc .js
// you can run this code in chrome on this link for example:
// get textContent of child element based on selector
function getText(el, selector){
if(!el) return;
var childEl = el.querySelector(selector);
return childEl ? childEl.textContent : ""
$(".propertydef").each((a,p) =>
ahmed-musallam / EventUtil.ts
Last active August 31, 2017 06:29
A typescript version of the Tiny Pub/Sub written by @cowboy here:
View EventUtil.ts
export class EventUtil
private static observable = $({});
* Subscribe to an event
public static subscribe = function(...args){
EventUtil.observable.on.apply(EventUtil.observable, args);
ahmed-musallam /
Last active October 23, 2017 15:40
JCR SQL2 Query Samples

JCR SQL2 Query Samples

A collection of JCR SQL2 query examples

Nodes that have a non-empty property with name 'propName'

   p.* FROM [nt:unstructured] AS p 
ahmed-musallam /
Created January 2, 2018 18:44
See how many files each pid is opening in macOs
# based on
# will print a list of comma seperated enties, each entry is in this format: <PID name>, <PID>, <Files open>
sudo lsof -n | perl -pe '$x = <>; while(<>) { ($cmd, $pid, $rest) = split(/\s+/); $cmds{$pid} = $cmd; $pids{$pid}++;} while( ($key, $val) = each %pids) { $pidName=$cmds{$key}; printf "$pidName,$key,$val \n" } ;'
ahmed-musallam / usage.js
Created January 16, 2018 17:45
Wait for a javascript namespace to become available, with timeout!
View usage.js
// in this example, we wait for jquery to become available.
console.log('jQuery is ready to be used!');
ahmed-musallam / multifield.css
Last active January 23, 2018 19:52
Multifield example with bootstrap and jquery ui, see it here:
View multifield.css
.multifield form {
margin: 0 auto;
max-width: 750px;
.multifield .margin-1rem {
margin: 1rem !important;
.multifield .fieldset-container {
View property-constraint-violation-checker.groovy
import javax.jcr.PropertyType
* This script will find all PropertyDifinitions for a node instance from it's primaryType and mixins
* It will then determine if any of the current properties violate any of the PropertyDifinitions. it only checks property name and type.
* For example, a "dam:Asset" node with a property "test" and a property "jcr:mixinTypes" of Type Reference has two violations:
* 1. "test" is not on the list of allowed properties for that node type
* 2. "jcr:mixinTypes" must be of type "Name"
ahmed-musallam / findUnregisteredNamespacePrefixes.groovy
Last active April 12, 2018 18:39
An AEM groovy console script to find all unregistered namespace prefixes in JCR subtree
View findUnregisteredNamespacePrefixes.groovy
def BASE_PATH = '/content/test' // CHANGE the path to search in
// BE CAREFUL! this may have performance implecations on large trees
// start with a deep tree and work your way up.
* Recurses over all nodes in the subtree "basePath"
* and checks every property of every node for prefixes that are not registered
* @returns an array or unregistered prefixes
ahmed-musallam / ArrayFilterWithPredicates.js
Last active June 23, 2018 14:44
A simple method to filter an array of objects based on predicates for strings
View ArrayFilterWithPredicates.js
* Built this to filters a large array based on predicates to use with a Vuejs app I was building.
* It provides a declarative way to filter an array of objects whose properties are strings.
* But it can be adapted and improved for other types.
* you can see an example vuejs app that uses this method here:
(function () {
* @param {Arrray} predicates: an array of predicates
ahmed-musallam / export-namespaces.groovy
Last active August 1, 2018 23:09
Import/Export namespaces from/to AEM instances
View export-namespaces.groovy
* This script will print a JSON array of all namespaces on current AEM instance
* Each JSON object in the array will be of the format:
* {"prefix":"The namespace prefix", "uri":"The namespace uri"}