Skip to content

Instantly share code, notes, and snippets.

View a-blank-slate's full-sized avatar
🎯
Focusing

Ashish Mishra a-blank-slate

🎯
Focusing
View GitHub Profile
@a-blank-slate
a-blank-slate / AddReppolicy.groovy
Created September 21, 2023 14:57
Groovy script to add rep policy for the results pulled in from xpath query
import org.apache.jackrabbit.api.JackrabbitSession;
import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
import org.apache.jackrabbit.api.security.principal.PrincipalManager;
import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
import javax.jcr.*;
def queryManager = session.workspace.queryManager;
def statement = "/jcr:root/content/geeksdemo//*[(jcr:content/@cq:template = '/conf/geeksdemo/settings/wcm/templates/page')]"
def query = queryManager.createQuery(statement, 'xpath')
final def result = query.execute()
@a-blank-slate
a-blank-slate / iterm2-solarized.md
Created February 27, 2023 12:40 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

@a-blank-slate
a-blank-slate / FindComponentUsingSQL2.java
Last active July 30, 2022 08:13
Servlet which uses sql2 query and finds all the component with the given resource type under a path in AEM
package com.colorful.core.servlets;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
@a-blank-slate
a-blank-slate / csv-reader.js
Created July 12, 2022 17:14
Small script to read csv file using csv-parser and papaparse libraries
const csv = require('csv-parser');
const fs = require('fs');
const papa = require('papaparse');
const file = fs.createReadStream('results.csv');
//using csv-parser
const results = [];
file
.pipe(csv())
.on('data', (data) => results.push(data))
@a-blank-slate
a-blank-slate / S3DataInsert.java
Created June 18, 2022 06:34
This utility puts the data in s3 bucket and also list down the data inside bucket.
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.BasicSessionCredentials;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.ObjectListing;
import com.amazonaws.services.s3.model.ObjectMetadata;
@a-blank-slate
a-blank-slate / ContentFragmentActor.java
Created May 15, 2022 06:46
These can be used to search for a specific or list of fragments and then map them to fragment model for returning json in servlet response. we ca also use child fragment list to iterate for child resources
package fragmentexamples.core.models;
import com.adobe.cq.dam.cfm.ContentFragment;
import com.adobe.cq.dam.cfm.ContentElement;
import com.adobe.cq.dam.cfm.FragmentTemplate;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.commons.lang.StringUtils;
import java.util.Optional;
import org.apache.sling.models.annotations.Model;
@a-blank-slate
a-blank-slate / docker-compose.yml
Created April 17, 2022 11:42
Use this to run wordpress locally on a Mac, paste this code in a docker-compose.yml file and then run docker-compose up -d
version: "3.9"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: dbpassword
@a-blank-slate
a-blank-slate / ssl-setup-guide.txt
Created April 4, 2022 05:52
Steps to follow for SSL Cloudflare origin server setup in Wordpress powered by bitnami
Download the Cloudflare origin server certificate and save them as Origin Certificate: server.crt and Private Key: server.key
Also download cloudflare CA certificate and save it as Cloudflare.pem
Open SSH connection then
cd /opt/bitnami/apache2/conf/bitnami/certs
Rename Exisitng certs to server.crt_legacy and server.key_legacy
sudo mv server.crt server.crt_legacy
sudo mv server.key server.key_legacy
@a-blank-slate
a-blank-slate / post-count-wp.php
Created April 2, 2022 16:25
This plugin uses Wordpress popular posts method to generate Page View Count via Wordpress Rest API
<?php
/**
* Plugin Name: Post View Count API
* Plugin URI: https://thecolorfulslate.com
* Description: Uses Wordpress post popular plugin to generate the result as JSON via Rest Endpoint.
* Version: 1.0
* Author: Ashish Mishra
* Author URI: https://thecolorfulslate.com
*/
@a-blank-slate
a-blank-slate / CheckDuplicateComponents.html
Created November 24, 2021 06:28
AEM Component which can be only used once in a parsys. Also sightly file is there with alert modal, if someone drops twice. the second component will be removed automatically. resource iterator is all added below
<sly data-sly-test="${wcmmode.edit && !resource.listChildren}">
<div class="cq-placeholder cq-marker-start" data-emptytext="Product Category Card"></div>
</sly>
<sly data-sly-test="${!properties.isThisFirst}">
<div data-sly-use.video="com.adobe.aem.guides.wknd.core.utility.CheckDuplicateComponents"></div>
<script>
alert('You can only use this component once, in this parsys!!!');
window.location.reload();
</script>