Friday, December 7, 2012

Logout using terminal / command line

If you ever find it difficult to find the logout button(sometimes happens - out of screen), run this command
/usr/bin/gnome-session-save --logout

or
/usr/bin/gnome-session-save --force-logout

Tuesday, September 4, 2012

Create your own custom ROM for any Android device (from XDA)

Don't want to spend time reading? Have a look at the videos here

You can find a detailed guide, which keeps on updating in this thread.

This guide is for the one who have little experience with Android. Also covers some good advanced topics.

Saturday, August 18, 2012

Meld: Comparison Tool

Meld is a visual diff and merge tool targeted at developers. Meld helps you compare files, directories, and version controlled projects. It provides two- and three-way comparison of both files and directories, and has support for many popular version control systems.

Meld helps you review code changes and understand patches. It might even help you to figure out what is going on in that merge you keep avoiding.

Features

  • Two- and three-way comparison between files and directories

  • Comparisons update as you type

  • Visualisations make it easier to compare your files

  • Actions on diff chunks make for easier merges

  • Supports Git, Bazaar, Mercurial, Subversion, etc.

File comparison

  • Edit files in-place, and your comparison updates on-the-fly

  • Perform two- and three-way diffs and merges

  • Easily navigate between differences and conflicts

  • Visualise global and local differences with insertions, changes and conflicts marked

  • Use the built-in regex text filtering to ignore uninteresting differences

  • Syntax highlighting (with optional gtksourceview)
Meld: Comparison Tool

Directory comparison

  • Compare two or three directories file-by-file, showing new, missing, and altered files

  • Directly open file comparisons of any conflicting or differing files

  • Filter out files or directories to avoid seeing spurious differences

  • Simple file management is also available
Meld: Comparison Tool

Version control

  • Meld supports many version control systems, including Git, Mercurial, Bazaar and SVN

  • Launch file comparisons to check what changes were made, before you commit

  • View file versioning statuses

  • Simple version control actions are also available (i.e., commit/update/add/remove/delete files)
Meld: Comparison Tool

Getting it

Meld is packaged for just about every Linux and Unix distribution, including Fedora, Ubuntu, and Suse. You should get Meld from your distribution's installer unless you want the absolute latest version. Also available on Ubuntu Software Center.

Meld does work on OS X and Windows, but there are no all-in-one packages for those systems available at the moment. On OS X, Meld is available from MacPorts or Fink. There are some notes available on how to get Meld running on Windows.

Note: This information is from the official website of MELD

Thursday, August 16, 2012

OS X 10.8 Mountain Lion bootable USB (without MAC)

Download the raw file from here.

How to use:

1 - Copy the .raw file to an USB stick using SUSE Studio Image Writer.

If you have error during copy, eject and re-connect the pen drive. When Windows asks if you want to format it, cancel and run Image Writer again.

If the problem persists, disable your anti-virus software, it may be blocking raw write to the drive.

Another Image Writer for Windows, if SUSE doesn't work
https://launchpad.net/win32-image-writer/+download


2 - Boot the USB drive and install.

If you need, type boot options, for example:
-v (verbose boot) [default]
-x (safe)
-s (single user)
GraphicsEnabler=yes (enable graphics card drivers) [default]
USBBusFix=yes (fix problems with USB devices)
npci=0x2000 (use if boot stops at "PCI configuration begin")
cpus=1

If you need, use TransMac to remove kexts which are causing problems (System/Library/Extensions) and use the flag -f (ignore caches) at boot, or remove /System/Library/Caches/com.apple.kext.caches/Startup/Extensions.mkext

If you get KP related to ApplePolicyControl.kext remove /System/Library/Extensions/AppleGraphicsControl.kext/Contents/PlugIns/ApplePolicyControl.kext

If boot stops right before reaching the installer, or graphics aren't working right, remove video kexts and boot with GraphicsEnabler=No -f

ATI = ATI*
Intel = AppleIntelHD* AppleIntelSNB*
nVidia = GeForce* NVDA*

You need at least one free partition, use Disk Utility (in the Utilities menu) to erase it as Mac Os Extended (Journaled).

If you want to install Chameleon (the boot loader) in this partition and you use MBR (not GUID, like if you already have Windows in the HD), it must be a primary (not extended/logical) partition.

Wait for the installation to finish and restart.


3 - Boot the USB drive, then choose to boot the HD you just installed OS X (not the installer USB again).


4 - Install Chameleon and the Extra folder to the HD.

I recommend using Chameleon Wizard to install and create/configure org.chameleon.Boot.plist and SMBIOS.plist in /Extra folder.
http://www.insanelymac.com/forum/index. ... pic=257464

5 - Install essential and other kexts you may need (network, audio, etc).

FakeSMC.kext is always needed.
http://www.mediafire.com/?lgxtj47kk47cn9k

While you don't have power management fixed, you will probably need NullCPUPowerManagement.kext.
http://www.mediafire.com/?uwvnvztwtna

If you use PS/2 keyboard or a laptop you will need VoodooPS2Controller.kext (or ApplePS2Controller.kext) and AppleACPIPS2Nub.kext.
http://www.mediafire.com/?jw9zk6i2d4m2vvd

I recommend using Kext Wizard to install kexts.
http://www.insanelymac.com/forum/index. ... pic=253395

Boot Options

The boot: prompt waits for you to type advanced startup options.
If you don't type anything, the computer continues starting up normally. It
uses the kernel and configuration files on the startup device, which it also
uses as the root device.

Advanced startup options use the following syntax:

[device]<kernel> [arguments]

Example arguments include

device: rd=<BSD device name>       (e.g. rd=disk0s2)
rd=*<IODeviceTree path>    (e.g. rd=*/PCI0@0/CHN0@0/@0:1)

kernel: kernel name                (e.g. "mach_kernel" - must be in "/" )

flags: -v (verbose)                -s (single user mode)
-x (safe mode)              -f (ignore caches)
-F (ignore "Kernel Flags" specified in boot configuration file)

"Graphics Mode"="WIDTHxHEIGHTxDEPTH" (e.g. "1024x768x32")

kernel flags                       (e.g. debug=0x144)
io=0xffffffff                      (defined in IOKit/IOKitDebug.h)

Example: mach_kernel rd=disk0s1 -v "Graphics Mode"="1920x1200x32"

If the computer won't start up properly, you may be able to start it up
using safe mode.  Type -x to start up in safe mode, which ignores all
cached driver files.

Special booter hotkeys:
F5            Rescans optical drive.
F10           Scans and displays all BIOS accessible drives.

Special booter commands:
?memory       Displays information about the computer's memory.
?video        Displays VESA video modes supported by the computer's BIOS.
?norescan     Leaves optical drive rescan mode.

Additional useful command-line options:
config=<file>             Use an alternate Boot.plist file.

