How to append to AES encrypted file

If you’re using AES in CBC mode, you can use the second to last block as the IV to decrypt the last block, which may be only partially full, then again to encrypt the plaintext of the last block followed by the new plaintext. Here’s a proof of concept: import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; … Read more

How to adjust gutter in Bootstrap 3 grid system?

You could create a CSS class for this and apply it to your columns. Since the gutter (spacing between columns) is controlled by padding in Bootstrap 3, adjust the padding accordingly: .col { padding-right:7px; padding-left:7px; } Demo: http://bootply.com/93473 EDIT If you only want the spacing between columns you can select all cols except first and … Read more

How to get an element’s padding value using JavaScript?

This will return the padding-left value: window.getComputedStyle(txt, null).getPropertyValue(‘padding-left’) where txt is the reference to your TEXTAREA element. The above works in all modern browsers and in IE9. However, it does not work in IE8 and below. Live demo: http://jsfiddle.net/simevidas/yp6XX/ Further reading: https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle Btw, just for comparison, this is how you get the same job done … Read more

jQuery How to Get Element’s Margin and Padding?

var bordT = $(‘img’).outerWidth() – $(‘img’).innerWidth(); var paddT = $(‘img’).innerWidth() – $(‘img’).width(); var margT = $(‘img’).outerWidth(true) – $(‘img’).outerWidth(); var formattedBord = bordT + ‘px’; var formattedPadd = paddT + ‘px’; var formattedMarg = margT + ‘px’; Check the jQuery API docs for information on each: outerWidth innerWidth width Here’s the edited jsFiddle showing the result. … Read more

Right padding with zeros in Java

You could use: String.format(“%-5s”, price ).replace(‘ ‘, ‘0’) Can I do this using only the format pattern? String.format uses Formatter.justify just like the String.printf method. From this post you will see that the output space is hard-coded, so using the String.replace is necessary.

Center text in div?

To center horizontally, use text-align:center. To center vertically, one can only use vertical-align:middle if there is another element in the same row that it is being aligned to. See it working here. We use an empty span with a height of 100%, and then put the content in the next element with a vertical-align:middle. There … Read more

Pad left or right with string.format (not padleft or padright) with arbitrary string

There is another solution. Implement IFormatProvider to return a ICustomFormatter that will be passed to string.Format : public class StringPadder : ICustomFormatter { public string Format(string format, object arg, IFormatProvider formatProvider) { // do padding for string arguments // use default for others } } public class StringPadderFormatProvider : IFormatProvider { public object GetFormat(Type formatType) … Read more