Skip to content

Instantly share code, notes, and snippets.

View frankvilhelmsen's full-sized avatar

Frank Vilhelmsen frankvilhelmsen

View GitHub Profile
UUID uuid = UUID.randomUUID()
String partone = ""+ Long.toString(uuid.getMostSignificantBits(), 36)
String parttow = ""+ Long.toString(uuid.getLeastSignificantBits(), 36)
String k = "PREFIX$partone$parttow".replace("-", "")
String l = k.length()
println "UUID short version ($l) : $k"
java.text.SimpleDateFormat dataformat = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss'Z'");
dataformat.setTimeZone(TimeZone.getTimeZone("Europe/Copenhagen")); // locale time
println dataformat.format(new Date())
dataformat.setTimeZone(TimeZone.getTimeZone("UTC")); // zulu time
println dataformat.format(new Date())​
@frankvilhelmsen
frankvilhelmsen / token_creator.groovy
Last active August 29, 2015 14:21
create request with an encrypted token
/* create token for accessing service */
format = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
timestamp = format.format(new Date(System.currentTimeMillis()))
sks = new javax.crypto.spec.SecretKeySpec("OuH5pmYeLIkqiirwiyvY+w==".getBytes(), "AES")
cip = javax.crypto.Cipher.getInstance("AES")
cip.init(javax.crypto.Cipher.ENCRYPT_MODE, sks, cip.getParameters());
raw = cip.doFinal( timestamp.getBytes() );
@frankvilhelmsen
frankvilhelmsen / .gitconfig
Last active August 29, 2015 14:02
gitconfig
# $HOME/.gitconfig
[user]
name = Frank Vilhelmsen
email = fv at frankvilhelmsen.com
[github]
user = frankvilhelmsen
token = token
[color]
ui = true
@frankvilhelmsen
frankvilhelmsen / gist:5432879
Created April 22, 2013 06:45
tcpdump-transcript
0x00c0: 3834 3831 3337 333d 3d3d 0d0a 436f 6e74 8481373===..Cont
0x00d0: 656e 742d 4469 7370 6f73 6974 696f 6e3a ent-Disposition:
0x00e0: 2066 6f72 6d2d 6461 7461 3b20 6e61 6d65 .form-data;.name
0x00f0: 3d22 7061 7373 776f 7264 220d 0a43 6f6e ="password"..Con
0x0100: 7465 6e74 2d54 7970 653a 2074 6578 742f tent-Type:.text/
0x0110: 706c 6169 6e3b 2063 6861 7273 6574 3d49 plain;.charset=I
0x0120: 534f 2d38 3835 392d 310d 0a0d 0a76 6572 SO-8859-1....ver
0x0130: 6131 3233 0d0a 2d2d 3d3d 3d31 3336 3438 a123..--===13648
0x0140: 3938 3438 3133 3733 3d3d 3d0d 0a43 6f6e 98481373===..Con
@frankvilhelmsen
frankvilhelmsen / gist:5362434
Last active December 16, 2015 02:29
call oracle stored procedure returning-cursor from clojure
(ns package.classname
(:require [clojure.xml :as xml]
[clojure.java.jdbc :as jdbc]))
(:import java.sql.Types)
(def db {:classname "oracle.jdbc.driver.OracleDriver"
: ....
:password (System/getenv "password")})
@frankvilhelmsen
frankvilhelmsen / gist:5336889
Last active December 15, 2015 22:59
parallel execution and wrapping jobs in callable groovy tasks
import java.util.concurrent.*
import static java.util.concurrent.TimeUnit.*
long now = System.currentTimeMillis()
// process
NORMAL = 1000; LONG = 2000; LIMIT = 1000
def MAX = 100
def LOW = (MAX * 0.05) // < 5%
@frankvilhelmsen
frankvilhelmsen / gist:5336873
Last active September 6, 2021 17:23
call oracle stored procedure returning-java types from clojure
(ns package.classnamere)
(:import java.sql.Types)
(def db {:classname "oracle.jdbc.driver.OracleDriver"
:....
:password (System/getenv "password")})
(defn prepared-statement " on oracle stored procedure " []
(jdbc/with-connection db
(with-open [stmt (.prepareCall (jdbc/connection) "{ call PACKAGE.PROCEDURE(?, ?) }")]
@frankvilhelmsen
frankvilhelmsen / sms.clj
Created March 21, 2013 11:52
Clojure SMS bulk sending multipart/form-data formular
(ns blog.sms
(use blog.common)
(:require [clojure.data.json :as json]
[clj-http.client :as client]))
(defn post "the data to sms gateway over http" [body]
(client/post "http://api/rpc/bulk/" {
:debug true
:multipart [
{:name "username" :content "******"}
@frankvilhelmsen
frankvilhelmsen / multipart.groovy
Last active September 3, 2021 06:48
Java or Groovy file to check Multipart/form-data opload protocol.
/**
* This utility class provides an abstraction layer for sending multipart HTTP
* POST requests to a web server.
* @author www.codejava.net
*
*/
public class MultipartUtility {
private final String boundary;
private static final String LINE_FEED = "\r\n";
private HttpURLConnection httpConn;