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 / DnDInteraction.js
Created February 20, 2017 22:58
How to Create ‘Drag and Drop’ Experiences for AEM authors
/* JsLint ignore Granite object from validation */
/* globals Granite*/
//define new interaction for dropping assets into fields, this wil copy the Asset's path into the field
var customePathbrowserInteraction;
(function (Granite, $) {
if (Granite && Granite.author && Granite.author.ui && Granite.author.ui.Interaction) {
// selector of element we want to drag
var DRAGGABLE_SELECTOR = '.cq-draggable.card-asset',
@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 / EventUtil.ts
Last active December 19, 2023 13:59
A typescript version of the Tiny Pub/Sub written by @cowboy here: https://gist.github.com/cowboy/661855
export class EventUtil
{
private static observable = $({});
/**
* Subscribe to an event
*/
public static subscribe = function(...args){
EventUtil.observable.on.apply(EventUtil.observable, args);
@ahmed-musallam
ahmed-musallam / compress_pdf.md
Last active March 10, 2024 13:53
How to compress PDF with ghostscript

How to compress PDF using ghostscript

As a developer, it bothers me when someone sends me a large pdf file compared to the number of pages. Recently, I recieved a 12MB scanned document for just one letter-sized page... so I got to googlin, like I usually do, and found ghostscript!

to learn more abot ghostscript (gs): https://www.ghostscript.com/

What we are interested in, is the gs command line tool, which provides many options for manipulating PDF, but we are interested in compressign those large PDF's into small yet legible documents.

credit goes to this answer on askubuntu forum: https://askubuntu.com/questions/3382/reduce-filesize-of-a-scanned-pdf/3387#3387?newreg=bceddef8bc334e5b88bbfd17a6e7c4f9

@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('/') 
// this code is the same as the servlet but for grovy console: https://github.com/OlsonDigital/aem-groovy-console
// OPTIONS
def PATH = '/content/dam/'
def query = createQuery([path:PATH, type:'nt:file', 'p.limit':'99999999999999999'])
def result = query.getResult();
long totalSizeInKB = 0
result.getHits().each{
def node = it.node
@ahmed-musallam
ahmed-musallam / README.md
Last active January 29, 2020 16:48
A simple groovy console script to find AEM pages with a certain template then display them in a nice table

A simple groovy console script to find AEM pages with a certain template then display them in a nice table

copy script to AEM groovy console, change parameters and run!

@ahmed-musallam
ahmed-musallam / README.md
Last active December 1, 2020 23:10
A simple local playground for mustache template (jsfiddle style)

A simple local playground for mustache template (jsfiddle style)

download mustache-playground.html and open with a browser tested only on chrome

you can now use in on my site: http://ahmedmusallam.com/mustache.html

Purpose:

quick templating for strings/html. Made to create multiple templates on the fly for repetitive jira ticket discriptions.

@ahmed-musallam
ahmed-musallam / README.md
Last active March 3, 2022 01:05
A simple groovy console script to find AEM pages with a certain component then display them in a nice table

A simple groovy console script to find AEM pages with a certain component then display them in a nice table

Copy script to AEM groovy console, change parameters and run!

@ahmed-musallam
ahmed-musallam / README.md
Created November 13, 2017 20:14
A ChartJs plugin to add offset to chart's min/max on the y axes

A ChartJs plugin to add offset to chart's min/max on the y axes

Take a look at this SF question for more details, see my answer.

how to use:

  1. Add code after chartjs code
  2. In chartsjs options set options.customOffset to any number you want to offset the chart