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 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 / 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 / AEM_SAX_PARSER_ERRORS.md
Last active October 30, 2023 19:29
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 / 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
@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!

// poll async featch calls in a syncronized fashion, IE do not start the next function call until the previous was resolved.
// also allows for throttling :)
async function poll(fn, onData, throttle) {
const _throttle = throttle || 5000;
let lastPollStarted;
async function _poll(_fn, _onData) {
lastPollStarted = new Date().getTime();
let response = await _fn();
if (response.status === 200) {
// Get and show the message
@ahmed-musallam
ahmed-musallam / console.html
Created December 11, 2017 19:34
A simple browser console-like html setup
<!--
I use this setup primarely on jsfiddle where I do not want to open chrome console while testing js code.
example: https://jsfiddle.net/wybmxgop/1/
-->
<!-- a Mono-spaced font-->
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
<style>
ul#console {
list-style-type: none;