JavaScript Code Smells by Elijah Manor

4 07 2015

Advertisements




HTML & CSS: Row with image and scrollable text having height adjusted to the image size

11 04 2015

I will show how, using CSS only, to set the height of the text in a row so it never exceeds the height of the image, and then if the long text exceeds the height, make it scroll. The image dimensions may vary and are not known at the implementation phase.

The goal

The thing I need to do is:

Row with height adjusted to the height of the image, with scrollable text

Row with height adjusted to the height of the image, with scrollable text

The solution

Please take a look here: https://jsfiddle.net/an1gsdm0/

I wrapped the whole row in a table-row. The image and the text are the table-cells in it. The text’s table-cell has inline-block div with text inside. You can test it by manipulating the .image class size. Then the text field height will adjust. Here is the code:

HTML:

<div class="container">
    <div id='first' class='img-div'>
        <img class="image" src='http://png-4.findicons.com/files/icons/2141/web_design_creatives/128/small_smile.png'/>
    </div>

    <div class="outer-text">
        <div id='second' class='text-div'>Put a long text here...
        </div>
    </div>
</div>

CSS:

.container{
    display: table-row;
}

.img-div {
    display: table-cell;
    float: left;
}

.outer-text{
    display: table-cell;

    height: 100%;
    width: 190px;
}

.text-div{
    display: inline-block;

    height: 100%;

    overflow-y: auto;
}

To test it for custom various image sizes change the height of the image:

.image{
    height: 190px;
}




JSLint and JSHint helps to avoid terrible mistakes in JavaScript code

21 02 2015

Smashing Magazine and JavaScript Weekly are reminding all JavaScript coders that there are tools to validate the code: JSLint and JSHint. Those who are accustomed to compiled languages will find it helpful. But not only those…

Read Article at: http://www.smashingmagazine.com/2015/02/18/avoid-javascript-mistakes-with-static-code-analyzer/





Tomcat – Java.Lang.OutOfMemoryError: PermGen Space

1 02 2015

If you see this, it means that your Tomcat server has not enough memory assigned for its Java Virtual Machine.

In a default configuration Tomcat even does not declare to require much momory. on my Windows 7 64-bit machine it was 86 Mb.

Using tips below you can adjust available memory as you need.

How to fix it [Linux]

To give Tomcat more memory navigate to ${tomcat-folder}\bin and create the setenv.sh file with params:

export JAVA_OPTS="-Dfile.encoding=UTF-8 -Xms128m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=1024m"

and restart Tomcat. setenv file will be automatically included in Tomcat startup script.

How to fix it [Windows]

To give Tomcat more memory navigate to ${tomcat-folder}\bin and create the setenv.bat file with params:

set JAVA_OPTS=-Dfile.encoding=UTF-8 -Xms128m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=1024m

and restart Tomcat. setenv file will be automatically included in Tomcat startup script.





Do JavaScript the right way

4 01 2015

Here are some great resources about JavaScript code style, best practices and tips and tricks. Worth to get familiar with them:





Configure SSL/HTTPS on Tomcat with Self-Signed Certificate

16 11 2014

Regarding security, the https with SSL is a minimum requirement. Moreover it has relatively low cost in implementation. Thanks to it your transport layer will be encrypted, preventing sniffing and main in the middle attack. Thanks to it your server validity will be verified with a certificate (In this tutorial I will use self-signed certificate. If you need trusted certificate, follow the trust agency instructions).

1. Generate keystore with self-signed certificate in it

You can generate keystore with java’s keytool. Open the windows command line or shell and check if you have keytool command in your path. If command is not recognized, find keytool app in your %java_home%\bin directory.

Execute this command:

keytool -genkey -alias keyAlias -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore myKeystore.p12 -validity 3650

The keytool will generate key (-genkey) with alias (-alias), PKCS12 storetype (-storetype), RSA algorthm 2048 bytes long stored under myKeystore.p12 file with validity equal to 3650 days (10 years).

Executing this command will ask you few identity questions:

Enter keystore password: keyPwd
Re-enter new password: keyPwd
What is your first and last name?
  [Unknown]:  127.0.0.1
What is the name of your organizational unit?
  [Unknown]:  LooksOK!
What is the name of your organization?
  [Unknown]:  LooksOK!
What is the name of your City or Locality?
  [Unknown]:  Minsk Mazowiecki
What is the name of your State or Province?
  [Unknown]:  mazowieckie
What is the two-letter country code for this unit?
  [Unknown]:  PL
Is CN=127.0.0.1, OU=LooksOK!, O=LooksOK!, L=Minsk Mazowiecki, ST=mazowieckie, C=PL correct?
  [no]:  yes

2. Check keystore contents – find your certificate in there

Issue list command to ensure that keystore contains certificate:

keytool -list -keystore keystore.p12 -storetype PKCS12

This is the output:

Keystore type: PKCS12
Keystore provider: SunJSSE

Your keystore contains 1 entry

keyalias, 2014-11-14, PrivateKeyEntry,
Certificate fingerprint (SHA1): 5A:3C:63:EC:CD:A9:AE:AA:D1:92:B3:3A:68:5A:95:C2:98:E3:69:01

So, the certificate is truly there!

3. Copy your keystore file to Tomcat dir

You can put your keystore file whenever you want, providing you will enter the path in tomcat config. I encourage you to put it under %Tomcat_home%/conf/myKeystore.p12.

4. Configure Tomcat

Tomcat configuration file is located in %Tomcat_home%/conf/server.xml. Find this section:

<!-- Define a SSL HTTP/1.1 Connector on port 8443
   This connector uses the BIO implementation that requires the JSSE
   style configuration. When using the APR/native implementation, the
   OpenSSL style configuration is required as described in the APR/native
   documentation -->

And uncomment the configuration below it. I will use the default 443 port (not the suggested 8443) and add four green lines specific to myKeystore:

<Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol"
  maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
  clientAuth="false" sslProtocol="TLS" 
  keystoreFile="conf/myKeystore.p12"
  keystoreType="PKCS12"
  keystorePass="keyPwd"
  keyPass="keyPwd"
/>

5. Test it

Start Tomcat and go to the:

https:\\127.0.0.1

Your browser will probably warn you about the untrusted certificate:

Przechwytywanie

6. Verify the CN (Common Name)

The Common Name is the url I provided when creating keytool: 127.0.0.1. If this particular address is used in a browser, the browser will not warn you. If you’ll open the

https:\\localhost

instead, the browser will warn you also that the url entered does not match the url provided on certificate creation.

Note: Don’t use Self_signed certificates in production! Use it only in test / dev environment

Did I help you?
I manage this blog and share my knowledge for free, sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





Scalable and modular CSS

18 10 2014

CSS can be a mess. It needs to have standards and rules to avoid a mess. Here is a good speech with recomendations to follow:

http://denisejacobs.com/speaking/talks/scalable-modular-css-ftw/

Remember also about the css standards developed during the years of practice in wordpress. I mentioned them here: https://looksok.wordpress.com/2014/10/11/web-development-done-well-wordpress-web-coding-standards/








%d bloggers like this: