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 /
Last active September 12, 2023 22:20
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):

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:

ahmed-musallam /
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:
# name of your master icon, must be at least 512X512
ahmed-musallam / Circular.js
Created January 25, 2018 22:11
A simple circular javascript data structure (backed by an array)
View Circular.js
* A simple circular data structure
function Circular(arr, startIntex){
this.arr = arr;
this.currentIndex = startIntex || 0;
} = function(){
var i = this.currentIndex, arr = this.arr;
package com.ahmedmusallam.service;
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;
View EstimatePathSize.groovy
// this code is the same as the servlet but for grovy console:
def PATH = '/content/dam/'
def query = createQuery([path:PATH, type:'nt:file', 'p.limit':'99999999999999999'])
def result = query.getResult();
long totalSizeInKB = 0
def node = it.node
ahmed-musallam /
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
View poll.js
// 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 / console.html
Created December 11, 2017 19:34
A simple browser console-like html setup
View console.html
I use this setup primarely on jsfiddle where I do not want to open chrome console while testing js code.
<!-- a Mono-spaced font-->
<link href="" rel="stylesheet">
ul#console {
list-style-type: none;
ahmed-musallam /
Created April 11, 2018 19:45
A script to install all packages in a folder to the AEM instance at 4502
# this script will install ALL zip packages in current directory the AEM instance at 4502
for f in *.zip
echo "installing: $f"
curl -u admin:admin -F file=@"$f" -F name="$f" -F force=true -F install=true http://localhost:4502/crx/packmgr/service.jsp
echo "done."
ahmed-musallam / DnDInteraction.js
Created February 20, 2017 22:58
How to Create ‘Drag and Drop’ Experiences for AEM authors
View DnDInteraction.js
/* 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 && && && {
// selector of element we want to drag
var DRAGGABLE_SELECTOR = '.cq-draggable.card-asset',