Saturday, December 27, 2014

Activate/Enable Sound in Windows 7 Safemode

Here are the sequence of steps. For full steps refer the reference [1].

  1. Run (Win key+R key) regedit
  2. Press Ctrl+F
    1. Make sure "Keys", "Values", and "Data" are all selected
    2. Type in Sound, video and game controllers
    3. Click [Find Next]
  3. Take note of the branch address in the status bar at the bottom (it will be something like HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4D36E96C-E325-11CE-BFC1-09002BE10318})
  4. Copy the device-driver GUID (the long numeric part between braces) and paste it somewhere like Notepad
  5. Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SafeBoot\Network
  6. Create a new key (right-click, select New → Key)
    1. Copy the GUID you saved and paste it into the key name
    2. Edit the (Default) value and type Sound, video and game controllers
  7. Create several new keys (under Network) called AudioEndpointBuilder, MMCSS and Audiosrv
  8. Edit the (Default) values of each of the new keys and type Service
  9. Reboot (you’ll boot into safe-mode)
  10. Open the Services snap-in (Win key+R key → services.msc)
    1. Search for "Multimedia Class Scheduler", "Windows Audio Endpoint Builder", and "Windows Audio Service services", and check if they are automatically turned on (they should be). If not start them. 
References:
1. http://superuser.com/questions/354325/how-to-enable-audio-in-safe-mode

Thursday, October 30, 2014

Latex: Underlining text along with adjacent white space

To underline text in latex we use \underline{...}.
In cases when we need to underline text and the adjoining whitespace (before and after the text), like in situations of having a filled form, we can use the \makebox command as below:

\underline{\makebox[2.5in][l]{Jane Doe}}

Reference:
1. http://www.latex-community.org/forum/viewtopic.php?f=44&t=5162

Saturday, October 11, 2014

Latex: Centering text in a table row when there is a image

When you are embedding images in a Latex table, often the text gets aligned to the bottom of the row, and the image decides the height of the row. To align the text in the columns to be vertically centered we have two options, as discussed in references [1][2][3][4].

Solution 1

Vertically centering cell entries is possible via the m{<width>} column type from the array package. Horizontal centering is obtained by prepending the column entries with \centering\arraybackslash (also supported by array). As described in [2], you can defines a new column type M which does all of the above:
\usepackage{array}
\newcolumntype{M}{>{\centering\arraybackslash}m{\dimexpr.25\linewidth-2\tabcolsep}}
And use can use it in a table as:
\begin{tabular}{|M|M|M|M|}

Or as described in [4], we can also define a new column type C as follows:
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}

Solution 2

Another simpler solution is to raise the baseline of the image, as text in a row is aligned to the image's baseline. The baseline of an image is at the bottom. You could use \raisebox to shift it up. Use half of \height, which stands for the height of the box to be raised.
\raisebox{-.5\height}{\includegraphics{some_picture}}

You can use it in a table as follows:
\begin{tabular}{lll}
\raisebox{-.5\height}{\includegraphics[scale=0.25]{example-image}} & text & text\\
\end{tabular}

References:
1. http://stackoverflow.com/questions/1357798/how-to-center-cell-contents-of-a-latex-table-whose-columns-have-fixed-widths
2. http://tex.stackexchange.com/questions/46386/vertically-center-cells-of-a-table
3. http://tex.stackexchange.com/questions/19080/how-to-vertically-center-text-with-an-image-in-the-same-row-of-a-table
4. http://www.latex-community.org/forum/viewtopic.php?f=45&t=15908

Latex: Image in a table overlaps the row separator line

When embedding images in Latex tables, you may find that the images will overlap with the horizontal line above its row. Like described by Stefan Kottwitz in [1], it looks like:

To avoid this problem, the easiest solution is to use the "trim" parameter of the includegraphics command. The trim option takes four lengths as argument, specifying the amount to remove or add to each side. trim= 1 2 3 4 would "crop" the picture by 1bp at the left, 2bp at the bottom, 3bp on the right and 4bp at the top.

