Author Archive
Python – Search key in a Dictionary by value
by edy_3dz on Feb.13, 2012, under Code snippets
If you need to get the key of an item from a Dictionary in Python, supposing that the items are unique, here’s an easy way to do it:
def find_key(dic, val): """return the key of dictionary dic given the value""" return [k for k, v in dic.iteritems() if v == val][0]
where dic is the dictionary, and val is the value for whose key you are looking for.
Get disk serial for licensing system
by edy_3dz on Feb.13, 2012, under Misc
I’m currently working on a big project, a management application for Desktop PCs. I had to implement a licensing system, so I chose to make the licensing based on the hard-disk’s serial, which is an unique number , and can’t be modified. To obtain the serial I preferred to use a library named GetDiskSerial. It consists of a DLL that can be easily used in Delphi, C++Builder, C#, Visual C++, Visual Basic, etc. Also, there are examples of how to use this library in all of these programming languages. The pricing is pretty reasonable, starting from $39.95, for a personal license. The price might go up to $359.55 for an unlimited license, but most of the time an commercial license that costs $69.95 will do.
I hope that this library will come as handy for you as it came to me
Happy unbreakable licensing systems coding!
C# – Copying a file with the same name without overwriting
by edy_3dz on May.29, 2011, under Code snippets
I recently encountered a situation where I needed to copy some files over a location where files with the same name already existed, and overwriting them wasn’t an option. So, the following code snippet verifies if a file with the same name already exists, in case which it tries to put a number after the file’s name.
if (File.Exists(path + fileName)
{
int count = 1;
string[] fileNameSplit = fileName.Split(new char[] { '.' });
string ext = "." + fileNameSplit[fileNameSplit.Length - 1];
string prefix = fileName.Substring(0, fileName.Length - ext.Length);
while (File.Exists(path + fileName))
{
fileName = prefix + "(" + count.ToString() + ")" + ext;
count++;
}
File.Copy(source, path + fileName);
}
else
{
File.Copy(source, path + fileName);
}
I hope that you’ll find this helpful
How to import books to Aldiko
by edy_3dz on Feb.09, 2011, under Android
If you want to import your own ebooks to Aldiko, one of the best ebook readers on Android, this is what you have to do:
- Install some ebook management software on your PC, for example Calibre
- Import your ebooks and convert them to epub format
- Copy the epub files to your Android smartphone to phone_directory/ebooks/import ; if the folder doesn’t exists, create it
- Start Aldiko, press the menu key, select Import, and wait until the files are copied
Enjoy!
How to change GRUB default entry
by edy_3dz on Jan.31, 2011, under Linux
If you installed Linux over Windows, the bootloader will change to GNU GRUB, and it’s default entry will be the fresh installed Linux. If you don’t want that, and you want Windows to be the default entry, this is what you have to do:
- in GRUB, count which line is the entry which you want to make it default; the count starts from 0, so the second line is 1, the third is 2 etc.
- boot into Linux
- open Terminal
- run the following command: sudo gedit /boot/grub/grub.cfg
- if prompted, enter your password
- in gedit, find the following line: set default=”0″
- change “0″ to the line you want
- save the file, and exit.
- you’re done
If you don’t want to use GRUB at all, you can try EasyBCD (runs only on Windows), it’s a very good boot manager.