Are you looking for customized advices? Click here to contact the expert!
cghersi
cghersi
Reputation Top 1%
Cristiano Ghersi
Great passion for Software Engineering, mostly coding in Java and C#, I enjoy creating modular and reusable code for everybody!
249 Snippets  (2nd place)
Published
16 Channels
Created
65 Channels
Following
2 hours ago
Last Visit
May 5, 2012
Registered
8538 points  (2nd place)
Reputation
Top 1% Publisher
Junior Code Generator
Serious Code Generator
Senior Code Generator
Master Code Generator
Guru Code Generator
Junior Publisher
Serious Publisher
Senior Publisher
Master Publisher
Guru Publisher
Junior Topic Hub
Serious Topic Hub
Senior Topic Hub
Master Topic Hub
Junior Trend Maker
Serious Trend Maker
Senior Trend Maker
Master Trend Maker
Junior Influencer
Serious Influencer
Senior Influencer
Junior Commenter
Serious Commenter
Senior Commenter
Master Commenter
Junior Judge
Serious Judge
Senior Judge
Master Judge
Junior Popular Coder
Serious Popular Coder
Senior Popular Coder
Master Popular Coder
Guru Popular Coder
Junior Autobiographer
Serious Autobiographer
Senior Autobiographer
Master Autobiographer
Junior Snip2Coder
Junior Geek Aggregator
Serious Geek Aggregator
Senior Geek Aggregator
Master Geek Aggregator
Junior Famous Coder
Serious Famous Coder
Senior Famous Coder
Master Famous Coder
Junior Wise Coder

Recent Snippets See all snippets by cghersi

public by cghersi created Apr 13, 2016  86  0  4  0

Transform a JKS keystore in a PEM certificate

This set of commands transform the certificate from a JKS to a PEM format. It requires JDK keytool and openssl.
keytool -keystore client.ts -exportcert -alias mobile | openssl x509 -inform der -text

#psw of keystore: changeit

keytool -importkeystore -srckeystore client.ts -destkeystore client.p12 -srcstoretype jks -deststoretype pkcs12

#psw of destination keystore: changeit

openssl pkcs12 -in client.p12 -out client.pem

#import psw: changeit
;

public by cghersi created Apr 1, 2016  94  0  3  0

Start Eclipse with a non-default JVM

Eclipse starts with a JMV that is usually the one in the PATH. E.g. the version retrieved thru java --version
C:\eclipse\eclipse.exe -vm "C:\Program Files\Java\jdk1.6.0_45\bin\javaw.exe"           
;

public by cghersi created Mar 29, 2016  122  2  6  1

Enable HTTPS on Tomcat

How to make the apps running on Tomcat able to publish over https
// 1. Export certificate request with keytool
// 1.1 Generate the keytool command with the form at this URL: https://www.digicert.com/easy-csr/keytool.htm
// 1.2 The result will be a pair of file mydomain.jks and mydomain.csr

// 2. Ask the certificate to the cert authority
// 2.1 The result will be a pair of file mydomain.pem and mydomain.p7b

// 3. Import mydomain.pem into mydomain.jks (assuming your alias is "server")
keytool -import -v -trustcacerts -alias server -file mydomain.pem -keystore iot_bissell_com.jks -storepass <secret_psw>

// 4. Edit conf/server.xml in the deployment of Tomcat, add this line 
// (under the element <Service name="Catalina">):
<Connector SSLEnabled="true" 
 ciphers="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA"
 clientAuth="false" keyAlias="server" 
 keystoreFile="/usr/local/tomcat/conf/mydomain.jks" 
 keystorePass="<secret_psw>" maxThreads="150" port="8080" 
 protocol="HTTP/1.1" scheme="https" secure="true" sslProtocol="TLS"/>            
;

public by cghersi created Mar 17, 2016  175  6  6  0

Check the missing indexes in SQL Server

This query returns the list of missing indexes for the queries that are currently running on the server
SELECT 
	er.session_id,
	er.blocking_session_id,
	er.start_time,
	er.status,
	dbName = DB_NAME(er.database_id),
	er.wait_type,
	er.wait_time,
	er.last_wait_type,
	er.granted_query_memory,
	er.reads,
	er.logical_reads,
	er.writes,
	er.row_count,
	er.total_elapsed_time,
	er.cpu_time,
	er.open_transaction_count,
	s.text,
	qp.query_plan,
	logDate = CONVERT(DATE,GETDATE()),
	logTime = CONVERT(TIME,GETDATE())
FROM sys.dm_exec_requests er 
CROSS APPLY sys.dm_exec_sql_text(er.sql_handle) s
CROSS APPLY sys.dm_exec_query_plan(er.plan_handle) qp
WHERE 
	CONVERT(VARCHAR(MAX), qp.query_plan) LIKE '%<missing%'            
;

public by cghersi created Feb 25, 2016  265  2  5  1

Install Docker and Docker compose on Ubuntu

This procedure installs docker and docker compose on Ubuntu 14.04. Thanks to the guides found here: https://docs.docker.com/v1.8/installation/ubuntulinux/ https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-compose-on-ubuntu-14-04
// download docker:
curl -sSL https://get.docker.com/ | sh

// If your company is behind a filtering proxy, you may find that the apt-key command fails for the Docker repo during installation. To work around this, add the key directly using the following:
// curl -sSL https://get.docker.com/gpg | sudo apt-key add -

// verify the correct installation:
sudo docker run hello-world

// install python-pip:
sudo apt-get -y install python-pip

// install docker compose:
sudo pip install docker-compose
;