To add some spacing at the top, we can use a negative value as shown below:
\includegraphics[trim=0 0 0 -5]{figure.jpg}

In case multiple parameters are to be specified, such as "width", we can do it as follows:
\includegraphics[trim=0 0 0 -5,width=0.2\textwidth]{figure.jpg}

References:
1. http://tex.stackexchange.com/questions/41788/image-in-table-covers-horizontal-line-above-it

Saturday, August 16, 2014

Using embedded fonts in eps graphs generated using gnuplot

When submitting camera ready versions to conferences/journals, you might come across a requirement where all the fonts (including those used in the EPS/PDF figures) should be embedded in the PDF.

To use embedded fonts in graphs generated using gnuplot, we need to use the font file used by MIKTEX (on windows) or its equivalent on Linux. In the below example, we use the "NimbusSanL-Regu" embedded font available in the ".pfb" file in the fonts folder in the Miktex installation directory (something like ...\Program Files\MiKTeX 2.7\fonts\type1\urw\helvetic\).

set terminal postscript eps enhanced "NimbusSanL-Regu" 12 fontfile "uhvr8a.pfb"
set output 'filename.eps'

When using the ".pfb" file you might come across an error in Gnuplot like:
"Automatic font conversion pfb->pfa not supported"

For this you can convert the pfb file to pfa file using tools like "pfbtops" (supports on-the-fly conversion to .pfa type) or "pfb2pfa" (if on-the-fly is not needed and you need the .pfa file output).  There is also an online service (http://everythingfonts.com/pfb-to-pfa) that can generate the pfa file.

Once the .pfa file is generated, you can use it in the same format.
set terminal postscript eps enhanced "NimbusSanL-Regu" 12 fontfile "uhvr8a.pfa"

References:
1. http://www.cepe.ethz.ch/howtodos/embed_fonts
2. http://everythingfonts.com/pfb-to-pfa
3. http://gnuplot.sourceforge.net/docs_4.2/node413.html

Thursday, July 24, 2014

Latex 'pdfpagelabels' turned off when using Hyperref

I received the following error when using ACM's sig-alternate.cls style file and using the PDFLatex command.

Error:
Package hyperref Warning: Option `pdfpagelabels' is turned off
hyperref because \thepage is undefined.

That seems to be caused by an update of the hyperref package. The workaround is to switch this option off.
Instead of using:
\usepackage{hyperref}


Use:
\PassOptionsToPackage{pdfpagelabels=true}{hyperref}

References:
1. http://www.latex-community.org/forum/viewtopic.php?f=5&t=162

Wednesday, July 16, 2014

Gnuplot pdf terminal dashed lines

To set pdf terminal in Gnuplot, check if the output of command "print GPVAL_TERMINALS" contains "pdfcairo" listed. If yes, then you can set the terminal output as PDF using the command

set terminal pdf
set output 'out.pdf'

To enables dashed lines when using PDF terminal in gnuplot, as pointed out in reference [1], set the terminal using the command below

set terminal pdf monochrome dashed
set output 'out.pdf'

References:
1. http://theletterpsi.blogspot.com/2010/11/setting-dashed-line-style-on-pdf.html
2. http://stackoverflow.com/questions/14004797/gnuplot-pdf-output

Wednesday, July 9, 2014

English Word Frequency Lists

Many might have come across a requirement for reasonable sized English word frequency lists. Here is one good and free word frequency list based on  British National Corpus (BNC). This post is just a pointer to the real resource (Reference 1), but I will copy some text from the reference describing the details about the file structure.

-----------------------------------------------
These are all available in 6 forms:
  • sorted alphabetically ("al") or by frequency (highest frequency first) ("num");
  • the complete lists, or a smaller file containing only those items occurring over five times (suffix "o5");
  • all lists are available compressed using gzip (".gz"). The
o5 lists are also available uncompressed (no suffix). The frequencies are for <CLAWS-word, POS> pairs.
For a list and brief descriptions of CLAWS POS-tags, see here.

The format is: four fields, separated by spaces.
 1: frequency
 2: word
 3: pos
 4: number of files the word occurs in
For non-orthographic words, spaces are replaced by underscore, giving eg "in_spite_of".
Lists are provided for the complete BNC (all), and for three subsets, as below:
 cg 'context-governed' spoken material    
  (eg meetings, lectures etc)  6.2M tokens,  79,906 types
 demog   'demographic' spoken material        
  (eg conversation)      4.2M tokens,  54,652 types
        written                             89.7M tokens, 921,074 types
 all                             100.1M tokens, 939,028 types
File sizes in MB ("al" and "num" variants all the same size) are:
  all uncompressed .gz o5 o5.gz
-------------------------------------------------------------
all  18.1   4.8 4.0 1.32
cg   1.4   0.39 0.43 0.15
demog   0.9   0.26 0.25 0.09 
written  17.8   4.7 3.9 1.30
-------------------------------------------------------------
For all.al.gz click here
For all.al.o5 click here
For all.al.o5.gz click here
For all.num.gz click here
For all.num.o5 click here
For all.num.o5.gz click here
For written.al.gz click here
For written.al.o5 click here
For written.al.o5.gz click here
For written.num.gz click here
For written.num.o5 click here
For written.num.o5.gz click here
For cg.al.gz click here
For cg.al.o5 click here
For cg.al.o5.gz click here
For cg.num.gz click here
For cg.num.o5 click here
For cg.num.o5.gz click here
For demog.al.gz click here
For demog.al.o5 click here
For demog.al.o5.gz click here
For demog.num.gz click here
For demog.num.o5 click here
For demog.num.o5.gz click here

References:
1. http://www.kilgarriff.co.uk/bnc-readme.html

Sunday, June 29, 2014

Python Multiprocess programming - A Pool of Workers


Python's Global Interpreter Lock prevents multithreading to actually be parallelizable, and sometimes making it much slower than single thread version. To obtain true parallelism, we need to use multiple processes.

Here is the code to start a certain number of processes, and pass tasks to them through a queue. The done_queue.get() blocking function ensures that the parent process remains active until the child threads finish everything. Once we obtain all the results, we stop the child processes using the "STOP" input (as even the child processes also block on input.get()).


import time
import random

from multiprocessing import Process, Queue, current_process, freeze_support

#
# Function run by worker processes
#

def worker(input, output):
    for func, args in iter(input.get, 'STOP'):
        result = calculate(func, args)
        output.put(result)

#
# Function used to calculate result
#

def calculate(func, args):
    result = func(*args)
    return '%s says that %s%s = %s' % \
        (current_process().name, func.__name__, args, result)

#
# Functions referenced by tasks
#

def mul(a, b):
    time.sleep(2*random.random())
    return a * b

def plus(a, b):
    time.sleep(2*random.random())
    return a + b

#
#
#

def test():
    NUMBER_OF_PROCESSES = 8
    TASKS1 = [(mul, (i, 7)) for i in range(20)]
    TASKS2 = [(plus, (i, 8)) for i in range(10)]

    # Create queues
    task_queue = Queue()
    done_queue = Queue()

    # Submit tasks
    for task in TASKS1:
        task_queue.put(task)

    # Start worker processes
    for i in range(NUMBER_OF_PROCESSES):
        Process(target=worker, args=(task_queue, done_queue)).start()

    # Get and print results
    print 'Unordered results:'
    for i in range(len(TASKS1)):
        print '\t', done_queue.get()

    # Add more tasks using `put()`
    for task in TASKS2:
        task_queue.put(task)

    # Get and print some more results
    for i in range(len(TASKS2)):
        print '\t', done_queue.get()

    # Tell child processes to stop
    for i in range(NUMBER_OF_PROCESSES):
        task_queue.put('STOP')


if __name__ == '__main__':
    freeze_support()
    test()

References: 
1. https://docs.python.org/dev/library/multiprocessing.html

Monday, April 28, 2014

Microsoft Excel Bar/Column Chart Patterns

It is possible to create GNUPlot style bar charts with patterns (shown below)  in Excel.


As discussed in Reference 2, for Excel 2007 you need to download the excel macro file "Pattern Fill Add-In". The usage instructions are provided in Reference 1.

References:
1. http://www.andypope.info/charts/patternfills.htm
2. http://answers.microsoft.com/en-us/office/forum/office_2007-excel/excel-2007-bar-chart-shading/99bab79a-e600-4bbe-a08e-448363d3173d

Microsoft Excel Clustered-Stacked Column/Bar Chart

We can create clustered-stacked column/bar charts -- like those shown below (taken from Reference 1) -- in Excel. It is doable, but the process involves many steps. Follow the instructions in Reference 1.


At one point, the instructions say - "Copy the range, and use paste special to add this data to the chart as a new series", for this if using Excel 2007 you need to click the 'Home' tab on the ribbon, click the 'Paste' drop-down arrow and choose 'Paste Special'.

References:
1. http://peltiertech.com/WordPress/clustered-stacked-column-bar-charts/
2. http://www.mrexcel.com/forum/excel-questions/559998-charts-add-new-data-copy-paste-special.html

Tuesday, April 8, 2014

Changing Windows Internet time synchronization frequency

You might come across situations when you need multiple Windows machines to have their times synchronized. You could setup time synchronization protocols between the machines, making one as the master and the others as slaves.

An easier alternative is to sync all the machine times to Internet times - the NIST time or Windows server time available by default in the Date & Time settings. Once you sync the machines with the Internet time, the machines might start drifting away over a period. Hence Windows periodically syncs the times with the Internet time; however, the default sync duration ranges from few days to weeks.

You can make the time sync happen much more frequently - like few hours. To do this, you need to make system registry changes. The following instructions are for Windows XP machine; for other versions, the process might be similar.

1. Go to Start-> Run and type "regedit" to open the registry settings.

2. Navigate to the following in the Registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient

3. The parameter you need to change is SpecialPollInterval
Right click on 'SpecialPollInterval' in the right hand column and select Modify>Decimal. The decimal number is in seconds. For example, you can set it to 86400 to mean 24 hours.

NOTE: Please backup the Registry beforehand to avoid any issues later (I do not know how this can be done).

Reference:
1. http://www.tomshardware.com/forum/55562-45-changing-frequency-internet-time-synchronisation 

Sunday, April 6, 2014

English words present in dictionary for Python use

A good resource of English words available in English dictionary is WordNet by Princeton University. Though its primary usage is not for getting the list of English words and their meanings, you can still get that information from WordNet.

Either you could download the WordNet database and do the parsing yourself (or using other pre-existing Python scripts), or use the NLTK natural language processing toolkit in Python. The toolkit provides instructions for using wordnet at WordNet Interface.

You could also use the PyEnchant spell checking library available for Python. Using this you can check whether a word is acceptable as per a specific English dictionary, though you won't get the word meanings.

As stated in [2], the word coverage in WordNet is not complete, but it is very useful. Depending on the use case, one option can be preferred over the other.

References:
1. http://www.velvetcache.org/2010/03/01/looking-up-words-in-a-dictionary-using-python
2. http://stackoverflow.com/questions/3788870/how-to-check-if-a-word-is-an-english-word-with-python
3. http://www.nltk.org/howto/wordnet.html
4. http://pythonhosted.org/pyenchant/

Tuesday, January 28, 2014

Delete "Not Existing" files in Windows 7

Sometimes even after we delete a file or move it, its ghost copy might still remain in the original folder. The ghost file might have been created due to a race condition. When we try to delete the file, we get an error stating "Cannot Delete the File, The file does not exist".

In that case, use a command prompt in windows and navigate to the folder. Use "dir /x" command to see if the ghost file is being listed. As per the reference [1], if you can identify the 8.3 format filename in the output, you can use it to delete the file using "del <filename>" command from the prompt. An easier way would be to use wildcard filename to delete the ghost file. The wildcard command might look like " del *file.txt".


References:
1. http://superuser.com/questions/388860/cant-delete-files-that-do-not-exist-but-appear-in-my-download-directory