Wednesday, July 31, 2013

Work notes; JTestR, JRuby and JMockit

Java; JMockit

Class MockUp

http://jmockit.googlecode.com/svn/trunk/www/javadoc/mockit/MockUp.html

Introduction to JMockit

public void testDoBusiness() {
Mockit.setUpMocks(MockCustomerDao.class)
List<Customer> customers = service.doBusiness();
http://bwinterberg.blogspot.com/2009/08/unittests-with-jmockit.html

Class Mockit

@Deprecated
public static void setUpMocks(Object... mockClassesOrInstances)
http://jmockit.googlecode.com/svn/trunk/www/javadoc/mockit/Mockit.html#setUpMocks%28java.lang.Object...%29

Instructed to use MockUp instead.

How to mock the default constructor of the Date class with JMockit?

long time = SystemTime.asMillis();
Calendar calendar = SystemTime.asCalendar();
Date date = SystemTime.asDate();
http://stackoverflow.com/questions/4563584/how-to-mock-the-default-constructor-of-the-date-class-with-jmockit

"it's good practice to use a SystemTime abstraction in your java classes. Replace your method calls (System#currentTimeMillis and Calendar#getInstance) and direct construction (new Date()) with static method calls"

Class Mockit; documentation

[[method summary]] http://jmockit.googlecode.com/svn/trunk/www/javadoc/mockit/Mockit.html

It appears that I have been finding lots of documentation that contains deprecated calls. Once I get that code working, I need to find out what the current way of doing business is.

JMockit Quick Tutorial (Cheat sheet)

[[tutorial table of contents]] https://github.com/ajermakovics/eclipse-jmockit-assist/wiki/JMockit-Quick-Tutorial-%28Cheat-sheet%29#wiki-Mocking_static_methods

JMockit and static methods

    @Test
    public void shouldMockStaticMethod() {
        new NonStrictExpectations() {
            final MockitEg mock = null;

            {
                MockitEg.shoeSize();
                result = new MockitEgDelegate();
            }
        };

        assertThat(MockitEg.shoeSize(),
                is(equalTo(MOCK_SHOE_SIZE)));
    }
http://binkley.blogspot.com/2011/07/jmockit-and-static-methods.html

There seems to be many ways of using JMockit. This example might hold some clues to understanding how to mock static methods. Other examples seem to indicate there is no difference between mocking static and instance methods. What happens, however, when there is a method with the same name for both static and instance scopes?

Mocking Static Method Calls

public class SweetLittleMock {
        // Same signature as static method in real class
        public static String doStuff() {
            return "SweetLittleMock";
    }
}
http://www.weblogism.com/item/254/mocking-static-method-calls

Another example of mocking static methods.

jmockit, openJDK and UnsatisfiedLinkError

Try adding <jdk6home>/lib/tools.jar to the classpath, before jmockit.jar. If that doesn't solve the problem, passing -javaagent:jmockit.jar as a JVM initialization parameter definitely should.
http://t5187.codeinpro.us/q/50813bbe4f1eba38a437e655

The problem I was having got resolved when I 1) specified JUnit 4 (instead of 3.x.x) in my pom.xml and 2) installed the Eclipse plugin for JMockit ("JMockit Eclipse Plug-in"; Help > Eclipse Marketplace > Find).

Getting started with the JMockit Testing Toolkit

If you are developing on JDK 1.5, then make sure that -javaagent:jmockit.jar (with the proper absolute or relative path to jmockit.jar) is passed as an initialization parameter to the JVM when running tests. This standard JVM initialization parameter causes it to load on start-up the "Java agent" that JMockit uses internally for bytecode instrumentation; this is required to work in all standard JVMs since version 1.5, in all OSs. You may have to use this parameter even on a newer JDK 1.6+, if its Attach API implementation is not supported by JMockit: such is the case with the IBM J9 JDK 1.6, the Mac OS X JDKs, and with JDKs for the Solaris OS.

If you use TestNG in a JDK 1.6+ environment, JMockit can be initialized in one of three possible ways (apart from use of "-javaagent" indicated above, which can also be used). See this page for details.
http://jmockit.googlecode.com/svn-history/r1166/trunk/www/installation.html

Again, installing the Eclipse plug-in did the trick for me.

mockito; simpler & better mocking

[[mockito logo]] http://code.google.com/p/mockito/

Looks nice and simple, but this being my first time in a long time of unit testing with Java, I don't want to feel like I'm limiting myself.

What's the best mock framework for Java? [closed]

http://stackoverflow.com/questions/22697/whats-the-best-mock-framework-for-java

RDoc

