Skip to content

Instantly share code, notes, and snippets.

@sshongru
sshongru / stripAlphaChannelFromPNGs.sh
Last active June 11, 2024 13:01
Bash script to remove alpha channel from PNG files for submission to the Apple App Store
#!/bin/bash
echo ""
echo "----------"
echo "This bash script recursively goes through every PNG file in a given folder"
echo "and removes its alpha channel. This is useful for preparing PNG files for"
echo "uploading to Apple's iOS App Store."
echo ""
echo "You'll know you might need to use this script if you see this error coming"
echo "from Apple when you try to upload the images:"
@sshongru
sshongru / replaceMaintainingTokenIndentation.js
Last active August 29, 2015 14:02
HTML String replace that maintains the original whitespace indentation of the token in the template.
/*
* This function replaces the token string with the replacement string, but maintains
* the original whitespace indentation the token had within the template.
*
* For example if your template has:
*
* <div>
* {% TOKEN %}
* </div>
*
@sshongru
sshongru / saveGeneratedImages.sh
Created June 7, 2014 16:58
Save 30 images from the imageGenerator
#!/bin/sh
IMAGE_STRING="http://localhost/git/imageGenerator.php?w=200&h=200"
OUTPUT_EXTENSION="png"
INDEX=0
NUM_IMAGES=30
while [ "${INDEX}" != "${NUM_IMAGES}" ]
do
@sshongru
sshongru / imageGenerator.php
Created June 6, 2014 06:26
PHP Script that generates a JPG
<?php
//
// Creates a JPG of the given size and with the given text in
// the center.
//
// parameters
// TODO: Is this secure enough?
$text = $_REQUEST['t'];
@sshongru
sshongru / ImageDiff
Last active December 17, 2015 21:29
Examines two PNG files and outputs a diff PNG if they are different.
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ImageDiff {
private static BufferedImage expectedImage;
@sshongru
sshongru / replaceString.sh
Created May 28, 2013 23:09
Replaces all occurrences of A with B
#!/bin/sh
# parse the test name from the path to the input file (/path/to/myTest.input => _path_to_myTest.input)
TEST_NAME=${1}
TEST_NAME=${TEST_NAME//A/B}
#TEST_NAME=${TEST_NAME/A/B} -> replace first occurrence
echo ${TEST_NAME}
@sshongru
sshongru / getFileSize.sh
Created May 6, 2013 21:04
Given a file it returns the file size from wc -c with the extra strings stripped off.
#!/bin/sh
# Usage: ./getFileSize.sh myFile.exe
# Outputs file size of the given file
FILE=${1}
DIRTY=`wc -c ${FILE}`
@sshongru
sshongru / getSubstring.sh
Created April 18, 2013 21:13
A simple BASH script that can parse a substring out of a larger string by stripping off the start then end parts of the string
#!/bin/sh
# parse the test name from the path to the input file (/path/to/myTest.input => myTest)
TEST_NAME=${1}
TEST_NAME=${TEST_NAME%.input*}
TEST_NAME=${TEST_NAME##*/}
echo ${TEST_NAME}