Options useful in the org.chameleon.Boot.plist file:
Wait=Yes|No             Prompt for a key press before starting the kernel.
"Quiet Boot"=Yes|No     Use quiet boot mode (no messages or prompt).
Timeout=8               Number of seconds to pause at the boot: prompt.
"Instant Menu"=Yes      Force displaying the partition selection menu.

"Default Partition"     Sets the default boot partition,
=hd(x,y)|UUID|"Label"    Specified as a disk/partition pair, an UUID, or a
label enclosed in quotes.

"Hide Partition"        Remove unwanted partition(s) from the boot menu.
=partition               Specified, possibly multiple times, as hd(x,y), an
[;partition2 ...]       UUID or label enclosed in quotes.

"Rename Partition"      Rename partition(s) for the boot menu.
=partition <alias>       Where partition is hd(x,y), UUID or label enclosed
[;partition2 <alias2>   in quotes. The alias can optionally be quoted too.
...]

GUI=No                  Disable the GUI (enabled by default).
"Boot Banner"=Yes|No    Show boot banner in GUI mode (enabled by default).
ShowInfo=No             Disables display of partition and resolution details.
"Boot Banner"=No will also disable this info.
"Legacy Logo"=Yes|No    Use the legacy grey apple logo (disabled by default).

PciRoot=<value>         Use an alternate value for PciRoot (default value 0).

UseKernelCache=Yes|No   Yes will load pre-linked kernel and will ignore /E/E
and /S/L/E/Extensions.mkext.
Default is No but Yes if you use Lion on a Raid partition.

KeyLayout=keymap        Use to change the keyboard mapping of the bootloader
(e.g. KeyLayout=mac-fr)

GraphicsEnabler=Yes|No  Automatic device-properties generation for gfx cards.
AtiConfig=<cardcfg>   Use a different card config, e.g. AtiConfig=Megalodon.
AtiPorts=<value>      Specify the number of ports, e.g. AtiPorts=2.
UseAtiROM=Yes|No      Use an alternate Ati ROM image
(path: /Extra/<vendorid>_<devid>_<subsysid>.rom)
UseNvidiaROM=Yes|No   Use an alternate Nvidia ROM image
(path:  /Extra/<vendorid>_<devid>.rom)
VBIOS=Yes|No          Inject NVIDIA VBIOS into device-properties.
display_0=<value>     Inject alternate value of display-cfg into NVDA,Display-A@0 (HEX).
display_1=<value>     Inject alternate value of display-cfg into NVDA,Display-B@1 (HEX).
EnableHDMIAudio=Yes      Inject HDMI audio for NVIDIA

EthernetBuiltIn=Yes|No  Automatic "built-in"=yes device-properties generation
for ethernet interfaces.

USBBusFix=Yes           Enable all USB fixes below:
EHCIacquire=Yes         Enable the EHCI fix (disabled by default).
UHCIreset=Yes           Enable the UHCI fix (disabled by default).
USBLegacyOff=Yes        Enable the USB Legacy fix (disabled by default).

ForceHPET=Yes|No        Force Enable HPET.

Wake=No                 Disable wake up after hibernation (default: enabled).
ForceWake=Yes           Force using the sleepimage (disabled by default).
WakeImage=<file>        Use an alternate sleepimage file.
(default path is /private/var/vm/sleepimage).

DropSSDT=Yes            Skip the SSDT tables while relocating the ACPI tables.
DSDT=<file>             Use an alternate DSDT.aml file
(default paths:
/DSDT.aml /Extra/DSDT.aml bt(0,0)/Extra/DSDT.aml).

GenerateCStates=Yes     Enable auto generation of processor idle sleep states
(C-States).
GeneratePStates=Yes     Enable auto generation of processor power performance
states (P-States).
CSTUsingSystemIO=Yes    New C-State _CST generation method using SystemIO
registers instead of FixedHW.

EnableC2State=Yes       Enable specific Processor power state, C2.
EnableC3State=Yes       Enable specific Processor power state, C3.
EnableC4State=Yes       Enable specific Processor power state, C4.

SMBIOS=<file>           Use an alternate SMBIOS.plist file
(default paths:
/Extra/SMBIOS.plist bt(0,0)/Extra/SMBIOS.plist).

SMBIOSdefaults=No       Don't use the Default values for SMBIOS overriding if
smbios.plist doesn't exist, factory values are kept.