RDoc documentation

  Hyperlinks to the web starting http:, mailto:, ftp:, or www. are recognized. An HTTP url that references an external image file is converted into an inline <IMG..>. Hyperlinks starting 'link:' are assumed to refer to local files whose path is relative to the --op directory.

  Hyperlinks can also be of the form label[url], in which case the label is used in the displayed text, and url is used as the target.
http://rdoc.sourceforge.net/doc/

How to word wrap in Vim

:set textwidth=80
:set wrapmargin=2
http://stackoverflow.com/questions/3033423/vim-command-to-restructure-force-text-to-80-columns

I also created some useful functions in my .vimrc file:

function! TurnOnLineWrap(...)
  "http://stackoverflow.com/questions/3033423/vim-command-to-restructure-force-text-to-80-columns
  :set textwidth=80
  :set wrapmargin=2
endfunction

function! TurnOffLineWrap(...)
  "http://stackoverflow.com/questions/3033423/vim-command-to-restructure-force-text-to-80-columns
  :set textwidth=0
  :set wrapmargin=0
endfunction

Java; JTestR (testing Java with Ruby)

Mocks

JtestR bundles the Ruby mocking framework Mocha. This is the mocking framework used for mocking in both Test/Unit and RSpec tests. For several reasons the RSpec way of mocking doesn't fit well with mocking of Java classes. Mocha on the other hand supports this quite easily.
http://jtestr.codehaus.org/Mocks

'RSpec' example for JTestR

describe Account do
  context "transfering money" do
    it "deposits transfer amount to the other account" do
      source = Account.new(50, :USD)
      target = mock('target account')
      target.should_receive(:deposit).with(Money.new(5, :USD))
      source.transfer(5, :USD).to(target)
    end

    it "reduces its balance by the transfer amount" do
      source = Account.new(50, :USD)
      target = stub('target account')
      source.transfer(5, :USD).to(target)
      source.balance.should == Money.new(45, :USD)
    end
  end
end
https://github.com/olabini/jtestr/tree/master/src/ruby/rspec

I've tried to use pure RSpec; I must be missing something, because I can't seem to get it to work. There doesn't seem to be enough documentation handy for me to understand how to "turn on" RSpec for JTestR.

Configuration

rspec

The rspec configuration works exactly like the test_unit configuration value. It also has the same :all parameter, for specifying that all tests are RSpec tests.
http://jtestr.codehaus.org/Configuration

Supposedly, this is where I configure RSpec to be used for my tests. I get some strange error about the missing method "filenames" when I do.

Getting Started

http://jtestr.codehaus.org/Getting+Started

Versions of JTestR

http://docs.codehaus.org/pages/viewpage.action?pageId=42008590

RSpec documentation for mocks

https://www.relishapp.com/rspec/rspec-mocks/v/2-14/docs/message-expectations

How to return a dynamic value from a Mocha mock in Ruby

prc = Proc.new do |xml| 
  "mocked: #{xml}"
end
to_mock.stubs(:post_to_embassy).with(orderInfoXml1).returns(prc.call(orderInfoXml1))
to_mock.stubs(:post_to_embassy).with(orderInfoXml2).returns(prc.call(orderInfoXml2))
http://stackoverflow.com/questions/2742565/how-to-return-a-dynamic-value-from-a-mocha-mock-in-ruby

Mocking constructors in Ruby

require 'mocha'

mock_file_obj = mock("My Mock File") do
  stubs(:some_instance_method).returns("foo")
end

File.stubs(:new).with(is_a(String)).returns(mock_file_obj)
http://stackoverflow.com/questions/72220/mocking-constructors-in-ruby

Mocha documentation - Class: Mocha::Mock

object = mock()
object.expects(:expected_method)
object.expected_method
http://gofreerange.com/mocha/docs/Mocha/Mock.html

Using Java Classes in JRuby

include Java 
...
Dir["/some/path/\*.jar"].each { |jar| require jar }
https://blogs.oracle.com/coolstuff/entry/using_java_classes_in_jruby http://www.pressingquestion.com/720587/Using-Custom-Java-Class-File-In-Jruby

This was instrumental in helping me understand how to pull in Java files into my Ruby tests.

Different dependencies for different build profiles in maven

<profiles>
    <profile>
     <id>debug</id>
     …
     <dependencies>
      <dependency>…</dependency>
     </dependencies>
     …
    </profile>
    <profile>
     <id>release</id>
     …
     <dependencies>
      <dependency>…</dependency>
     </dependencies>
     …
    </profile>
</profiles>
http://stackoverflow.com/questions/166895/different-dependencies-for-different-build-profiles-in-maven

