Skip to content

Instantly share code, notes, and snippets.

// No Optional arguments, hence no Optional return value.
Integer product(Integer value1, Integer value2) {
return value1.intValue()*value2.intValue();
}
// Calling place is same as earlier, but presence check is done
// as soon as the values are computed before calling product()
// function.
Optional<Integer> value1 = computeValue1();
if(!value1.isPresent()) {
System.out.println("value1 is missing.");
/**
* Computes the product of the given Integer arguments.
* If any of the arguments are missing, it will return empty as result.
*/
Optional<Integer> product(Optional<Integer> value1, Optional<Integer> value2) {
if(value1.isPresent() && value2.isPresent()) {
return Optional.of(value1.get().intValue()*value2.get().intValue());
} else {
return Optional.empty();
}
@rosarinjroy
rosarinjroy / py
Last active December 19, 2015 19:08
This is a simple script which will execute the given argument like "perl -ne".
#!/usr/bin/env python
#
# Author: Rosarin Roy rosarinjroy at hotmail dot com
#
help_text = """
This script can be used similar to "perl -ne". See the examples below.
Example 1: Hello world
mypy 'print "Hello World"'
@rosarinjroy
rosarinjroy / wtitle.sh
Created July 12, 2013 18:06
A useful bash function to set the Terminal window title
# Works only inside xterm or an equivalent term.
function wtitle {
if [ -z "$ORIG_PS1" ] ; then
ORIG_PS1=$PS1
fi
export PS1="\[\033]0;$1 - \u@\h:\w\007\]$ORIG_PS1"
}
@rosarinjroy
rosarinjroy / open-remote-sqlplus-session.el
Created September 15, 2012 07:15
Elisp functions to open remote SQLplus sessions
;; This utility is to open a SQLplus session from an intermediate jump host.
;; You can invoke the "open-remote-sqlplus-session-interactive" function interactively,
;; which will prompt you for a jump host and the connection string to the SQLplus session.
;; Please change the "list-of-sqlplus-setup-commands" to fit your needs.
;; Also you should change the entries in alias-to-jumphosts-alist to a suitable value.
;; - Roy 09/15/2012.
(defvar alias-to-jumphosts-alist '(("development" . ((:sshurl . "user@devhost") (:sqlurl . "devuser/devpassword@devel")))
("integration" . ((:sshurl . "user@integhost") (:sqlurl . "intuser/intpassword@integ")))
("qa" . ((:sshurl . "user@qahost") (:sqlurl . "qauser/qapassword@qa"))))
@rosarinjroy
rosarinjroy / rails-console.el
Created April 19, 2012 01:22
Elisp code to create a rails console
(defun rails-console ()
"Create a rails console process, if one doesn't exist. And switch to *rails-console* buffer."
(interactive)
(if (null (get-buffer "*rails-console*"))
(progn
(term "/bin/bash")
(term-send-string (get-buffer-process "*terminal*") "rails console\n")
(switch-to-buffer "*terminal*")
(rename-buffer "*rails-console*")
(term-line-mode))
@rosarinjroy
rosarinjroy / output.dat
Created April 10, 2012 21:56
Micro benchmark output
10000000, 19366534, 58864372, 3.04
20000000, 29383997, 95479759, 3.25
30000000, 45976039, 175275721, 3.81
40000000, 57853499, 234138642, 4.05
50000000, 73506767, 291500083, 3.97
60000000, 87584072, 349426518, 3.99
70000000, 103897341, 429060055, 4.13
80000000, 122580223, 526850899, 4.30
90000000, 130561644, 563535489, 4.32
100000000, 149137528, 640108388, 4.29
@rosarinjroy
rosarinjroy / ByteBufferVersusShifting.java
Created April 10, 2012 20:57
Convert byte array to long using shifting and ByteArray and compare the performance
package main;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
* The objective is to compute the value of long represented as a sequence of
* bytes using ByteBuffer and by shifting, and compare the performance.
*
*/