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
ahmed-musallam / extractAEMGraniteUIwidget doc .js
Created July 20, 2017 02:45
A snippet to extract AEM Granite UI widget doc as json
// you can run this code in chrome on this link for example: https://docs.adobe.com/docs/en/aem/6-2/develop/ref/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/checkbox/index.html
// 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
ahmed-musallam / SQL2-Query-Samples.md
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'

SELECT 
   p.* FROM [nt:unstructured] AS p 
WHERE 
 ISDESCENDANTNODE('/') 
@ahmed-musallam
ahmed-musallam / showFiles.sh
Created January 2, 2018 18:44
See how many files each pid is opening in macOs
# based on https://www.reddit.com/r/osx/comments/3ewn93/too_many_open_files_in_system_what_is_causing_this/ctj765h/
# 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
ahmed-musallam / usage.js
Created January 16, 2018 17:45
Wait for a javascript namespace to become available, with timeout!
// in this example, we wait for jquery to become available.
waitFor("$",1000*60,function(){
console.log('jQuery is ready to be used!');
})
@ahmed-musallam
ahmed-musallam / multifield.css
Last active January 23, 2018 19:52
Multifield example with bootstrap and jquery ui, see it here: https://jsfiddle.net/bdrp0eow/
.multifield form {
margin: 0 auto;
max-width: 750px;
}
.multifield .margin-1rem {
margin: 1rem !important;
}
.multifield .fieldset-container {
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
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
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
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
/**
* 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: http://jsfiddle.net/ahmedmusallam/jruxn3bh/
*/
(function () {
/**
* @param {Arrray} predicates: an array of predicates
@ahmed-musallam
ahmed-musallam / export-namespaces.groovy
Last active August 1, 2018 23:09
Import/Export namespaces from/to AEM instances
import com.google.gson.JsonArray
import com.google.gson.JsonObject
/**
* 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"}
*
*/
/**
Decodes asset names if they contain any encoded chars.
*/
import java.net.URLDecoder
START = "/content/dam"
// renames a node
def renameToDecoded(node)