Configure JTestR with Maven

      <plugin>
        <groupId>org.jtestr</groupId>
        <artifactId>jtestr</artifactId>
        <version>0.3.2-SNAPSHOT</version>
        <configuration>
          <port>20333</port>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
https://github.com/stuarthalloway/jtestr/blob/master/jtestr/examples/multi_maven_project/pom.xml

Anyone using JRuby testing framework for Eclipse/Maven?

http://stackoverflow.com/questions/9179491/anyone-using-jruby-testing-framework-for-eclipse-maven

Cucumber-JVM might be an option I can look into if JTestR doesn't end up working.

JTestR + Eclipse

JRuby & JTestR in Eclipse
 
In your eclipse Package Manager sidebar, Right Click -#> Run As.. -#> Run Configurations. Go ahead and select ‘JUnit’ and hit the ‘New Launch Configuration’ button.
 
Fill in the configuration as follows:
 
* Run a single test
Project: your-project-name
Test class: org.jtestr.ant.JtestRSuite
Now just open the ‘Arguments’ tab and inside the ‘VM arguments:’ box
 
-Djtestr.junit.tests=rspec_tests
rspec_tests is the folder where my tests are stored, feel free to change this to something like /test/jtestr/funny_test or whatever structure you store your files in.
https://gist.github.com/peterlind/660434

Valuable little gem that helped me get my JTestR tests running in Eclipse.

Boost your Java Test with Ruby and JtestR

http://www.infoq.com/news/2008/01/boost-java-test

Yet another plug for JTestR. Again promising the benefits of RSpec. If I could only get it to work for me...

What is needed in order to run the JTestR samples? (or using JTestR at all)

mvn install:install-file -DgroupId=org.jtestr -DartifactId=jruby-complete -Dpackaging=jar -Dversion=r1c672b495cfd204421f4a7aed17f6135e730a3b2 -Dfile=[PATH_TO_DOWNLOADED.jar]
http://stackoverflow.com/questions/5578729/what-is-needed-in-order-to-run-the-jtestr-samples-or-using-jtestr-at-all

I needed to do this as well when I tried to pull in JTestR resources.

JRuby

JRuby documentation

http://jruby.org/documentation

Sweetens up JRuby Mocha with several helpers to simplify testing Java from Ruby

https://github.com/elight/jrsplenda

This is old code. If it could be resurrected, it might prove useful for testing my Java code.

Unit Testing J2EE from JRuby

http://evan.tiggerpalace.com/unit-testing-jruby-from-java-public.pdf

Again, old. And the speaker isn't there to fill in the context. It sounds like it was a great presentation. Might hold some further clues to successfully testing Java using Ruby.

Using JRuby with Maven

    <dependency>
      <groupId>org.jruby</groupId>
      <artifactId>jruby-core</artifactId>
      <version>1.7.0.RC1</version>
    </dependency>
https://github.com/jruby/jruby/wiki/Using-JRuby-with-Maven

JRuby and Java Code Examples

https://github.com/jruby/jruby/wiki/JRubyAndJavaCodeExamples

Ok; looks a little overwhelming at first glance.

Your First Day with JRuby

http://www.jfokus.se/jfokus10/preso/jf-10_FirstDayWithJRuby.pdf

PDF slideshow; without the speaker, I'm not sure how much worth this will be.

RSpec Expectations

http://rubydoc.info/gems/rspec-expectations/frames

Rjb - Ruby Java Bridge

instance = str.new_with_sig('Ljava.lang.String;', 'hiki is a wiki engine')
http://rjb.rubyforge.org/

Another way to call Ruby from Java code?

Module: Mocha::API

 - (Mock) mock(name, &block) 
 - (Mock) mock(expected_methods_vs_return_values = {}, &block) 
 - (Mock) mock(name, expected_methods_vs_return_values = {}, &block) 
http://gofreerange.com/mocha/docs/Mocha/API.html

Class: RSpec::Core::RakeTask

- (Object) pattern

Glob pattern to match files.

default: 'spec/*/_spec.rb'
http://rubydoc.info/github/rspec/rspec-core/RSpec/Core/RakeTask#pattern-instance_method

Trying to get JRSplenda working again by upgrading some of the calls. I admit, I really didn't have enough background on the project yet to do much besides being dangerous.

RSpec

Behaviour Driven Development framework for Ruby (w/tag 1.2.0)

https://github.com/dchelimsky/rspec/tree/1.2.0

What's the require for "RSpec::Core::RakeTask"?

require 'rspec/core/rake_task'
https://www.relishapp.com/rspec/rspec-core/v/2-4/docs/command-line/rake-task

