Skip to content

Instantly share code, notes, and snippets.

@joshkitt
joshkitt / gist:5164842
Created March 14, 2013 20:18
PDFBox - extract images
File file = new File("/tmp/pdf.pdf");
PDDocument doc = PdfTestUtils.getDocument(file);
PDDocumentCatalog catalog = doc.getDocumentCatalog();
PDPage page = (PDPage) catalog.getAllPages().get(0);
PDResources resources = page.getResources();
Map images = resources.getImages();
int i = 0;
for (Object o : images.keySet()) {
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="font">
<edit mode="assign" name="rgba">
<const>rgb</const>
</edit>
</match>
<match target="font">
<edit mode="assign" name="hinting">
@joshkitt
joshkitt / gist:da85e11e443a43bb7c37
Created November 20, 2014 16:35
Java - Ignore SSL Certificate
try {
SSLContext ctx = SSLContext.getInstance("SSL");
X509TrustManager tm = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
brew update && brew upgrade && brew cleanup
@joshkitt
joshkitt / alias.zsh
Created February 27, 2017 17:56
ZSH (Oh My Zsh) "custom" directory alias file
alias mvnq='mvn package -o -Dmaven.test.skip'
alias mvnx='f() { mvn $1 package -o -Dmaven.test.skip };f'
function binarySearch(data, search) {
// console.log("data", data);
var mid = Math.floor(data.length / 2);
// console.log('mid', mid)
if (data[mid] === search) {
// see if mid is what we're looking for
return data[mid];
} else if (data.length === 1) {
@joshkitt
joshkitt / gist:c674bffd5c9c6a47798a421be1c2b5b7
Created December 18, 2017 18:47
Combine multiple files into a single file (recursive)
find . -name '*.txt' -exec cat {} \; > all.txt
@joshkitt
joshkitt / SessionConfiguration.java
Last active July 15, 2019 16:25
Java Session Listener
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
@Configuration
public class SessionConfiguration {
@Bean
@joshkitt
joshkitt / aws-ec2-userdata.sh
Last active July 30, 2020 15:21
AWS EC2 User Data Example
#!/bin/bash
sudo su
yum update -y
yum install -y httpd
systemctl start httpd.service
systemctl enable httpd.service
EC2_AVAIL_ZONE=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
echo "<h1>Hello World from $(hostname -f) in AZ $EC2_AVAIL_ZONE </h1>" > /var/www/html/index.html
@joshkitt
joshkitt / AWS-VPC-NACL.md
Last active March 27, 2020 17:17
AWS VPC NACL firewall rules

Inbound

Rule # Type Protocol Port Range Destination Allow / Deny
100 HTTP (80) TCP (6) 80 0.0.0.0/0 ALLOW
110 HTTPS (443) TCP (6) 443 0.0.0.0/0 ALLOW
120 SSH (22) TCP (6) 22 < IP > ALLOW
130 Custom TCP Rule TCP (6) 32768 - 65535 0.0.0.0/0 ALLOW
* ALL Traffic ALL ALL 0.0.0.0/0 DENY