Skip to content

Instantly share code, notes, and snippets.

Cash Register Problem

A cash register has a drawer with separate bins for eight different denominations of money:

  • Pennies
  • Nickels
  • Dimes
  • Quarters
  • Singles
  • Fives
@jalex19100
jalex19100 / singleColumnDataStats.sh
Last active April 27, 2016 21:54
The above script reads from stdin, and prints tab-separated columns of output on a single line. See: http://unix.stackexchange.com/questions/13731/is-there-a-way-to-get-the-min-max-median-and-average-of-a-list-of-numbers-in
#!/bin/sh
sort -n | awk '
BEGIN {
c = 0;
sum = 0;
}
$1 ~ /^[0-9]*(\.[0-9]*)?$/ {
a[c++] = $1;
sum += $1;
}
@jalex19100
jalex19100 / SimpleLocalhostSSL.sh
Last active April 26, 2016 19:11
OpenSSL SSL cert creation for localhost intranet development
openssl genrsa -out server.key -passout pass:test 1024
openssl req -new -subj "/CN=localhost" -key server.key -out server.csr
openssl x509 -req -days 36500 -in server.csr -signkey server.key -out server.crt
## Lines needed in the Apache configuration to enable SSL (probably in a <VirtualHost *:443> tag):
# SSLEngine on
# SSLProtocol all -SSLv2
# SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!SEED:!IDEA
# SSLCertificateFile /keylocation/server.crt
@jalex19100
jalex19100 / twitter_cleanup.user.js
Last active March 11, 2016 18:49
Twitter cleanup
// ==UserScript==
// @name Remove Twitter Inline Images
// @namespace fixTheTwittersNet
// @version 0.2
// @include /^https?://www\.twitter\.com/.*$/
// @include /^https?://twitter\.com/.*$/
// @author This dude
// @description This script removes inline images until you click the expand button
// ==/UserScript==
/* jshint -W097 */
@jalex19100
jalex19100 / create_azure_pfx.sh
Created December 21, 2015 17:38
Create Azure-compatible cert with openssl (mac/linux)
#!/bin/bash
#
# REF: https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure-ssl-certificate/#bkmk_selfsigned
#
###### serverauth.cnf #####
#[ req ]
#default_bits = 2048
#default_keyfile = privkey.pem
#distinguished_name = req_distinguished_name
#attributes = req_attributes
@jalex19100
jalex19100 / StringPerformance.java
Created December 4, 2015 19:07
Really old class to test String performance in Java. Wasn't that helpful.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
/**
* Class: StringPerformance
*/
public class StringPerformance {
@jalex19100
jalex19100 / grabThatFinalXHR.js
Created November 25, 2015 20:50
Grab only the most recently requested ajax call to avoid the response getting overwritten by older calls
var handleSuccess = (function () {
var latestRequestTimestamp = 0;
return function handleSuccess(timestamp, data) {
if (timestamp < latestRequestTimestamp) { return; }
latestRequestTimestamp = timestamp;
/ stuff
};
});
// Also: https://maven.apache.org/plugin-developers/cookbook/add-svn-revision-to-manifest.html
// pom.xml pieces
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>${versions-maven-plugin.version}</version>
</plugin>
<plugin>
keytool -importkeystore -srckeystore "source-keystore.jks" -destkeystore "destination-keystore.jks" -srcstorepass password -deststorepass password -srcalias "alias"
@jalex19100
jalex19100 / unpivot.sql
Created November 11, 2015 22:25
Oracle Unpivot with Tuple magic
-- Personal preference for unpivot
SELECT
SUBSTR(CLMN, 0, INSTR(CLMN,'_TOTAL_FROM', 1, 1)-1) AS COLOR, COUNT, COUNT/TOTAL*100 || '%' AS PCT, TOTAL, FROM_DATE, TO_DATE
FROM (
WITH SUMMARY AS
(SELECT
TO_DATE('2015-09-28','YYYY-MM-DD') AS FROM_DATE, TO_DATE('2015-10-01','YYYY-MM-DD') AS TO_DATE, 100000 AS TOTAL, 90000 AS BLUE,
5000 AS RED,3000 AS GREEN,0 AS YELLOW
FROM DUAL)
SELECT * FROM SUMMARY