Skip to content

Instantly share code, notes, and snippets.

@ran488
ran488 / uuid.rb
Created January 18, 2017 23:15
Generate a UUID from Ruby
require 'securerandom'
puts SecureRandom.uuid
# OR
# direct from command line: jruby -e "require 'securerandom' ; puts SecureRandom.uuid"
# IRB
# irb(main):001:0> require 'securerandom'
# true
# irb(main):002:0> SecureRandom.uuid
# "8af55604-db60-4347-bb0a-1e13ac058685"
@ran488
ran488 / insert_if_not_exsits.sql
Created June 6, 2016 17:42
Insert into an Oracle table only if it does not already exist (no errors)
-- first SELECT has values you want to insert.
-- second SELECT has enough of those values to verify if record already exists (e.g. primary key)
insert into some_table(col1, col2)
select "value 1", "value 2" from dual where not exists
(select 1 from some_table where col1 = "value 1" and col2 = "value3")
@ran488
ran488 / mongo_aggregation.js
Created October 28, 2015 23:22
MongoDB Aggregation Framework - Various Example Queries
// http://docs.mongodb.org/manual/reference/operator/aggregation/
db.agencyProfiles.aggregate( [
{ $match: {"_id":"Florida SUI Wage"} },
{ $unwind: "$agencyErrors" },
{ $project: {_id:0, agencyErrors: {errorDescription:1, cannedAction:{actionCodeDescription:1}}}}
] )
@ran488
ran488 / CsvToExcelTransformer.java
Created September 17, 2015 00:46
Take arbitrary CSV data and transform it into a "real" Excel worksheet using Apache POI. Why? Because sometimes you just can't lose leading zero's on a field that looks like a number.
// Gradle dep's
// compile 'org.apache.poi:poi:3.12'
//compile 'com.opencsv:opencsv:3.5'
//compile 'log4j:log4j:1.2.14'
package util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringReader;
@ran488
ran488 / build.gradle
Created April 25, 2014 13:59
Running Fortify from Gradle build. These are the snippets of code you can add to your build.gradle to run the analyzer and spit out a Fortify *.fpr file. Fortify is not F/OSS, so you (your company) will need a license, so the dependencies won't be out in public repo's. You will have to add it to your company's private repo (e.g. Artifactory).
// Add a new configuration
configurations {
fortify { extendsFrom compile }
}
// pull in the fortify libs for the new configuration
dependencies {
fortify 'com.fortify:sourceanalyzer:3.90'
}
@ran488
ran488 / SftpSessionFactory.java
Created April 15, 2014 13:19
Class to use in place of Spring's DefaultSftpSessionFactory class for when your key file is inside your WAR file. The Spring implementation will eventually try to get the full file path to send into Jsch constructor, but since the file is in the WAR instead of on filesystem, that will fail. This overrides the setPrivateKey() method to take the c…
package com.XXXXXXXX.filetransfer;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
@ran488
ran488 / mult_chart.rb
Created November 17, 2011 13:52
Ruby - print multiplication chart
# Prints out a multiplication chart
# whipped this to show my 8 year old daughter how cool programming is...
# 1 2 3 4 5 6 7 8 9
# ---------------------------------------------
# 1 | 1 2 3 4 5 6 7 8 9
# 2 | 2 4 6 8 10 12 14 16 18
# 3 | 3 6 9 12 15 18 21 24 27
# 4 | 4 8 12 16 20 24 28 32 36
# 5 | 5 10 15 20 25 30 35 40 45
# 6 | 6 12 18 24 30 36 42 48 54
@ran488
ran488 / md5.rb
Created November 9, 2011 16:50
md5 checksum in Ruby
#!/usr/bin/ruby -w
require 'digest/md5'
ARGV.each do |f|
digest = Digest::MD5.file(f)
puts "#{f}: #{digest}"
end
__END__
@ran488
ran488 / Canonical Identity.xsl
Created August 18, 2011 17:44
Canonical Identity XSL
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
@ran488
ran488 / gget.groovy
Created August 11, 2011 13:48
Simple Groovy script to get URL resource (as text) and blast it to stdout
if(args){
def url = args[0]
def text = url.toURL().text
println text
}
else {
println "USAGE: gget url"
}