Sunday, January 27, 2019

JavaScript window.location

Using location replace means that this will replace the current history of the page; it is impossible to use the back button to go back to the original page.
window.location.replace("www.i_am_going_to_other_site.com");

Using location assign, this will keep the history for you and with using back button, you can go back to the original page
window.location.assign("www.i_am_going_to_other_site.com");

another way to redirect to another page is using pure Js like below
window.location.href="www.i_am_going_to_other_site.com";

Friday, January 18, 2019

Copy value to clipboard using Javascript

I've discovered 2 approach to copying something to the clipboard using Javascript.

1. You can copy the value from an input field.
<input type="text" value="Hello World" id="myInput">
<button onclick="myFunction()">Copy text</button>
<script>
function myFunction() {
  var copyText = document.getElementById("myInput");
  copyText.select();
  document.execCommand("copy");
  alert("Copied the text: " + copyText.value);
}
</script>
2. You can copy the value directly from a variable.
<script>
  var content = "this is to be copied to clipboard";
  var copyText = $('<input>').val(content).appendTo('body').select();
  document.execCommand('copy');
</script>

Wednesday, January 16, 2019

CodeIgniter validation_errors() is not working

$this->form_validation->run() returns false when no $_POST data is found. It will not set any error to be printed.

Monday, January 14, 2019

Create Large Dummy File

You can create a large dummy file (with the help of the commands below) that can be compressed to a very small file.

In Windows, you do this.
fsutil file createnew C:\temp\10MB-file.dat 10485760
fsutil file createnew C:\temp\20MB-file.dat 20971520
fsutil file createnew C:\temp\30MB-file.dat 31457280
In Linux, you do this.
dd if=/dev/zero of=10MB-file.dat bs=10485760 count=1
dd if=/dev/zero of=20MB-file.dat bs=20971520 count=1
dd if=/dev/zero of=30MB-file.dat bs=31457280 count=1

Reference:
Use this page to get the file size value - https://whatsabyte.com/P1/byteconverter.htm