1
|
|
1
|
|
That’s it! After that, you should be able to add the hard drive to your system without any issue.
]]>So today I created a quick PHP script which will allow you to create valid JSON from VDF data, so you can parse it much more easily and hopefully make better use of it!
For those who would like to do this, but in a separate language here’s the series of regular expressions I applied, after first encapsulating the entire string in curly braces. NB: ${n} in the replacement is specifying a callback where n is the n’th matched item in the expression. There may be a different call back specification in your preferred language.
1 2 3 4 5 6 7 8 9 10 |
|
To the best of my knowledge these regular expressions cover all of VDF, but I cannot guarantee they will work forever. However if it ceases to work I will update it as soon as I notice/am informed.
]]>1 2 3 |
|
Then it takes these items and calculates the length they take up, and finds our remaining length from max length.
1 2 3 |
|
If we have any length left, ie. we can use some of the intermediary path, it tries to do so. Else it just gives back a path with the drive letter and filename only. The first step of shortening the the intermediary path is to remove the first and last elements, as we are already using them, then join the tokens back together into a string.
1 2 3 4 5 |
|
Then we need to get the lengths of the first and second sections for the shortened path, the text around our eventual ellipses. In the event the remaining length is an odd number, ceiling one value and floor the other.
1 2 3 |
|
Finally we rebuild our now shortened path. Taking lenA characters from the front and lenB characters from the end. Then use these parts and put them together with our ellipses and drive / filename to form our new shortened path!
1 2 3 4 |
|
Not too hard of a task, but an interesting one that gives a good example of string manipulation.
]]>clip_loc
pointing to its location on disk. NOTE: You can also use a URL instead of a file.
After we have our AudioInputStream, we create our clip. We use getClip() from the AudioSystem class, then open our AudioInputStream for the clip, then just use the clips start() method to play it. It’s that simple!
After that we have a set of empty while loops. These loops just serve to block execution while the clip is playing. ie. keep the program open until the clip finishes playing. If your program will stay open anyways, then you will want to remove these lines and place the clip’s close() method in an appropriate place.
After the loops, the clip closes to release resources and we’re done! That simple.
Also, you’ll notice the entire code was wrapped in a try statement. Feel free to throw the exceptions instead. Also, I used a generalized catch to handle all the Exceptions. This is not good practice, but it made the code simpler. Really you’d want to catch each exception and handle it individually.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
So this is pretty simple to follow. It starts with a number, then just sends it to the recursive method. If the number = 2, which is our http://en.wikipedia.org/wiki/Base_case, then it is obviously prime and we add it to our array of prime numbers.
If not, we start at two for our counter and keep adding one until we get a number that evenly divides into our target number.!num.mod(i).equals(zero)
Or, if we go past the mid point if(num.subtract(i).subtract(i).signum() == -1)
we know it is a prime number by deductive reasoning: If you start at 2 (which when the number is divided by 2 yields half the number), then go past half the number there is no way you can even divide into the number.
If it is prime, we add it to the array and return, breaking out of this recursive dive. Else, if we found two divisors, we recurse through both of them to get their prime factorizations. Because the prime factorization of any number is equal to the prime factorization of its factors.
That’s all for today. Any questions or comments feel free to respond!