Friday, January 30, 2015

Fixed: Universal USB Installer syslinux errors

found solution from

https://ardamis.com/2011/09/18/universal-usb-installer-syslinux-errors/


I was trying to create a bootable flash drive with Ubuntu 11.04 using the Universal USB Installer 1.8.6.3 utility from pendrivelinx.com on a Windows 7 64-bit machine with a 16 GB flash drive (mapped to G:), but I kept getting an error that the drive wouldn’t be bootable.
The message in the command line window read:
Execute: C:\Users\[username]\AppData\Local\Temp\[random].tmp\syslinuxnew.exe -maf G:
Syslinux Errors 1
A message box would then appear with the following warning:
Universal USB Installer 1.8.6.3 Setup
An error(1) occurred while executing syslinux.
Your USB drive won’t be bootable…
[OK]
When I opened a command prompt and ran syslinuxnew.exe -maf G:, the result was zero FAT sectors. When I ran syslinux.exe -maf G:, I got a much more informative message, or at least one that I could better understand: this doesn’t look like a valid FAT filesystem.
And of course, the flash drive wasn’t FAT32, it was NTFS. I had forgotten to format the drive as FAT32 before running the utility, but I also managed to not check the box next to “We will format G:\Drive as FAT32.” in the utility itself.
No wonder Google wasn’t returning any results when I searched this – who’s going to have missed properly formatting the drive not once but twice?
In the event that a quick format as FAT32 doesn’t work for you, you can try running a few diskpartcommands in Windows to really thoroughly format a flash drive, including the MBR and partition table.

Saturday, January 17, 2015

Convert int to String or char* yourself


It was asked by an interviewer to me in an interview and I found a bit of equivalent code in


char* version 

char* itoa(int value, char* result, int base) {
  // check that the base if valid
  if (base < 2 || base > 36) { *result = '\0'; return result; }

  char* ptr = result, *ptr1 = result, tmp_char;
  int tmp_value;

  do {
   tmp_value = value;
   value /= base;
   *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
  } while ( value );

  // Apply negative sign
  if (tmp_value < 0) *ptr++ = '-';
  *ptr-- = '\0';
  while(ptr1 < ptr) {
   tmp_char = *ptr;
   *ptr--= *ptr1;
   *ptr1++ = tmp_char;
  }
  return result;
 }



std::string version



std::string itoa(int value, int base) {

  std::string buf;

  // check that the base if valid
  if (base < 2 || base > 16) return buf;

  enum { kMaxDigits = 35 };
  buf.reserve( kMaxDigits ); // Pre-allocate enough space.


  int quotient = value;

  // Translating number to string with base:
  do {
   buf += "0123456789abcdef"[ std::abs( quotient % base ) ];
   quotient /= base;
  } while ( quotient );

  // Append the negative sign
  if ( value < 0) buf += '-';

  std::reverse( buf.begin(), buf.end() );
  return buf;
 }