Skip to content

Instantly share code, notes, and snippets.

Avatar

Ahmed Musallam ahmed-musallam

View GitHub Profile
@ahmed-musallam
ahmed-musallam / generate-icns.sh
Created Feb 24, 2020
A Shell script to generate .ico and .icns files (mac/windows app icons) from a single PNG
View generate-icns.sh
# 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
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
View device-detector.js
/***
*
* a trimmed down version (~812 bytes minified, not gzipped) of: https://github.com/matthewhudson/current-device/blob/master/src/index.js
* to determine current device is mobile, tablet or desktop
* USAGE:
* 1. prebuilt property: `window.device.type` returns "mobile", "tablet" or "desktop"
* 2. could call `window.device.mobile()` or `window.device.tablet()` or `window.device.desktop()` to check for each
* 3. other methods such as `window.device.windows()`, `window.device.windowsPhone()`, `window.device.android()`, `window.device.blackberry()`
*/
@ahmed-musallam
ahmed-musallam / exportNameSpaceCND.js
Created Apr 11, 2019
The hackiest way to export/import namespaces between AEM instances without any external dependencies
View exportNameSpaceCND.js
/**
* 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 / ComponentPropertyUpdater.java
Created Mar 19, 2019
An ACS MCP that helps in updating one component property in bulk
View ComponentPropertyUpdater.java
package com.mycom.core.mcp;
import com.adobe.acs.commons.fam.ActionManager;
import com.adobe.acs.commons.mcp.ProcessDefinition;
import com.adobe.acs.commons.mcp.ProcessInstance;
import com.adobe.acs.commons.mcp.form.CheckboxComponent;
import com.adobe.acs.commons.mcp.form.FormField;
import com.adobe.acs.commons.mcp.form.PathfieldComponent;
import com.adobe.acs.commons.mcp.model.GenericReport;
import java.io.Serializable;
View decodeAssetNames.groovy
/**
Decodes asset names if they contain any encoded chars.
*/
import java.net.URLDecoder
START = "/content/dam"
// renames a node
def renameToDecoded(node)
View HttpClientService.java
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 / ArrayFilterWithPredicates.js
Last active Jun 23, 2018
A simple method to filter an array of objects based on predicates for strings
View ArrayFilterWithPredicates.js
/**
* 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 Aug 1, 2018
Import/Export namespaces from/to AEM instances
View export-namespaces.groovy
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"}
*
*/
@ahmed-musallam
ahmed-musallam / install-all-packages-in-current-folder.sh
Created Apr 11, 2018
A script to install all packages in a folder to the AEM instance at 4502
View install-all-packages-in-current-folder.sh
#!/bin/bash
# this script will install ALL zip packages in current directory the AEM instance at 4502
for f in *.zip
do
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."
done