Tuesday, October 6, 2015

Monday, October 5, 2015

[Java] Formatting numeric string output

include java.io.*; 
....
System.out.format("..... %h ......', String word);


Converters and Flags Used in TestFormat.java
ConverterFlagExplanation
d A decimal integer.
f A float.
n A new line character appropriate to the platform running the application. You should always use %n, rather than \n.
tB A date & time conversion—locale-specific full name of month.
td, te A date & time conversion—2-digit day of month. td has leading zeroes as needed, te does not.
ty, tY A date & time conversion—ty = 2-digit year, tY = 4-digit year.
tl A date & time conversion—hour in 12-hour clock.
tM A date & time conversion—minutes in 2 digits, with leading zeroes as necessary.
tp A date & time conversion—locale-specific am/pm (lower case).
tm A date & time conversion—months in 2 digits, with leading zeroes as necessary.
tD A date & time conversion—date as %tm%td%ty
 08Eight characters in width, with leading zeroes as necessary.
 +Includes sign, whether positive or negative.
 ,Includes locale-specific grouping characters.
 -Left-justified..
 .3Three places after decimal point.
 10.3Ten characters in width, right justified, with three places after decimal point.

Source

Regards,
HAJAR.

[Java] Override Error (Java compatibility setting)

I've just learned that there are compatibility settings in Java.

Earlier versions of java doesn't support certain newer features. So whenever you see an error on parts of the code where you really don't see any error, go to project > Properties > Java Compiler > Enable Project specific setting and change the compiler compliance level to a later version, depending on the java features you want to make enabled, such as @Override which only applies to Java 1.5 and up.

Source

Regards,
HAJAR.

[Windows] Best way to make shutdown timer

At least for me LoL

Source

Regards, HAJAR.

Saturday, October 3, 2015

[Java try..finally] Unhandled Exception Type IOException

While trying to program Java Files and I/O on java, I have encountered this error while trying to implement the finally block.

Unhandled Exception Type IOException

This was the code snippet I'd implemented, referred from tutorialspoint's java tutorials:

 
try {
         in = new FileInputStream("input.txt");
         out = new FileOutputStream("output.txt");
         
         int c;
         while ((c = in.read()) != -1) {
            out.write(c);
         }
      }finally {
         if (in != null) {
            in.close();
         }
         if (out != null) {
            out.close();
         }
      }

The trick is to add a catch IOException for the first try and try...catch in the finally block. The fix that works:


try {
 in = new FileInputStream("input.txt");
 out = new FileOutputStream("output.txt");
 while ((c = in.read())!= -1){
 out.write(c);
 }
} catch (IOException e) {
 System.out.println(e);
} finally {
 try {
 if (in != null) in.close();
 if (out != null) out.close(); 
 } catch (IOException ex) {
  System.out.println(ex);
 }
}

That's all for today. Regards, HAJAR.

Monday, September 7, 2015

[C++] scanf thinks a float is double

C++ promotes float as double. 

warning: format ‘%f’ expects argument of type ‘float*’, but argument 2 has type ‘double’ [-Wformat=]
  scanf("%f",rad); // rad is declared as float

So, apply the following fix (it has worked and it should work again):
scanf("%f", &rad)

Set the Default Directory on Terminal (UBuntu)

Click Here!

Reset Password of Root (UBuntu)

Click Here!

Monday, August 24, 2015

Ubuntu 14.04.3 LTS, Virtualbox and Windows 10

This is the guide to future me from the current me who's had some troubles installing the guest OS on her computer in the past, but now sort of get it.

So here goes.

STEP 1 Download and Install:

VirtualBox: 5.0.x build for Windows

UBuntu distro: http://www.ubuntu.com/download/desktop

This will give you an iso disk image of the UBuntu distro. I use Ubuntu 14.04.3 LTS, which was the most recent at the time.

STEP 2 Set up the guest OS on Virtualbox.

Follow this tutorial:


Summary:

1. New > Name and choose your operating system > Memory Size : Half of your installed RAM (depending also on what you'll use the VM for) > Hard Disk: Create a virtual Hard Disk > Dynamically allocated (Fixed size is okay but it will take a lot of time) > Size (40 GB or what's appropriate)

Creating a virtual hard disk is like installing a hard disk for your guest OS, but it uses the space of the real hard disk at the host OS. This separates all operations of the guest OS from the host OS so that anything you do on the guest OS will not affect your host OS. By dynamically allocating the disk space, your guest OS will not take up 40GB of hard disk space initially, but will grow in size until it reaches the limit as you add stuff to it. Fixed size, according to my understanding, will take up that 40GB of space as you install it, as if reserving that space for future works.

2. Settings >

> Processor > Processor (Set to as many processors you wish your Guest OS will utilize)

> Storage > Controller: IDE > Empty (Set optical drive to the UBuntu ISO disk image, which is, according to my understanding, is the installer of the OS)

3. Install

Run the OS and follow your instinct (LoL) This may take a while, especially if you opt for fixed allocation so do not shut down or bail or give up or whatever.

TIPS:

Tip 1: If your VT-x virtualization is not enabled, go to BIOS > advanced setting > CPU > enable VT-x virtualization. For the love of god, try scrolling down if you can't find the VT-x virtualization option. Don't be stupid like me. And don't ask me what that is because I don't know that either. All I know is that it's a thing that makes hosting virtual machines possible.

Tip 2: Skip the virtualbox Guest Additions installation instruction because his doesn't work for the circumstances are different. Instead, go to step 3.

STEP 3

Now that you got your shit together, you may have noticed, as you launch your new guest OS, the resolution is shit. You need a VirtualBox Guest Additions to fix this.

Follow this tutorial:

vBox Guest Additions install

Summary:

1. "Now click "Devices > Insert guest additions CD image" in the virtualbox window. This will insert the guest additions cd image into the guest OS. On Xubuntu the cd should get mounted automatically inside the /media directory."

And wallah, you're done.

Regards,

Hajar 



Saturday, August 1, 2015

How to navigate Windows using a keyboard

It was 6.45 am and there was a nagging voice inside my head that told me not to go back to bed and be productive this time. So I turned on my PC begrudgingly, and still lazy, I've decided that using the mouse is too bothersome.

Perhaps it's not too late to learn the shortcuts to navigating windows?

Hence I asked google for help and found this really helpful page :  How to navigate Windows using a keyboard

And I did something extra. I took all the tips on the page, and fit it in a sticky note which i put up on my desktop for easy reference and training.




KEYBOARD SHORTCUTS
Windowsclose | ctrl+f4
menu | alt+spacebar(Sp)
window operations:resize | win + down
max  | win + up
window mode  | alt + Sp > restore > enter
move | alt + Sp > move > arrow keys
switch windows | alt + tab
navigate fields | tab, Sp , arrow, enter
browser operations:Close tabs | ctrl + F4
Switch tabs | ctrl + tab / ctrl + shift + tab
new window | ctrl + n
new tab | ctrl + t
close tab | ctrl + w
documents navigation:one word / paragraph at a time | ctrl + arrow keys
Begin of document | home key
End of codument | end key
Highlight text | shift + arrow ( + ctrl / + end key)
Right click | shift + f10

Regards,
HAJAR. 

Saturday, July 25, 2015

How to Install Bloodshed Dev C++ (plus extra notes on OpenGL + Dev C++)

Get the Dev C++ installer.

Bloodshed website: 

or

download it from here:

I've learned to keep backup copies of all the files I've downloaded in the past to avoid future complications, which happens, because, as I've learned the hard way, not everything uploaded on the internet stays on the internet forever, because, data needs servers and sometimes data owners have the power to delete data. Which is kind of ironic, really, because I'm using google drive to backup this copy.

Once you've set up a typical installation, don't forget to rename C:\MinGW (tip: Why is my compiler just not working? ), if you've had a previous MinGW installation on your computer. Or else, you'd get an error during compilation. In my case, I changed the name to C:\MinGW_ext and that solved the problem.

Extra note:
Now, I was doing this because I needed to work with OpenGL and glut (Setup instructions here: OpenGL with Dev C++)  and my lecturer preferred Dev C++. I though all was well, but it turns out that all was not well when I encounter another problem with glut.h. I tried to compile a code without an #include <iostream> and got an error. So to fix that, make sure you include <iostream>. (Tip: Glut in Dev C++ error “redeclaration of C++ built-in type `short'”.)

Regards,
HAJAR.