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 / compress_pdf.md
Last active July 2, 2024 09:52
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 / AEM_SAX_PARSER_ERRORS.md
Last active May 14, 2024 11:53
org.apache.jackrabbit.vault.fs.impl.io.GenericArtifactHandler Error while parsing

How to fix AEM error org.apache.jackrabbit.vault.fs.impl.io.GenericArtifactHandler Error while parsing when deploying AEM package

I ran into this issue with one of the projects I was working on, AEM throws this very unhelpful error:

rg.apache.jackrabbit.vault.fs.impl.io.GenericArtifactHandler Error while parsing <path here>/.content.xml: {}
org.xml.sax.SAXException: null
	at org.apache.jackrabbit.vault.fs.impl.io.DocViewSAXImporter.startElement(DocViewSAXImporter.java:662)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:374)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2784)
@ahmed-musallam
ahmed-musallam / exportNameSpaceCND.js
Created April 11, 2019 23:59
The hackiest way to export/import namespaces between AEM instances without any external dependencies
/**
* EXPORT NAMESPACES
* 1. Open http://localhost:4502/crx/explorer/ui/namespace_editor.jsp
* 2. Open Chrome console, run script below
* 3. Copy result.
*/
/**
* IMPORT NAMESPACES
* 1. Open http://localhost:4502/crx/explorer/nodetypes/index.jsp
@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
@ahmed-musallam
ahmed-musallam / README.md
Last active May 14, 2024 11:51
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 / generate-icns.sh
Created February 24, 2020 15:42
A Shell script to generate .ico and .icns files (mac/windows app icons) from a single PNG
# Required deps:
# imagemagick: https://imagemagick.org/script/download.php
# name of your master icon, must be at least 512X512
PNG_MASTER="icon-large.png"
ICONSET_FOLDER="AppIcon.iconset"
sizes=(
16x16
32x32
@ahmed-musallam
ahmed-musallam / HttpClientService.java
Last active February 28, 2024 17:20
A simple HTTP server jUnit 5 extension based on https://gist.github.com/rponte/710d65dc3beb28d97655
package com.ahmedmusallam.service;
import java.io.IOException;
import java.net.URI;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
@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 / Circular.js
Created January 25, 2018 22:11
A simple circular javascript data structure (backed by an array)
/**
* A simple circular data structure
*/
function Circular(arr, startIntex){
this.arr = arr;
this.currentIndex = startIntex || 0;
}
Circular.prototype.next = function(){
var i = this.currentIndex, arr = this.arr;
// 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