"Scan Single Drive"     Scan the drive only where the booter got loaded from.
=Yes|No               Fix rescan pbs when using a DVD reader in AHCI mode.
Rescan=Yes              Enable CD-ROM rescan mode.
"Rescan Prompt"=Yes     Prompts for enable CD-ROM rescan mode.
SystemId=<UUID>         Set manually the system id UUID,
SMUUID in smbios config (reserved field) isn't used.
SystemType=<n>          Set the system type where n is between 0..6
(default =1 (Desktop)
md0=<file>              Load raw img file into memory for use as XNU's md0
ramdisk. /Extra/Postboot.img is used otherwise.

Sunday, August 12, 2012

Multi-Booting Windows 7, Windows 8, Mac OS X Lion and Ubuntu

Getting Started

Things you need:
- Lion USB prepared with UniBeast (see tonymacx86.com)
- Win7 install media (preferably USB stick with Win7 SP1)
- Win8 install media (USB stick)
- Ubuntu 12.04LTS (USB stick) (see ubuntu.com)
- A blank HDD or SSD ready as install target

Section A (plan your partition scheme)

When setting up a multi-boot system involving Windows it is important to realize you will need to create what is known as a hybrid MBR/GPT partition scheme.  It is necessary to place all partitions intended to be accessed by Windows such that they are in sync’d MBR table.  This means they should be placed first.  For this guide, I will be setting up the following partitions on a 320GB hard drive:
EFI: 200MB, created by Mac OS X Disk Utility when partitioning
Win7: ~60GB, NTFS
Win8: ~60GB, NTFS
Transfer: ~60GB, exFAT (could use FAT32 as well)
Lion:~60GB, Mac OS X Extended (journaled)
Linux-Swap: 8GB (my computer has 8GB memory)
Linux: a bit less than 60GB (amount left), ext4
As a result, the Win7, Win8, and Transfer partitions are accessible to MBR based Windows.  Lion and Linux can access all of the partitions.  The Transfer partition can be used to move data between systems.

Section B (create initial partition scheme)

  1. Boot from the Lion USB key.
  2. Go into Disk Utility
  3. Select Partition tab
  4. Select to repartition as GPT the entire drive.  In my case, I use 5 partitions here (this will give you 5 equal sized partitions, if you want something different, you can do that).  Label, and set the file system type as follows:
    Win7, FAT32
    Win8, FAT32
    Transfer, exFAT
    Lion, Mac OS X Journaled
    Linux, FAT32
  5. Apply your changes, and Quit Disk Utility
  6. Shutdown your computer
  7. Remove Lion USB key.
  8. Insert the Ubuntu USB key, turn on computer and boot from Ubuntu USB
  9. Connect to wireless if necessary (if you don’t have the ethernet cable plugged in)
  10. Open the Ubuntu Software Center application
  11. Go to the Edit menu, and select “Software Sources…”
  12. Check the box for “universe”, then click Close
  13. Run Terminal (easiest way is Ctrl+Alt+T)
  14. Run the following commands:
    sudo apt-get update
    sudo apt-get install gptsync
  15. Copy gptsync to your Linux USB for later use (that way if you have to run it again, you don’t have to reinstall using apt-get above):
    sudo cp /sbin/gptsync /cdrom/gptsync
  16. Now run gparted (go to Ubuntu Home and type gparted, then click on it)
  17. gparted will scan your drives and display the first one
  18. If you have multiple drives in your system, make sure the target drive is displayed (for this guide I have one HDD known under Linux as /dev/sda)
  19. The last partition in the list should be the Linux/FAT32 partition… Delete that partition
  20. Create a new partition (select the unallocated space, then select Partition –> New from the menu)
  21. Make the size 8192 (smaller or larger depending on how much RAM you have)
  22. Set the file system type to ‘Linux-Swap’, and set the Label to ‘Linux-Swap’
  23. Now create another new partition, this time use all remaining space, and set the file system type to ‘ext4′ and Label to ‘Ubuntu’
  24. Select the Win7/FAT32 partition, and Format it as NTFS
  25. Select the Win8/FAT32 partition, and Format it as NTFS
  26. Apply the changes
  27. Select the first NTFS partition (the one that was Win7/FAT32) and label it Win7
  28. Select the second NTFS partition (the one that was Win8/FAT32) and label it Win8
  29. Apply the changes… You should now have a complete partition setup that matches our plan in Section A
  30. Now go back to the Terminal window that you launched earlier, and type the following:
    sudo /cdrom/gptsync /dev/sda
    (note: /dev/sda is the target drive)
  31. Shutdown the computer, and remove the Ubuntu USB key

Section C (Install Windows 7)

  1. Insert your Windows 7 USB key, and boot from it (alternatively, use your Win7 DVD)
  2. Choose your language, click Install Now, accept the license then choose ‘Custom’
  3. You should be able to select the Win7/NTFS partition and click Next.  If you can’t, format that partition (Drive Options within the Windows 7 installer).  If you still can’t install to that partition after formatting, close the Windows 7 Installer, and restart the computer, restarting the Windows 7 installer.
  4. Proceed to completely install Windows 7
  5. At the end of the Install sequence you now have Windows 7 installed with the Windows 7 boot loader
  6. Shutdown the computer, and remove the Windows 7 USB key

Section D (Install Windows 8)

  1. Insert your Windows 8 USB key, and boot from it
  2. Choose your language, then choose ‘Custom’
  3. You should be able to select the Win8/NTFS partition and click Next
  4. Proceed to completely install Windows 8
  5. At the end of the Install sequence you now have Windows 7 and Windows 8 installed using the Windows 8 boot loader (dual boot Win7/Win8 — this will cause trouble when we go to use the Chimera boot loader, but we’ll fix it later)
  6. Shutdown the computer, and remove the Win8 USB key

Section E (Install Lion)

  1. Insert your UniBeast prepared Lion install USB key, and boot from it.
  2. Choose your language
  3. If you proceed to the target selection page, you will probably notice that it won’t allow you to install to the Lion partition created earlier (I’m not sure why, but we fix that in the next step)
  4. Run ‘Disk Utility’ (again).
  5. Choose the ‘Lion’ partition on the left, then ‘Erase’ tab on the right.
  6. Erase (format) it as Mac OS X Extended (journaled)
  7. Quit Disk Utility
  8. You can now select ‘Lion’ as the target partition for Mac OS X install.
  9. Do that and run through the install like normal.
  10. After install, do any post-install stuff you need to do (in my case running HP ProBook Installer v4 to install, among other things, Chimera boot loader)
  11. Shutdown the computer, and remove the Lion USB key.
  12. You should be able to boot from the hard disk now and see the Chimera boot loader (or whatever boot loader you’re using)

Section F (Cleanup Windows BCD bootmgr)


First of all, if you are only installing one Windows operating system (just Windows 7 or just Windows 8), you can skip this section.  Otherwise, read on.

Now that you have Chimera installed, you can use it exclusively to boot between Windows 7 (although it is cumbersome), Windows 8, and Lion.  For now, if you attempt to boot the Win8 partition using Chimera, it will not work, but if you boot Win7 partition using Chimera, you will get the Windows 8 boot menu and you’ll be able to boot either Win7 or Win8 (Chimera is loading the Windows 8 boot loader).  The goal of this section is to fix that so, you can boot directly into the Win7 and Win8 partitions.

Basically what is going on here is that Windows 8 installed the Windows 8 boot loader into the Win7 partition and set up a dual boot between Win7/Win8.  There is no Windows boot loader on the Win8 partition.

Here’s how we fix this mess:
  1. Using Chimera, boot the Win7 partition
  2. You will now see the Windows 8 boot loader with selections for Windows 7 and Windows 8
  3. Choose to boot Windows 8 (Note: If you instead select Windows 7, the Windows 8 boot loader will reboot the computer, you will see the Chimera screen again, and should you select the Win7 partition from there, you will then boot directly to Windows 7)
  4. Once in Windows 8, go to the Desktop, then right click on the bottom-left corner of the screen, from the menu, choose “Command (Admin)”
  5. OK the UAC prompt
  6. You are now in the Windows 8 command line
  7. Some explanation might be handy here if your drive configuration is different than mine.  In my case there is only one HDD, so at this point in Windows 8, the C: drive is the Win8 partition and the D: drive is the Win7 partition.  We need to copy the necessary files for boot from the Win7 partition to the Win8 partition, as the Win8 partition doesn’t have a complete boot loader.  To do this we execute the following commands:
    robocopy d:Boot c:Boot /mir /xf bcd.*
    bcdedit /export c:BootBCD
  8. Now we have a copy of the necessary boot files on both the Win7 and Win8 partitions, which will allow us to boot either one from Chimera.  Next we have to make it such that each boot menu contains only Windows 7 or Windows 8, and make it such that the boot menu does not appear.  To do so, you need to follow these instructions carefully.  First of all let’s fix up the Windows 8 boot menu.
  9. First you need to determine the identifier used for the Windows 7 entry in the boot loader.  Run the following:
    bcdedit /store c:BootBCD
  10. This displays information about the BCD menu on the Win8 partition.  You want to look for the second “Windows Boot Loader” entry where it says “identifier”.  That is the entry you want to delete.
  11. In my case the identifier is {408f7757-c9e3-11e0-8a2d-b7f526558aef}, so the command required is:
    bcdedit /store c:BootBCD /delete {408f7757-c9e3-11e0-8a2d-b7f526558aef} /cleanup
  12. We also need to fix up the {bootmgr} device entry:
    bcdedit /store c:BootBCD /set {bootmgr} device partition=C:
  13. After that, you are done with the boot loader on the Win8 partition.  To check your results, type:
    bcdedit /store c:BootBCD
  14. Now you have to fix up the Win7 boot entries, such that they do not include Windows 8. First determine which entry must be deleted:
    bcdedit /store d:BootBCD
  15. It will probably look exactly like the one above before we changed it.  The Windows 8 identifier should be {default}, so to delete it, we use:
    bcdedit /store d:BootBCD /delete {default} /cleanup
  16. Now we need to make it such that the menu doesn’t display in either case:
    bcdedit /store c:BootBCD /set {bootmgr} displaybootmenu no
    bcdedit /store d:BootBCD /set {bootmgr} displaybootmenu no
  17. At that point, we should be done.  You can display your work and double-check it with:
    bcdedit /store c:BootBCD
    bcdedit /store d:BootBCD
  18. Each boot menu should have only one boot menu entry, and they should be pointing to the appropriate partition… Win8 to C:, and Win7 to D:
  19. Restart the computer and try booting into each Win7 and Win8 partitions from Chimera.  It should work with no intervening Windows boot loader menu now.

Section G (Cleanup the Chimera menu)


When you boot your computer, you will notice that the Chimera boot loader picks up on the Transfer/exFAT partition and shows ‘GPT unknown’.  It would be nice to eliminate this from the menu.

  1. To do so, use Chimera to boot into Lion
  2. Once there, bring up a Terminal to determine which partition the exFAT partition is by typing: diskutil list
  3. Look under the IDENTIFIER column.  If you are following this guide exactly, the Transfer partition will be ‘disk0s4′
  4. Now use TextEdit to edit your /Extra/org.chameleon.Boot.plist
  5. Find or add the <Key>Hide Partition</key> section
  6. In the line below it, change or add the line to read:
    string>hd(0,4)</string>
  7. That should hide the partition 4 on disk 0.
  8. Save the file.
  9. Restart to test, then Shutdown the computer.

Section H (Install Ubuntu)

  1. Turn on the computer and boot using the Ubuntu install USB
  2. Choose the first option, “Run Ubuntu” (do not choose the installer directly)
  3. After you arrive at the Ubuntu desktop, if you’re not connected to the internet, you may want to take this opportunity to do that (via the menu bar at the top of the screen)
  4. After that, choose the second icon down (run the Ubuntu installer)
  5. Answer the various questions about language, then Continue
  6. Eventually, you’ll come to a screen that asks about “Installation Type”. Choose “Something Else” from this screen. This gives you greater control over where Ubuntu installs.  Then click Continue.
  7. It will now scan disks.
  8. Look in the resulting list for the partition made earlier of ‘ext4′ type.  In my case, it is /dev/sda7.  Select it and click ‘Change’
  9. Change the ‘Use as’ to ‘Ext4 journaling file system’
  10. Change the ‘Mount point’ to ‘/’ (no quotes), click the checkbox to Format, then click OK.
  11. Find the swap partition created earlier. In my case it is /dev/sda6.  Select it and click ‘Change’.  Verify that it is using it as ‘swap area’ (should already be setup that way).  Click OK.
  12. IMPORTANT! You will want to pay special attention to the ‘Device for boot loader installation’.  Change it to the same ext4 partition we used in steps 9 & 10. This will cause grub2 to be installed on the Ubuntu partition and won’t interfere with the Chimera boot loader already installed.  Again, in my case, it is /dev/sda7.
  13. You are now ready to install Ubuntu, so click ‘Install Now’, ignore the warning about the boot loader installation and Continue.
  14. While it is copying files, you can answer the other questions about Location, Keyboard layout, account, etc.
  15. Skip the part about importing accounts from Windows (ie. no checkbox)
  16. After Ubuntu installs is a good time to check to be sure the hybrid partition scheme is still intact, so don’t restart right when it asks you to.  Instead, bring up a terminal (Ctrl+Alt+T) and type:    sudo /cdrom/gptsync /dev/sda
    (of course, substituting /dev/sda with the real path of your HDD in case it is not /dev/sda)
    Answer Y, if it proposes changes.
  17. Now you are ready to restart and test.  You should now be able to boot Windows 7, Windows 8, Mac OS X Lion, and Ubuntu from the Chimera menu.  You will notice that you see the grub menu in the case of booting Linux, but we can fix that in the next section.

Section I (Cleanup/Disable GRUB2 menu)

  1. Boot into Ubuntu
  2. Type the following:
    gksu gedit /etc/default/grub
  3. In the editor, uncomment the GRUB_HIDDEN_TIMEOUT=0, and make GRUB_TIMEOUT=0, then save the file
  4. Back in the terminal, type:
    sudo update-grub
  5. Restart and test.  At this point, if you select Ubuntu from the Chimera boot loader, it should go directly there and you won’t see the GRUB2 menu (if you want it, supposedly you hold down shift while booting… side note: it didn’t work for me).

Section J (Install support for exFAT in Ubuntu)


In order to use the Transfer partition from Ubuntu, you need to install exFAT support as it doesn’t support it natively.  I used exFAT because it is a little more capable that FAT32 (particularly in support for files larger than 4GB)… if you decided to just use FAT32, you can skip this section.

  1. Boot into Ubuntu, then run Terminal (Ctrl+Alt+T)
  2. First we need to install exfat support using apt-get:
    sudo apt-add-repository ppa:relan/exfat
    sudo apt-get update
    sudo apt-get install fuse-exfat
  3. Now you can mount the Transfer (on /dev/sda4 in Linux) partition with:
    sudo mkdir /mnt/transfer
    sudo mount -t exfat /dev/sda4 /mnt/transfer
  4. And you can make it mount automatically, by editing fstab:
    gksu gedit /etc/fstab
  5. Once in the editor, add the following line to the bottom:
    /dev/sda4 /mnt/transfer exfat defaults 0 0
  6. Save, then to mount and check after that edit:
    sudo mount -a

Section K (Disable Fast Startup for Windows 8)


It appears that the new Hybrid Hibernate/Fast Startup feature new in Windows 8 does not work with this Chimera boot scheme.  I would suggest you disable it:

  1. Boot to Windows 8
  2. Go to the Windows 8 Desktop
  3. Right click at bottom left corner of screen, and choose Control Panel
  4. Search for ‘Power Options’
  5. Choose ‘Change what the power buttons do’
  6. Choose ‘Change settings currently unavailable’
  7. Scroll down to Shutdown settings
  8. Untick “Turn on fast startup (recommended)”
  9. Now shutdown from Windows 8 will now work correctly.

Conclusion


If you made it this far, you may be deciding to give it a try.  And if you do, please leave feedback as a comment. And if you find an error, let me know and I’ll try to fix it.  Good luck!

Source: Guide to Installing Windows 7, Windows 8, Mac OS X Lion, and Ubuntu Multi-Boot.

Wednesday, July 18, 2012

JavaScript - Singleton Pattern

The singleton design pattern is probably the simplest and most common pattern in JavaScript.

So why should you use the singleton pattern?
  • Encapsulation of members & functions
  • Creates its own Namespace
  • A singleton is a single instance object
  • Encourages code reuse
  • Improves readability because you can logically organise your code

The point of a singleton is to only have one instance. A shopping cart is a good example of something that you may want only a single instance of at one time.


The simplest form of Singleton is an object literal. This loose form of Singleton cannot be instantiated. All of the members are now accessible through the Singleton variable, accessible through dot notation.
varmyCart = {
   self: this,

   totalCost: 0,

   totalQty: 0,

   cart: {},

   getCart: function(){ },

   updateCart: function(){ }

};

alert( "Total cost: $"+ myCart.totalCost );

By using closures, we can create Private and Public Members and Functions. This pattern is more commonly called the Module Pattern.

 var myCart = function(){
    // Private

    var self = this;

    var totalCost = 0;

    var totalQty = 0;

    var cart = {};

    return {

        // Public

        getCart: function(){ },

        updateCart: function(){ }

    };

}();

HTML5 localStorage

Persistent Client-Side Key-Value Pairs

The localStorage object has four primary method:
  • localStorage.clear()

  • localStorage.getItem( key )

  • localStorage.removeItem( key )

  • localStorage.setItem( key, value )

When dealing with the localStorage object, it is important to remember that, like cookies, you are dealing with string values. Both the key and the value arguments must be strings. And, while the browser might not throw an error if you pass-in non-string values, you'll quickly find that it is simply calling the toString() method implicitly.

Run the following sample code and check the console:
<html>
<head>
<script type="text/javascript">
console.log("tim in localStorage —",("tim" in localStorage));
console.log("localStorage.getItem( tim ) —",localStorage.getItem( "tim" ));
localStorage.setItem( "tim", "nice" );
localStorage[ "bad" ] = "awesome";
console.log("tim in localStorage —",("tim" in localStorage));
console.log("localStorage.getItem( ‘bad’ ) —",localStorage.getItem( "bad" ));
var myObject = {};
localStorage.setItem( "myObject", myObject );
console.log("typeof( myObject ) —",typeof( localStorage.getItem( "myObject" )));
localStorage.removeItem( "tim" );
delete localStorage[ "bad" ];
console.log("tim in localStorage —",("tim" in localStorage));
console.log("bad in localStorage —",("bad" in localStorage));
var clientId;
var id = localStorage.getItem(clientId);
if (!id) {
id = Math.floor(Math.random()*10000);
localStorage[clientId] = id;
}
var x = "new";
localStorage[x] = "killer";
console.log(localStorage.getItem(x));
</script>
</head>
<body></body>
</html>

Monday, July 9, 2012

Download entire website from terminal using wget

This will help you to download entire website along with the links to other pages.i.e, you can almost browse the website offline. First install wget(if not present). Then run this from terminal.
wget --mirror -p --convert-links -P ./LOCAL-DIR WEBSITE-URL

–mirror : turn on options suitable for mirroring.
-p : download all files that are necessary to properly display a given HTML page.
–convert-links : after the download, convert the links in document for local viewing.
-P ./LOCAL-DIR : save all the files and directories to the specified directory.

Friday, July 6, 2012

How to format USB or external drive in Ubuntu

If you could find the device on the Launcher, just right-click and select "format". Otherwise, see this....

You can use the disk utility(installed by default) to format the drive. There is an option 'format volume' select that option.
How to format USB or external drive in Ubuntu

How to format USB or external drive in Ubuntu

How to format USB or external drive in Ubuntu

How to format USB or external drive in Ubuntu

How to format USB or external drive in Ubuntu

Thursday, July 5, 2012

Taking Screenshots in Mac OS X

  • Command-Shift-3: Take a screenshot of the screen, and save it as a file on the desktop

  • Command-Shift-4, then select an area: Take a screenshot of an area and save it as a file on the desktop

  • Command-Shift-4, then space, then click a window: Take a screenshot of a window and save it as a file on the desktop

  • Command-Control-Shift-3: Take a screenshot of the screen, and save it to the clipboard

  • Command-Control-Shift-4, then select an area: Take a screenshot of an area and save it to the clipboard

  • Command-Control-Shift-4, then space, then click a window: Take a screenshot of a window and save it to the clipboard

In Leopard and later, the following keys can be held down while selecting an area (via Command-Shift-4 or Command-Control-Shift-4):

  • Space, to lock the size of the selected region and instead move it when the mouse moves

  • Shift, to resize only one edge of the selected region

  • Option, to resize the selected region with its center as the anchor point

Submitting Your App to AppStore

Submitting your app to the App Store is a multistep process involving several tools. First, create a distribution provisioning profile using iOS Provisioning Portal. Then create an archive, validate it, and submit it to the App Store using Xcode. When your app is approved, set the date the app will be available to customers using iTunes Connect. Finally, don’t forget to respond to user issues after you ship your first version.

Before You Begin

Before starting, you should have a distribution certificate and the status of your iTunes Connect app record should be “Waiting for Upload” or later, as described in “Creating Your App Record in iTunes Connect.”

Now, create a distribution provisioning profile using the iOS Provisioning Portal.

Create a Distribution Provisioning Profile

When the app is ready for publication, you create a distribution provisioning profile by selecting App Store as the method of distribution. The steps are similar to creating an ad hoc provisioning profile for testing except that you select an app ID only. You do not select any signing certificates or device IDs.

To create a distribution provisioning profile . . .
  1. Log in to the iOS Provisioning Portal from the Member Center.
  2. Select Provisioning in the sidebar.
  3. Select the Distribution tab.
  4. Click New Profile.
  5. Select App Store as the distribution method.
    Submitting Your App to AppStore

  6. Enter a profile name.
  7. Confirm that your distribution certificate is displayed.
  8. Choose app ID.
  9. Click Submit.

    When the status of the ad hoc provisioning profile changes from Pending to Active, you can begin using it. You may need to refresh the webpage in the iOS Provisioning Portal to see the status change. If you are using Safari, select View > Reload Page.

Configuring Your Project for App Store Submission

To submit your app for publication on the App Store, you need to build the app using your team’s distribution code signing identity.

To configure your project to facilitate the building of distribution-identity–signed archives of your app:
Submitting Your App to AppStore
  1. In your project, duplicate the Release build configuration and name the duplicate “AppStore”.
  2. Set the Code Signing Identity build setting to your team’s distribution code signing identity through the app’s distribution provisioning profile for the AppStore build configuration.
  3. In the target, delete the Validate Build Product build setting specification for the Release build configuration.
  4. Goto manage schemes and duplicate the scheme that builds your app and name the duplicate  “<App_Name>-AppStore”.
  5. In the AppStore scheme, set the build configuration for the Archive action to AppStore.

Create and Validate the Archive


To create the archive . . .
  1. Select the Xcode project window.
  2. Choose iOS Device from the scheme toolbar menu.



  3. Choose Product > Archive.
    The Archives organizer appears and displays the new archive.
To validate the archive . . .
Submitting Your App to AppStore
  1. In the Archives organizer, select the archive.
  2. Click the Validate button.
  3. Enter your iTunes Connect credentials and click Next.
  4. Select the app you want to share and the appropriate signing identity, and click Next.
  5. Review validation issues found, if any, and click Finish.
You need to fix any validation issues, create a new archive, and validate it again. You cannot proceed until the archive passes the validation tests.

Submit the Archive

Only after passing validation tests, can you submit your app to the App Store. In fact, Xcode validates your archive again during the submission process.
If you find "submit" button, click on it and give the "iTunes Connect" credentials and select the corresponding distribution provisioning profile.Else, follow this procedure



To submit the archive to the App Store . . .
Submitting Your App to AppStore
  1. In the Archives organizer, select the archive.
  2. Click the Distribute button.
  3. Select “Submit to the iOS App Store” and click Next.
  4. Enter your iTunes Connect credentials and click Next.
  5. Select the app you want to share and the appropriate signing identity, and click Next.
    Xcode runs the validation tests again. If issues are found, click Cancel and fix them before continuing.
    Submitting Your App to AppStore


  6. Enter a filename and location for the App Store package and click Save.
Xcode transmits the archive to Apple, where it is examined to determine whether it conforms to the app guidelines. If the app is rejected, correct the problems that were brought up during app approval and resubmit it. Before you submit the app, you should read iOS Human Interface Guidelines and App Store Review Guidelines for iOS Apps to avoid problems.

Ship Your App

Use iTunes Connect to set a date when the app is available on the App Store. For example, you can choose a date that immediately releases the app to the App Store after it is approved, or you can set a date for sometime in the future. Using a later availability date allows you to arrange other marketing activities around the launch of your app.
To set the availability date . . .
Submitting Your App to AppStore
  1. Log in to iTunes Connect .
  2. Select Manage Your Applications.
  3. Select your app in iOS App Recent Activity.
  4. Click Rights and Pricing.
  5. Choose a date from the Availability Date pop-up menus.
  6. Optionally, edit the other fields on this form.
  7. Click Save.
Changes you make to Rights and Pricing go live immediately (expect 24 hours for a full refresh of the changes on the App Store).

Creating Your App Record in iTunes Connect

When an app is sold in the App Store, the store displays a lot of information about the app, including its name, a description, an icon, screenshots, and contact information for your company. To provide that information, you log in to iTunes Connect, create a record for the app, and complete some forms. In this chapter you learn how to go through this process.

Note: Normally, you create your iTunes Connect app record late in the development process because there’s a time limit from when you create the record to when you must submit your app. However, some Apple technologies, including Game Center and In-App Purchase, require that an iTunes Connect record to be created earlier. For example, with In-App Purchase, you need to create the app record so that you can add the details of the items you want to sell. This content needs to be created before the development process is complete so that you can use it to test the code you added to implement In-App Purchase.

Before You Begin

Before you begin, make sure that you have these assets ready to enter into the forms:
  • The date when you want to ship your app (you can set the latest date allowed and change it later)

  • A brief description of your app that iTunes will display to customers

  • An app icon (512 x 512 pixels) ready for upload

  • At least one screenshot of your app ready for upload

  • An internal version number for your submission

  • A bundle ID that you've set to match your app ID
Therefore before you can create the actual iTunes Connect app record, you need to accomplish three main tasks, using Xcode:
  1. Capture screenshots.

  2. Set the launch image.

  3. Set your bundle ID.

Capture Screenshots

Using Xcode, you can capture screenshots of your app on a device and save the images on your desktop to upload to iTunes Connect later and use as a launch image.

To capture a screenshot on your device . . .
  1. Connect the device to your Mac.
  2. In Xcode, run your app on the device (as described in “To launch the app on the device”).
  3. Configure the app on the device the way you want it.
  4. In Xcode, open the Devices organizer.
  5. In the Devices section, click the disclosure triangle next to the iOS device.
  6. Select Screenshots .
  7. Click New Screenshot in the lower-right corner.


Creating Your App Record in iTunes Connect

To save a PNG file of a screenshot, drag the screenshot from Xcode to the desktop. Optionally, move the screenshots to a folder so that you can keep them all in one place.

Set the Launch Image

Besides capturing screenshots, you should set a launch image that acts as a placeholder for your application’s user interface at launch time. Do this at the same time that you capture screenshots for iTunes Connect.
To set your launch image . . .
  1. In the Xcode Devices organizer, select the screenshot in the Screenshots folder of the Library section.
  2. Select “Save as Launch Image.”
  3. Specify the name of the image and the target app, and click Next.
    Creating Your App Record in iTunes Connect
After performing these steps, the corresponding launch image is set in the Summary pane in Xcode. For example, if the screenshot was captured on an iPhone 4, the screenshot now appears in the Summary pane as the Retina Display launch image in iPhone/iPod Deployment Info.

Set the Bundle ID to Match the App ID

The record in iTunes Connect also includes a field for a bundle ID; the value you place in this field must exactly match the bundle ID for the app. The app name and version you enter in iTunes Connect must also match the Xcode project configuration.

You set the bundle ID for your app when you create your Xcode project as described in “Creating an Xcode Project.” For your convenience, the bundle ID defaults to a reverse-domain name using the company identifier followed by the product name that you entered when you created your Xcode project—for example,com.charlestaylor.HelloWorld, where com.charlestaylor is the company identifier and HelloWorld is the product name. The bundle ID is actually set in theInfo.plist file of your Xcode project and can be changed to any identifier that follows the RFC 1034 specification.

The bundle ID that you enter in iTunes Connect cannot be changed after the first version of your app is approved or you enabled some specialized technologies, such as iCloud storage or push notifications. Therefore, you should pick the final bundle ID for your app now.

To set your bundle ID in the Info.plist file . . .
  1. In the Xcode project navigator, select the project.
  2. Select your target in the Targets section, in the second column, to display the project editor.
  3. Click the Info tab.
  4. Enter the bundle ID in the Value column of the “Bundle identifier” row.

Create the iTunes Connect App Record

Next, you create the actual iTunes Connect app record and complete some forms. After you finish this process the status of your app is “Prepare for Download.” You need to answer additional questions about export compliance before the status changes to “Waiting for Upload.” The app record status needs to be at least “Waiting for Upload” to submit your app to the App Store.


To create an iTunes Connect app record . . .
  1. Log in to iTunes Connect (described in “To go to iTunes Connect”).
  2. Select Manage Your Applications.
  3. Click Add New App.
    Creating Your App Record in iTunes Connect
  4. Complete the forms by inserting your app's information.
  5. Click Done.
    Creating Your App Record in iTunes Connect
To complete the export compliance question . . .
  1. In iTunes Connect, select Manage Your Applications.
  2. Select your app.
  3. Click View Details.
    Creating Your App Record in iTunes Connect
  4. Click “Ready to Upload Binary.”
  5. Answer the Export Compliance question and click Save.
  6. Click Continue.
    The status of the app should change to “Waiting for Upload.”

Creating Distribution certificate

Before an app can be distributed, your team must have a valid distribution certificate linked to a distribution provisioning profile. Only team admins can create or install a distribution certificate. Each team can have only one active distribution certificate. The team admin can either use Xcode to create a distribution certificate or manually request and download one from iOS Provisioning Portal.

A team’s distribution certificate allows a developer to build an app for distribution. If your team wants to use another Mac to create a distribution build, you need to transfer a copy of the distribution certificate as described in, “Safeguarding and Transferring Your Signing and Provisioning Assets” in Tools Workflow Guide for iOS.


Using Xcode to Create a Distribution Certificate

You should use Xcode to create your distribution certificate. Xcode creates, downloads, and installs a development certificate, distribution certificate, and the iOS Team Provisioning Profile for you. Xcode can also restore missing certificates and renew expired certificates.

To create a distribution certificate . . .

  1. In Xcode, open the Devices organizer.

  2. Select Provisioning Profiles in the Library section.

  3. Click the Refresh button at the bottom of the window..

  4. Enter your user name and password and click Log in.

    After you log in to your account, a prompt appears, asking whether Xcode should request your distribution certificate.

  5. Click Submit Request.

  6. If a prompt appears, at the end of the refresh process, asking if you want to export your developer profile, click Export.
Your request for a distribution certificate is automatically approved. The distribution certificate is added to your keychain and appears in Xcode. You can view, download, or revoke the distribution certificate in the iOS Provisioning Portal.


Manually Managing a Distribution Certificate

Although it is easier to use Xcode to create a distribution certificate, you can manually create a distribution certificate. If you do not have access to Xcode, generate a Certificate Signing Request (CSR) with Keychain Access, submit your request, and download the certificate from the iOS Provisioning Portal.

Generating a Certificate Signing Request with Keychain Access

To generate a Certificate Signing Request manually . . .

  1. Open Keychain Access on your Mac (located in Applications/Utilities).

  2. Open Preferences and click Certificates. Make sure both Online Certificate Status Protocol and Certificate Revocation List are set to Off.

  3. Choose Keychain Access > Certificate Assistant > Request a Certificate From a Certificate Authority.



  4. Enter your user email address and common name. Use the same address and name as you used to register in the iOS Developer Program. No CA Email Address is required.

  5. Select the options “Saved to disk” and “Let me specify key pair information” and click Continue.

  6. Specify a filename and click Save.

  7. For the Key Size choose 2048 bits and for Algorithm choose RSA. Click Continue and the Certificate Assistant creates a CSR and saves the file to your specified location.
Creating a CSR generates a public and private key pair. The private key is stored in the login keychain.

Submitting a Certificate Signing Request for Approval

  1. Navigate to the Certificates area of the iOS Provisioning Portal and click the Distribution tab. Click Request Certificate.

  2. Click Choose File, choose your CSR file, and click Submit.


After the CSR is approved, the certificate is listed under Current Distribution Certificate. If it doesn’t appear automatically, you may need to refresh the page.

Downloading and Installing Distribution Certificates

  1. Navigate to the Certificates area of the iOS Provisioning Portal and click the Distribution tab. Click Download next to the certificate.

  2. In the Finder, double-click the downloaded .cer file to open Keychain Access and install your certificate in your default keychain (usually the login keychain).

Distribution Certificates Must Be Renewed Periodically

A distribution certificate is valid for one year from date of issue. After it expires, you won’t be able sign and install apps on your devices although this will not affect any existing apps in the App Store.

To continue distribution, navigate to the Devices organizer in Xcode. Select the expired profile and click Renew Profile in the red bar at the top. This will renew your expired certificate and add it to the provisioning profile. After you get a new distribution certificate, you can submit new apps or app updates to the App Store.

If you are enrolled in the iOS Developer Enterprise Program, revoking your distribution certificate will make your app fail on any installed devices. Only revoke your certificate if your app or private key have been compromised. You can create a second distribution certificate six months before your existing certificate expires. The overlapping certificate allows you to continue to build and distribute your app once your first certificate expires.

Saturday, June 9, 2012

Change Keyring password

If you change your login password you might find that you get prompted for your "default keyring" password, this can be annoying, and sadly it isn't obvious how to change this to be the same as your new login password (or another password if you are being ultra secure!).


Change Keyring password

  • Go to Passwords and Keys

  • Click on the Passwords tab

  • Right click over Passwords: login

  • Select Change Password
If you change your password to the same as your login password you won't get prompted for your default keyring password when you log in.


Change Keyring password
Or else you can delete it

Building Your Application for Release using Eclipse ADT

After you finish configuring your application you can build it into a release-ready .apk fle that is signed and optimized. The JDK includes the tools for signing the .apk file (Keytool and Jarsigner); the Android SDK includes the tools for compiling and optimizing the .apk file. If you are using Eclipse with the ADT plugin or you are using the Ant build script from the command line, you can automate the entire build process.

In preparation for signing your application, you must first ensure that you have a suitable private key with which to sign. Following Keytool command generates a private key:
$ keytool -genkey -v -keystore my-release-key.keystore
-alias alias_name -keyalg RSA -keysize 2048 -validity 10000

Running the example command above, Keytool prompts you to provide passwords for the keystore and key, and to provide the Distinguished Name fields for your key. It then generates the keystore as a file called my-release-key.keystore. The keystore and key are protected by the passwords you entered. The keystore contains a single key, valid for 10000 days. The alias is a name that you — will use later, to refer to this keystore when signing your application.

The Export Wizard performs all the interaction with the Keytool and Jarsigner for you, which allows you to sign the package using a GUI instead of performing the manual procedures to compile, sign, and align, as discussed above. Once the wizard has compiled and signed your package, it will also perfom package alignment with zipalign. Because the Export Wizard uses both Keytool and Jarsigner, you should ensure that they are accessible on your computer.

To create a signed and aligned APK in Eclipse:
  1. Select the project in the Package Explorer and select File > Export.
  2. Open the Android folder, select Export Android Application, and click Next.The Export Android Application wizard now starts, which will guide you through the process of signing your application, including steps for selecting the private key with which to sign the APK (or creating a new keystore and private key).
  3. Complete the Export Wizard and your application will be compiled, signed, aligned, and ready for distribution.

Friday, May 11, 2012

Words formed by selecting one letter from each set (set combinations)






//Input 1,2   3,4,5  6  -1  each set is entered line-by-line
//-1 is the end of input
//output will be 136,146,156,236,246,256





import java.io.*;
import java.util.*;
import java.lang.String;
import java.util.StringTokenizer;
public class Possibilities {
    public static void main(String[] args) throws IOException {
        String s;
        ArrayList<String> a1 = new ArrayList<String>();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        s = br.readLine();
        if (!s.equals("-1"))
            a1 = generatePossibilities(s);
        System.out.println(a1);
    }

    public static ArrayList<String> generatePossibilities(String s)
            throws IOException
    {
        ArrayList<String> a1 = new ArrayList<String>();
        ArrayList<String> a2 = new ArrayList<String>();
        ArrayList<String> a3 = new ArrayList<String>();
        BufferedReader br1 = new BufferedReader(
                new InputStreamReader(System.in));
        String s2 = br1.readLine();
        if (!s2.equals("-1"))
        {
            a2 = generatePossibilities(s2);
            a3 = generateList(s);
            for (int l = 0; l < a3.size(); l++)
                for (int k = 0; k < a2.size(); k++)
                    a1.add(a3.get(l) + a2.get(k));
        }
        else
            a1 = generateList(s);

        return a1;
    }

    public static ArrayList<String> generateList(String s) throws IOException
    {
        ArrayList<String> a1 = new ArrayList<String>();
        StringTokenizer st = new StringTokenizer(s, ",");
        while (st.hasMoreTokens())
            a1.add(st.nextToken());

        return a1;
    }
}

Saturday, April 28, 2012

Phonegap plugin for Ads on iPhone

I suppose you know how to create a Phonegap project and also how to add a plugin into the project.

First download the required code from here.
Add the "Ads" folder to your plugins list.

To do this, right-click on the Plugins folder in Xcode and select to “Add Files to…” the folder.


Navigate to the Ads folder, and select the folder. Check “Copy items

into. . .” and “Create groups for. . .” A ChildBrowser folder is added to the Plugins folder. Copy the content of "js" folder to desired location.

Then update the plist to use the plugin
In Supporting Files > PhoneGap.plist, add under Plugins

(click the down arrow to the left of Plugins, then click on the + symbol to open a new row):

Key: SAiOSAdPlugin

Type: String (default)

Value: SAiOSAdPlugin

See the "index.html" for initialization of the code.
Now, to display the Ad, call "showTheAd(true)"

and whenever you want to hide the Ad call "showTheAd(false)"

Make sure you link in the iAd framework to your project. Do this by going to your project settings in Xcode. Then select your target and in the right pane go to "Build Phases." Then in the "Link Binary with Libraries" section hit the "+" button to add more frameworks. Select iAd.framework click "Add" and then rebuild.

Friday, April 27, 2012

Google Plus +1 and share

This a html code that can be added to website to share some content on  GooglePlus

You can use any image(but select a related one). By clicking on the image, content will be posted

on the users G+ account. Consider the following samople code
<a href="https://plusone.google.com/_/+1/confirm?hl=en&url=<LINK TO BE SHARED>"

<img src="ANY IMAGE" /></a>

Also the proper description will be posted, along with the link.

Monday, April 16, 2012

Shortest Job First Scheduling using HEAP







// Input is from the file "input.txt" in the form (a1,t1),(a2,t2),(a3,t3)  (arrival time, time to complete ie, burst time)




import java.io.*;
import java.util.*;

public class SJFHeap {
    static class point {
        double time;
        double run;
        int no;
        double total;

        point(int i, double a, double b) {
            no = i;
            time = a;
            run = b;
            total = 0;
        }
    }

    static class MHeap {
        private point[] Heap;
        private int maxsize;
        private int size;
        public MHeap(int max) {
            maxsize = max;
            Heap = new point[maxsize];
            size = 0;
        }

        private int leftchild(int pos) {
            return 2 * pos;
        }

        private int rightchild(int pos) {
            return 2 * pos + 1;
        }

        private int parent(int pos) {
            return pos / 2;
        }

        private boolean isleaf(int pos) {
            return ((pos > size / 2) && (pos <= size));
        }

        private void swap(int pos1, int pos2) {
            point tmp;
            tmp = Heap[pos1];
            Heap[pos1] = Heap[pos2];
            Heap[pos2] = tmp;
        }

        public void insert(point elem) {
            size++;
            Heap[size] = elem;
            int current = size;
            int paren = parent(current);
            if (paren >= 1)
                while (Heap[current].run < Heap[paren].run) {
                    swap(current, paren);
                    current = parent(current);
                }
        }

        public void print() {
            int i;
            for (i = 1; i <= size; i++)
                System.out.println("(" + Heap[i].time + "," + Heap[i].run + ")");
        }

        public point removemin() {
            swap(1, size);
            size--;
            if (size != 0)
                pushdown(1);

            return Heap[size + 1];
        }

        private void pushdown(int position) {
            int smallestchild;
            while (!isleaf(position)) {
                smallestchild = leftchild(position);
                if ((smallestchild < size)
                        && (Heap[smallestchild].run > Heap[smallestchild + 1].run))
                    smallestchild = smallestchild + 1;
                if (Heap[position].run <= Heap[smallestchild].run)
                    return;
                swap(position, smallestchild);
                position = smallestchild;
            }
        }
    }

    public static void main(String[] args) throws IOException {
        MHeap h = new MHeap(10);
        FileInputStream fstream = new FileInputStream("input.txt");
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        point ele;
        String strLin;
        strLin = in.readLine();
        StringTokenizer st = new StringTokenizer(strLin, " (,)");
        int mp = st.countTokens();
        point[] task = new point[mp / 2];
        point[] tem = new point[mp / 2];
        int l = 0, num;
        while (st.hasMoreTokens())
        {
            String x = st.nextToken();
            double x1 = Double.parseDouble(x);
            String y = st.nextToken();
            double y1 = Double.parseDouble(y);
            point pt = new point(l + 1, x1, y1);
            task[l] = pt;
            l++;
        }
        num = l;
        int j = 0, i = 0, killed = 0;
        double now = 0, prev = 0, diff, kill = 0;
        point pt = task[0];
        while (i != num)
        {
            now = task[i].time;
            if (i == 0)
            {
                h.insert(task[i]);
                i++;
                prev = now;
            }
            else
            {
                pt = h.removemin();
                diff = now - prev;
                if (pt.run > diff)
                {
                    pt.run = pt.run - diff;
                    h.insert(pt);
                }
                else
                {
                    pt.total = prev + pt.run - pt.time;
                    kill = prev + pt.run;
                    pt.run = 0;
                    tem[j++] = pt;
                }
                h.insert(task[i]);
                prev = kill > 0 ? kill : now;
                i++;
            }
        }

        h.insert(h.removemin());
        while (h.size != 0)
        {
            pt = h.removemin();
            pt.total = prev + pt.run - pt.time;
            tem[j++] = pt;
            prev = prev + pt.run;
        }
        for (i = 0; i < j; i++)
            System.out.println("Process-" + tem[i].no + " processed for " + tem[i].total);
    }
}