Skip to content

Instantly share code, notes, and snippets.

@saltnlight5
saltnlight5 / security.groovy
Created October 26, 2012 18:50
security.groovy
// http://docs.oracle.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html
// MessageDisgest
// - Take input text/bytes and produce a fixe length digest
// - MD5, MD2, msgDigest-1
//
// Cipher
// - Take cleartext text and key and produce a ciphertext
// - Symmetric uses secret key (fast): DES, 3DES are fixed key length
// - Asysmmetric uses public/private key (slow): AES, RSA are variable length
@saltnlight5
saltnlight5 / linux_tips.sh
Created October 26, 2012 16:04
linux_tips.sh
# Set bash shell prompt - show current working dir and shell name in two lines.
# The '\e]2;\w\a' will set and update the term title bar
export PS1='\e]2;\w\a\e[32m\]\u@\h:\e[33m\]\w\e[0m\]
$(basename $SHELL)> '
# Set kshshell prompt - show current working dir and shell name in two lines.
export PS1='$USER@$HOSTNAME:$PWD
$(basename $SHELL)> '
# Grep dir recursively with certain file types only
@saltnlight5
saltnlight5 / bash_programming.sh
Created October 26, 2012 16:02
bash_programming.sh
# Number comparison: [[ -gt, -ge, -lt, -le ]]
# Number comparison: (( <, <=, >, >= ))
# String comparison: [[ ==, != ]]
# String comparison: -z zero_length_string, -n not_zero_length_string
# String comparison:
[[ $a == z* ]] # True if $a starts with an "z" (pattern matching).
[[ $a == "z*" ]] # True if $a is equal to z* (literal matching).
[ $a == z* ] # File globbing and word splitting take place.
[ "$a" == "z*" ] # True if $a is equal to z* (literal matching).
@saltnlight5
saltnlight5 / replace.sh
Created October 26, 2012 14:16
replace.sh
#!/usr/bin/env bash
#
# String replace on a file, or all files in a directory
# Author: Zemian Deng 10/26/2012
#
# Usage:
# ./replace.sh my_file localhost `hostname`
# ./replace.sh my_dir localhost `hostname`
# DRY=1 ./replace.sh my_dir localhost `hostname`
#
@saltnlight5
saltnlight5 / varsubstitution.groovy
Created October 25, 2012 11:53
varsubstitution.groovy
// String variable substitutions
def parseVariableNames(String text) {
def names = []
def pos = 0, max = text.length()
while (pos < max) {
pos = text.indexOf('${', pos)
if (pos == -1)
break
def end = text.indexOf('}', pos + 2)
if (end == -1)
@saltnlight5
saltnlight5 / tzconverter.groovy
Created October 25, 2012 02:42
tzconverter.groovy
/* Usage
groovy tzconverter.groovy '2012-10-24 00:00 EST'
groovy tzconverter.groovy '2012-10-24 00:00 CST' EST
groovy tzconverter.groovy '2012-10-24 00:00 MST' EST
groovy tzconverter.groovy '2012-10-24 00:00 PST' EST
groovy tzconverter.groovy '2012-10-24 00:00 EDT' EST
*/
fromDt = args[0]
toTz = args.length > 1 ? args[1] : TimeZone.getDefault().getID()
@saltnlight5
saltnlight5 / User.java
Created October 19, 2012 20:13
Spring Demos
package it.data;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class User {
@Id
DROP TABLE IF EXISTS TEST;
CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255));
INSERT INTO TEST VALUES(1, 'Hello');
INSERT INTO TEST VALUES(2, 'World');
SELECT * FROM TEST ORDER BY ID;
UPDATE TEST SET NAME='Hi' WHERE ID=1;
DELETE FROM TEST WHERE ID=2;
http://www.thegeekstuff.com/2009/07/linux-apache-mod-ssl-generate-key-csr-crt-file
# openssl genrsa -des3 -out www.thegeekstuff.com.key 1024
Generating RSA private key, 1024 bit long modulus
.......................................++++++
...................................................++++++
e is 73547 (0x01001)
Enter pass phrase for www.thegeekstuff.com.key:
Verifying - Enter pass phrase for www.thegeekstuff.com.key:
@Grab('org.quartz-scheduler:quartz:2.1.6')
@Grab('org.slf4j:slf4j-simple:1.7.1')
import org.quartz.*
import org.quartz.impl.*
import org.quartz.jobs.*
import static org.quartz.DateBuilder.*
import static org.quartz.JobBuilder.*
import static org.quartz.TriggerBuilder.*
import static org.quartz.CalendarIntervalScheduleBuilder.*