In Bash, we can add contents to file easily using the > character. Like this : echo "myContents" > ~/myfile.txt What if you want to append contents to the file without overwriting ? The easiest way to do this is change the “>” to “»”. Just by making this small change, appending will be done : echo "myContents" >> ~/myfile.txt Even if the file doesn’t exist, Bash will create one with the contents given to append.... [READ MORE]
Posts marked with "Text" in tags
Creating a File with Contents in Bash
It’s really easy to create a file in Bash with cat and > : cat "/home/simsu/file.txt" > "/home/simsu/file.txt" But, what if you want to add contents to file too ? In this case, we can use cat and echo. Here’s how we do it in echo : echo "My File, My Choice" > "/home/simsu/file.txt" But, there’s a problem with doing like this. Since there is an option to limit the characters of a Terminal command, adding large contents is not possible.... [READ MORE]
Move Cursor To End Of Input Or Textarea In jQuery
The function that moves the cursor of an input element to the end in jQuery is .focus(). But sometimes, this won’t work even if you replace it with [0].click(). It’ll maybe work on input fields properly, but won’t properly at all in text areas. Mostly it won’t work, if you are calling the .focus() function inside an event listener function. To solve this you can use 2 other methods if the first one don’t work.... [READ MORE]
Generating Random String in PHP
In PHP you can generate random number by using rand function, but there is no specific function to generate a random text or string. In this post I’m going to show the function that will generate a random string of length mentioned. Here is the function: function rand_string($length) { $str=""; $chars = "subinsblogabcdefghijklmanopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $size = strlen($chars); for($i = 0;$i < $length;$i++) { $str .= $chars[rand(0,$size-1)]; } return $str; } Usage To generate a random string use rand_string() function with the parameter of length of the to be generated string.... [READ MORE]