RSpec runner and formatters

https://github.com/rspec/rspec-core

Why can't I load spectask?

no such file to load -- spec/rake/spectask
https://www.ruby-forum.com/topic/312974

In my case, it is because the code I was revamping used RSpec and I had RSpec2 installed.

Ruby

Why does Ruby 1.9.2 remove “.” from LOAD_PATH, and what's the alternative?

require_relative 'file_to_require'

# or
require './filename'

# or 
export RUBYLIB="."

# or
require File.expand_path(File.join(File.dirname(__FILE__), 'filename'))
http://stackoverflow.com/questions/2900370/why-does-ruby-1-9-2-remove-from-load-path-and-whats-the-alternative

Bundler: how to use without rails?

require "rubygems"

# The part that activates bundler in your app:
require "bundler/setup" 

# require your gems as usual
require "some_gem"
http://stackoverflow.com/questions/6999547/bundler-how-to-use-without-rails

Unit testing in Ruby

http://www.developerfusion.com/article/84444/unit-testing-in-ruby/

There is no Java to speak of here, but this looked pretty good for Ruby development.

Maven

Running specific Maven Test with JVM Args

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <forkMode>pertest</forkMode>
          <argLine>${maven.test.jvmargs}</argLine>
        </configuration>
      </plugin>
http://blog.tfd.co.uk/2007/09/21/running-specific-maven-test-with-jvm-args/

Exec Maven Plugin - Usage

Note: The java goal doesn't spawn a new process. Any VM specific option that you want to pass to the executed class must be passed to the Maven VM using the MAVEN_OPTS environment variable. E.g.

MAVEN_OPTS=-Xmx1024m
http://mojo.codehaus.org/exec-maven-plugin/usage.html

Hoe versions

http://rubygems.org/gems/hoe/versions

Trying to get JRSplenda working required some changes. I thought by going back in time to a previous version of Hoe that I would be able to fix somethings. In the end, I think I simply commented out the references to hoe.

Switch from deprecated Hoe.new to Hoe.spec

https://github.com/collectiveidea/migration_test_helper/pull/5

How to use git to download a particular tag?

git clone will give you the whole repository.

After the clone, you can list the tags with git tag -l and then checkout a specific tag: git checkout tags/<tag_name>
http://stackoverflow.com/questions/791959/how-to-use-git-to-download-a-particular-tag

Install Gem from Github Branch?

$ rake build
http://stackoverflow.com/questions/2823492/install-gem-from-github-branch

It's suggested that "gem" be left off the "rake build" command.

Thursday, July 25, 2013

Work notes; more vim

Vim

Omit 'Pattern not found' error message in Vim script

:%s/x/y/ge
http://stackoverflow.com/questions/1043432/omit-pattern-not-found-error-message-in-vim-script

Advanced Vim macros

http://blog.sanctum.geek.nz/advanced-vim-macros/

Wonderful resource in helping me better understand registers, macros and how to use inside vim functions.

How to create escaped vim characters besides just copying?

<C-V> + somekey = escaped vim character code
http://unix.stackexchange.com/questions/46827/vim-executing-a-key-command-in-a-function

Variables in Vimscript: Registers as Variables

:let @a = "hello!"
http://learnvimscriptthehardway.stevelosh.com/chapters/19.html

How to use vim registers?

# from vim after selecting a block of text
"ny

# where n is the register letter you want to save the text in
http://stackoverflow.com/questions/1497958/how-to-use-vim-registers

Seven habits of effective text editing

:abbr Lunix Linux

vip:w !wc -w

:grep
:cn

[I:
http://www.moolenaar.net/habits.html

Vim Scripting - call function once for all selected lines

fun Foo() range
    ...
endfun
http://stackoverflow.com/questions/8597153/vim-scripting-call-function-once-for-all-selected-lines

Mapping keys in Vim - Tutorial (Part 1)

nunmap - Unmap a normal mode map
vunmap - Unmap a visual and select mode map
xunmap - Unmap a visual mode map
sunmap - Unmap a select mode map
iunmap - Unmap an insert and replace mode map
cunmap - Unmap a command-line mode map
ounmap - Unmap an operator pending mode map
http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_%28Part_1%29

Escaping single quotes

    :echo escape('as''df', '''') 
http://vim.1045645.n5.nabble.com/escape-and-td1200763.html

Clearing/setting the last search

:let @/ = ""
:let @/ = '^\c[a-z0-9]'
http://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting

How do I emulate a keypress inside a Vim function?

" Press CTRL-Y:
normal <Ctrl+v><Ctrl+y>
http://stackoverflow.com/questions/9445273/how-do-i-emulate-a-keypress-inside-a-vim-function

Vim - yank into search register

" First, "Ayw to yank a word into register A
" Then, / ^R A to put the contents of register A into the search string.
http://stackoverflow.com/questions/2312844/vim-yank-into-search-register

Wednesday, July 24, 2013

Work notes; bash

Bash

How to view the rails console history?

less ~/.irb_history
http://stackoverflow.com/questions/11601303/how-to-view-the-rails-console-history

I opened one of my log files from finder and it was automatically opened in textedit. I proceeded to select content using vim key sequences and ended up over-writing a section. "No problem," I thought; "I'll just close the file and not save." To my dismay, textedit didn't even prompt me and saved the file just before closing it. And with no backups, I figured I had lost it.

But wait; I seem to recall that the Rails console has history because I can up-arrow to previous commands. Where is it? How relieved I was to discover '~/.irb_history'.

Exclude items in a list in a bash script

http://moinne.com/blog/ronald/bash/exclude-items-in-a-list-in-a-bash-script

Looks interesting, but I went with a different route.

Bash Shell Loop Over Set of Files

FILES="./ws-idm/src/main/config/server.jks
./ws-ucidm/src/main/config/server.jks
./ws-ucidm-service/src/main/config/server.jks"

for f in $FILES
do
 cp /Users/davidvezzani/java-app/tomcat/conf/server.002.jks $f
done
http://www.cyberciti.biz/faq/bash-loop-over-file/

I needed to update all instances of a Java keystore I was working on.

Monday, July 22, 2013

Work notes; ssl and certificates

SSL; Cipher suites

What are cipher suites?

http://en.wikipedia.org/wiki/Cipher_suite

Configuring Apache to accept a particular list of cipher suites

https://httpd.apache.org/docs/2.0/ssl/ssl_howto.html

Testing ssl connections using OpenSSL's s_client and s_server

http://wiki.wireshark.org/SSL

Bash script to test OpenSSL's supported cipher suites against a given web server

https://www.ssllabs.com/ssltest/index.html

OpenSSL's documentation for ciphers

http://www.openssl.org/docs/apps/ciphers.html#NAME

How to Disable SSL weak Ciphers in Tomcat Server

http://www.fromdev.com/2009/02/tomcat-best-practices-securing-ssl-by.html

How to control the SSL ciphers available to Tomcat

http://stackoverflow.com/questions/7417809/how-to-control-the-ssl-ciphers-available-to-tomcat

Java™ Cryptography Architecture Standard Algorithm Name Documentation; JSSE Cipher Suite Names

http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#jssenames

SSLHandshakeException: Received fatal alert: handshake_failure when setting ciphers on tomcat 7 server

http://stackoverflow.com/questions/15544116/sslhandshakeexception-received-fatal-alert-handshake-failure-when-setting-ciph?rq=1

-keyalg is only one part of the solution; the other peer involved in the ssl conversation must support a compatible hash algorith for OID in addition to supporting a common cipher suite

SSL; handshake

Give me a detailed breakdown of how the ssl-handshake works

http://pic.dhe.ibm.com/infocenter/tivihelp/v2r1/index.jsp?topic=%2Fcom.ibm.itame2.doc_5.1%2Fss7aumst18.htm

An overview of the SSL handshake

http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/index.jsp?topic=%2Fcom.ibm.mq.csqzas.doc%2Fsy10660_.htm http://pic.dhe.ibm.com/infocenter/tivihelp/v2r1/index.jsp?topic=%2Fcom.ibm.itame2.doc_5.1%2Fss7aumst18.htm

SSL; keytool

Documentation for keytool

http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/keytool.html

Keytool and the -keyalg option

http://stackoverflow.com/questions/15544116/sslhandshakeexception-received-fatal-alert-handshake-failure-when-setting-ciph?rq=1

Java keytool; common commands

https://www.sslshopper.com/article-most-common-java-keytool-keystore-commands.html

Keytool keeps giving SHA256 sigalg instead of requested alg

http://stackoverflow.com/questions/14163889/keytool-keeps-giving-sha256-sigalg-instead-of-requested-alg

keytool - Key and Certificate Management Tool; Supported Algorithms and Key Sizes

http://docs.oracle.com/javase/1.5.0/docs/tooldocs/solaris/keytool.html

How do I generate a 2048 bit CSR using Java Keytool?

http://www.entrust.net/knowledge-base/technote.cfm?tn=8425

keytool - Key and Certificate Management Tool; Option Defaults

http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/keytool.html

SSL; misc

Online tester for SSL-enabled servers

https://www.ssllabs.com/ssltest/index.html

Hash Algorithm OIDs

http://msdn.microsoft.com/en-us/library/ff635603.aspx

SSL; OpenSSL

Creating a self-signed test certificate

http://www.openssl.org/docs/HOWTO/certificates.txt

Public Key Encryption and Digital Signatures using OpenSSL

http://sandilands.info/sgordon/public-key-encryption-and-digital-signatures-using-openssl

these procedures do not involve browsers at all; it's a great example in raw form of how to use certificates for encrypting and signing data

Testing ssl connections using OpenSSL's s_client and s_server

http://wiki.wireshark.org/SSL

Bash script to test OpenSSL's supported cipher suites against a given web server

https://www.ssllabs.com/ssltest/index.html

OpenSSL's documentation for ciphers

http://www.openssl.org/docs/apps/ciphers.html#NAME

Tomcat

How to Disable SSL weak Ciphers in Tomcat Server

http://www.fromdev.com/2009/02/tomcat-best-practices-securing-ssl-by.html

How to control the SSL ciphers available to Tomcat

http://stackoverflow.com/questions/7417809/how-to-control-the-ssl-ciphers-available-to-tomcat

Tomcat configuration; creating a certificate for an SSL-enabled Tomcat server

http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html

HOWTO: Secure SSL in Tomcat and JBoss

http://www.techstacks.com/howto/secure-ssl-in-tomcat.html

The HTTP Connector; SSL Support - BIO and NIO

http://tomcat.apache.org/tomcat-7.0-doc/config/http.html

Vim

How do you do a case insensitive search using a pattern modifier using less?

http://stackoverflow.com/questions/16828/how-do-you-do-a-case-insensitive-search-using-a-pattern-modifier-using-less

How to do case insensitive search in Vim

http://stackoverflow.com/questions/2287440/how-to-do-case-insensitive-search-in-vim

Bash

Bash custom functions

http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-8.html

What's the best way to check that environment variables are set in Unix shellscript

http://stackoverflow.com/questions/307503/whats-the-best-way-to-check-that-environment-variables-are-set-in-unix-shellscr

Weblogic

Using Weblogic SSL

http://www.inf.fu-berlin.de/lehre/WS00/SWT/BEA/documentation/docs51/classdocs/API_secure.html

Introduction to WebLogic Security; Cipher Suites

http://docs.oracle.com/cd/E13222_01/wls/docs81/secintro/concepts.html

Understanding WebLogic Security; J2EE and WebLogic Security

http://docs.oracle.com/cd/E11035_01/wls100/secintro/concepts.html

Wednesday, July 3, 2013

Work notes; vim macros and mappings

Multiline capability for GVim

"Instead you can use \_., which means "match any single character including newline". It's a bit shorter than what you have. See :h /\_.."
/This\_.*text/
http://stackoverflow.com/questions/784176/multi-line-regex-support-in-vim

How to use vim registers?

Great reference on what registers are and how to use them. http://stackoverflow.com/questions/1497958/how-to-use-vim-registers

vim clear last search highlighting

    :let @/ = ""
http://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting

Multiple search and replace in one line

There are a couple ways of doing multiple commands

one

:%s/aaa/bbb/e | %s/111/222/e

two (<CR> represents actual carriage returns)

:%s/aaa/bbb/e<CR>%s/111/222/e
http://stackoverflow.com/questions/4737099/multiple-search-and-replace-in-one-line

Vim: Visual mode maps

There is a lot more in the web references, but here are some of the examples.
:vnoremap g/ y/<C-R>"<CR>
:vnoremap qq <Esc>`>a'<Esc>`<i'<Esc>
View all current mappings
:vmap
Remove a mapping
:vunmap g/
http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_%28Part_1%29#Visual_mode_maps

Deselecting matching strings after search-and-replace in Vim

Stumbled upon command to turn highlighting on/off. Will remove highlighting from the current search. Highlighting will return on your next search.
:nohlsearch 
Will disable highlighting for your current vim session.
:set nohlsearch
Will clear the search pattern register (so that n etc. won't work).
:let @/="" 
http://stackoverflow.com/questions/10499866/deselecting-matching-strings-after-search-and-replace-in-vim

Write your own Vim function

function! JournalBasicConversion(...)
  :%s/^}}/ç/g
  :%s/\n{{\(\([\r\n]\+[^ç]\+.*\)\+\)\nç/\r<pre class=\"code\">\1\r<\/pre>/eg
  :%s/^==\+ \(.\+\)$/<h3>\1<\/h3>/eg
  :%s/^\[\([^\]]\+\)\]$/<a href=\"\1\" target=\"_new\">\1<\/a>/eg
  :%s/>\n\n/>\r<br \/>\r\r/eg
endfunction
http://vim.wikia.com/wiki/Write_your_own_Vim_function

Multiline capability for GVim

"Instead you can use \_., which means "match any single character including newline". It's a bit shorter than what you have. See :h /\_.."
/This\_.*text/
http://stackoverflow.com/questions/784176/multi-line-regex-support-in-vim

How to use vim registers?

Great reference on what registers are and how to use them. http://stackoverflow.com/questions/1497958/how-to-use-vim-registers

vim clear last search highlighting

    :let @/ = ""
http://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting

Multiple search and replace in one line

There are a couple ways of doing multiple commands one
:%s/aaa/bbb/e | %s/111/222/e
two (<CR> represents actual carriage returns)
:%s/aaa/bbb/e<CR>%s/111/222/e
http://stackoverflow.com/questions/4737099/multiple-search-and-replace-in-one-line

Vim: Visual mode maps

There is a lot more in the web references, but here are some of the examples.
:vnoremap g/ y/<C-R>"<CR>
:vnoremap qq <Esc>`>a'<Esc>`<i'<Esc>
View all current mappings
:vmap
Remove a mapping
:vunmap g/
http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_%28Part_1%29#Visual_mode_maps

Deselecting matching strings after search-and-replace in Vim

Stumbled upon command to turn highlighting on/off. Will remove highlighting from the current search. Highlighting will return on your next search.
:nohlsearch 
Will disable highlighting for your current vim session.
:set nohlsearch
Will clear the search pattern register (so that n etc. won't work).
:let @/="" 
http://stackoverflow.com/questions/10499866/deselecting-matching-strings-after-search-and-replace-in-vim

When doing a search/replace on a visual selection, how can I keep the selection?

Great summary on how selections work in Vim.
  1. Run gv to reselect the visual area, and use : from there.
  2. Use the special visual range notation * as a shortcut. For example, you can run :*s/in/out/g to run a substitution on the lines of the previous visual area.
gv

:*s/in/out/g
http://www.reddit.com/r/vim/comments/1ghqng/when_doing_a_searchreplace_on_a_visual_selection/

Search and replace in a visual selection

"The substitute command (:s) applies to whole lines, however the \%V atom will restrict a pattern so that it matches only inside the visual selection. This works with characterwise and blockwise selection (and is not needed with linewise selection). "

http://vim.wikia.com/wiki/Search_and_replace_in_a_visual_selection

Scripting common tasks in Vim

Looks interesting...

"Here you can find a bunch of useful macros, also I recommend you to learn well the useful q macro recording command, it's very very powerful..."

http://stackoverflow.com/questions/255624/scripting-common-tasks-in-vim

VIM: how to execute content of the buffer?

This led me in the right direction to better understand macros, buffers and their relationship to one another.

http://stackoverflow.com/questions/5326430/vim-how-to-execute-content-of-the-buffer

CSS Gradient Background Maker

Wonderful resource to create gradients; many versions to support different browsers.

http://ie.microsoft.com/testdrive/graphics/cssgradientbackgroundmaker/

When doing a search/replace on a visual selection, how can I keep the selection?

Great summary on how selections work in Vim.
  1. Run gv to reselect the visual area, and use : from there.
  2. Use the special visual range notation * as a shortcut. For example, you can run :*s/in/out/g to run a substitution on the lines of the previous visual area.
gv

:*s/in/out/g
http://www.reddit.com/r/vim/comments/1ghqng/when_doing_a_searchreplace_on_a_visual_selection/

Search and replace in a visual selection

"The substitute command (:s) applies to whole lines, however the \%V atom will restrict a pattern so that it matches only inside the visual selection. This works with characterwise and blockwise selection (and is not needed with linewise selection). "

http://vim.wikia.com/wiki/Search_and_replace_in_a_visual_selection

Scripting common tasks in Vim

Looks interesting...

"Here you can find a bunch of useful macros, also I recommend you to learn well the useful q macro recording command, it's very very powerful..."

http://stackoverflow.com/questions/255624/scripting-common-tasks-in-vim

VIM: how to execute content of the buffer?

This led me in the right direction to better understand macros, buffers and their relationship to one another.

http://stackoverflow.com/questions/5326430/vim-how-to-execute-content-of-the-buffer

CSS Gradient Background Maker

Wonderful resource to create gradients; many versions to support different browsers.

http://ie.microsoft.com/testdrive/graphics/cssgradientbackgroundmaker/

Work notes; getting to know Oracle

What is the current (or default) schema in the database being accessed?

select user from dual;
https://forums.oracle.com/thread/495481

How do I create a schema?

Schemas are associated with database users in a one-to-one relationship. To create a schema, create a new user. This usually means you will need to have administrative access to the database.
CREATE USER sidney 
    IDENTIFIED BY out_standing1 
    DEFAULT TABLESPACE example 
    QUOTA 10M ON example 
    TEMPORARY TABLESPACE temp
    QUOTA 5M ON system 
    PROFILE app_user 
    PASSWORD EXPIRE;
http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_8003.htm#i2065278

How do I find out what schemas are available on the database I am accessesing?

Since schemas are linked to user accounts,
SELECT username FROM all_users ORDER BY username;
http://stackoverflow.com/questions/4833459/oracle-sql-query-for-listing-all-schemas-in-a-db

Creating table in other schema oracle using select.

CREATE TABLE schema1.table1 AS (SELECT * FROM SCHEMA.table@LinkedDB);
http://stackoverflow.com/questions/10730596/creating-table-in-other-schema-oracle-using-select

When issuing a command in maven that appears to go wrong, guard the arguments with double-quotes:

mvn install:install-file "-DgroupId=org.mozilla" "-DartifactId=jss" "-Dversion=4.2.5" "-Dpackaging=jar" "-Dfile=C:\Users\AArmijos\workspace\componentes-1.0.4\deps\jss-4.2.5.jar"
http://stackoverflow.com/questions/16348459/maven-3-0-5-command-error-the-goal-you-specified-requires-a-project-to-execute

Add the Oracle JDBC driver to your Maven environment.

mvn install:install-file "-Dfile={Path/to/your/ojdbc.jar}" "-DgroupId=com.oracle" "-DartifactId=ojdbc6" "-Dversion=11.2.0" "-Dpackaging=jar"
http://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/

Use the Oracle JDBC driver in your Maven project.

# pom.xml
   <!-- ORACLE JDBC driver, need install yourself -->
   <dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0</version>
   </dependency>
<br />

# hibernate.cfg.xml
    <hibernate-configuration>
     <session-factory>
      <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
      <property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521:MKYONG</property>
      <property name="hibernate.connection.username">mkyong</property>
      <property name="hibernate.connection.password">password</property>
      <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
      <property name="hibernate.default_schema">MKYONG</property>
      <property name="show_sql">true</property>
      <mapping resource="com/mkyong/user/DBUser.hbm.xml"></mapping>
    </session-factory>
   </hibernate-configuration>
<br />

# HibernateUtil.java
 static {
  try {
   factory = new AnnotationConfiguration().configure().
     setNamingStrategy(SrvTableNamePrefixNamingStrategy.INSTANCE).
     // addPackage("com.xyz") //add package if used.
     buildSessionFactory();
   
  } catch (Throwable ex) {
   // Make sure you log the exception, as it might be swallowed
   System.err.println("Failed to create sessionFactory object." + ex);
   throw new ExceptionInInitializerError(ex);
  }
 }

# Runner.java
 protected Session getSession(){
  Session session = HibernateUtil.getSessionFactory().openSession();
  return session;
 }


Convert a Maven project to an eclipse project.

mvn eclipse:eclipse
http://www.mkyong.com/hibernate/maven-3-hibernate-3-6-oracle-11g-example-xml-mapping/

Skip running the test phase when running Maven.

"-Dmaven.test.skip=true"
http://stackoverflow.com/questions/1607315/build-maven-project-without-running-unit-tests

What is the "printf" equivalent for Java?

String status = String.format("The rename status is (%d)", RENAME_SUCCEEDED);
http://alvinalexander.com/blog/post/java/use-string-format-java-string-output

Strip off '[' and ']' from a line.

:%s/^\[\([^\]]\+\)\]$/\1/g

Convert code blocks using '{{' and '}}' to a <pre class="code"> block

:%s/^}}/ç/g
:%s/\n{{\(\([\r\n]\+[^ç]\+.*\)\+\)\nç/\r<pre class=\"code\">\1\r<\/pre>/g

Create titles

:%s/^==\+ \(.\+\)$/<h4>\1<\/h4>/g

Create links

:%s/^\[\([^\]]\+\)\]$/<a href=\"\1\" target=\"_new\">\1<\/a>/g

Create breaks

:%s/>\n\n/>\r<br \/>\r\r/g

Escape < in code example blocks

:%s/\t</\t \&lt;/g
:%s/</\&lt;/g