Thursday, June 28, 2012

Inno Setup Command to Siliently Install vcredist

From the command line:
vcredist_x86.exe /q:a /c:"VCREDI~1.EXE /q:a /c:""msiexec /i vcredist.msi /qn"" "
In an Inno Setup script:
[Files]
Source: {src}\bin\vcredist_x86.exe; DestDir: {app}\bin\;

[Run]
Filename: {app}\bin\vcredist_x86.exe; Parameters: "/q:a /c:""VCREDI~3.EXE /q:a /c:""""msiexec /i vcredist.msi /qn"""" """; WorkingDir: {app}\bin; StatusMsg: Installing Micosoft's C/C++ runtime ...
References

Wednesday, June 20, 2012

Concatenate Multiple Files on the Windows Command Line


If the files are small in size, and you have a small number of them:
type file1.txt > out.txt
type file2.txt >> out.txt
type file3.txt >> out.txt
If you have a large number of large files, this might be a better option:
copy /b file1.dat+file2.dat+file3.dat out.dat /b
or:
copy /b *.dat out.dat /b

Thursday, November 24, 2011

Formula to Increment Month in Excel

Given A1 contains the starting date:
=DATE(YEAR(A1),MONTH(A1)+1,DAY(A1))
increments the month.

References

Adding/Subtracting n Month(s) To/From a Date, ozgrid.com
Excel forumula to add a month, Computing.Net

Thursday, December 30, 2010

Registry Setting to View HTML Source in IE6 with GVim

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\View Source Editor\Editor Name]
@="C:\\vim\\vim60\\gvim.exe"

Monday, December 27, 2010

Dump and Load a SVN Repository

These are the steps I took the last time I needed to move a Subversion (SVN) repository from one machine to another.

* Dump the repository to a file:
   svnadmin dump /path/to/repositories/projectrepo > projectrepo.dump
* If your repository is large, you might want to compress it using your favorite tool. This was on Linux, so:
   gzip projectrepo.dump
* Transfer the repository to the target machine.
* Decompress:
   gzip projectrepo.gump.gz
* Create an empty repository:
   svnadmin create /path/to/new/repositories/projectrepo
* Load the project repository:
   svnadmin load /path/to/new/repositories/projectrepo < projectrepo.dump

Friday, April 30, 2010

Recovering a Deleted Google Account

I just deleted one of my Google accounts by mistake. In panic, I done some web searching on how to restore it. This led me to this page, Why can't deleted Google accounts be recovered? . From there I was led to this form, I can't access my account. After filling in as much information as possible, and submitting the form, my account was restored approximately three hours later. Given that others seemed to have less success, I can only guess I succeed without too much trouble because I could recall some significant details about my account, in particular the date I created it, the password for it, the account creation verification number, and because I linked it to another Google account.

Where is Trac installed on Ubuntu Linux?

/usr/share/pyshared/trac/

Saturday, March 6, 2010

Links to Free Icons for Desktop and Web Applications

I'm always on the search for free icons for my software applications. Here are some icon web sites originally compiled by [1].

* Gallery and search:
* Icon search engines:
* Galleries:
And here are some icon sets I like and have liberal licenses (compiled from [2]).

* These are particularly good for standard sized buttons and toolbars on traditional desktop applications.
* A little more exotic, and perhaps more suitable for web pages or desktop applications with large buttons.
References

[1] Steven Snell, 11 Great Resources to Find Free Icons, Jan 31, 2010, http://designm.ag/resources/find-icons/
[2] Steven Snell, 35 of the Best Icon Sets for Web Designers, Dec 28, 2009, http://designm.ag/resources/icons-for-web-designers/

Wednesday, February 10, 2010

Ignore Warnings Emitted from Python

Launch python with the -W arguments.

python -W arg, where arg is action:message:category:module:lineno

This assumes python is on your path. If not, a full path is required, such as

C:\Python26\python -W arg

and on linux

#!/usr/bin/env python -W arg
Example for
#!/usr/bin/env python -W ignore::DeprecationWarning  name_of_script.py
#!/usr/bin/env python -W ignore::DeprecationWarning
 

C|> python -?
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-B     : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x
-c cmd : program passed in as string (terminates option list)
-d     : debug output from parser; also PYTHONDEBUG=x
-E     : ignore PYTHON* environment variables (such as PYTHONPATH)
-h     : print this help message and exit (also --help)
-i     : inspect interactively after running script; forces a prompt even
         if stdin does not appear to be a terminal; also PYTHONINSPECT=x
-m mod : run library module as a script (terminates option list)
-O     : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x
-OO    : remove doc-strings in addition to the -O optimizations
-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew
-s     : don't add user site directory to sys.path; also PYTHONNOUSERSITE
-S     : don't imply 'import site' on initialization
-t     : issue warnings about inconsistent tab usage (-tt: issue errors)
-u     : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x
         see man page for details on internal buffering relating to '-u'
-v     : verbose (trace import statements); also PYTHONVERBOSE=x
         can be supplied multiple times to increase verbosity
-V     : print the Python version number and exit (also --version)
-W arg : warning control; arg is action:message:category:module:lineno
-x     : skip first line of source, allowing use of non-Unix forms of #!cmd
-3     : warn about Python 3.x incompatibilities that 2to3 cannot trivially fix
file   : program read from script file
-      : program read from stdin (default; interactive mode if a tty)
arg ...: arguments passed to program in sys.argv[1:]

Other environment variables:
PYTHONSTARTUP: file executed on interactive startup (no default)
PYTHONPATH   : ';'-separated list of directories prefixed to the
               default module search path.  The result is sys.path.
PYTHONHOME   : alternate <prefix> directory (or <prefix>;<exec_prefix>).
               The default module search path uses <prefix>\lib.
PYTHONCASEOK : ignore case in 'import' statements (Windows).
PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.

Wednesday, February 3, 2010

Invalid File Name Characters (Windows, Linux)

On Windows, NTFS the following characters are not permitted [Filename, Microsoft KB 177506]:
* : < > ? \ / " |
Useful to also avoid:
[ ] = + , . : ;
From File Naming Conventions in Linux:
File names in Linux can contain any characters other than (1) a forward slash ( / ), which is reserved for use as the name of the root directory (i.e., the directory that contains all other directories and files) and as a directory separator, and (2) the null character (which is used to terminate segments of text). Spaces are permitted, although they are best avoided because they can be incompatible with legacy software in some cases.

Tuesday, January 26, 2010

Building a Windows Installer (wininst) for Django

The Django website does not have a Windows installer for Django (at least not for version 1.1). However, you can easily build an installer yourself.

Download django.<version>.tar.gz. Unpack (e.g. using 7-Zip), and run the following command in the directory where setup.py is located (the root of the unpacked project), say Django1.1.1.

python setup.py bdist --format=wininst

This will create the installer Django-<version>.win32.exe the dist directory.

Friday, January 22, 2010

Running Python's Distutil Created Wininst Installers (.exe) from the Commmand Line

I recently created an installer with Inno Setup that was used to launch a bunch of other installers. As such, I needed to, more or less, run those sub-installers from the command line during install and uninstall. The sub-installers were executables generated by Python's distutils using the wininst bdist command (i.e. "wininst" installers for Windows).

Given the wininst installer mypymodule.1.2.exe, to install, execute the command mypymodule.1.2.exe. This places the files Removemypymodule.exe and wininst-mypymodule.log in the root directory of the Python installation. To uninstall execute the command path/to/python/root/Removemypymodule.exe -u path/to/python/root/wininst-mypymodule.log.

Saturday, November 7, 2009

Updating Subversion's (SVN's) Repository Version

Sometimes it's necessary to manually upgrade Subversion's repository after upgrading Subversion (SVN) itself, such as to take advantage of a new feature. For example, I recently upgraded Subversion from 1.4 to 1.5, but did not upgrade my repository. This worked fine until I (inadvertently) tried to use a 1.5 feature. Using TortoiseSVN, I tried to merge a branch into the trunk using the 1.5 "merge tracking" feature, but because of the older repository version, I got an error something like "Error: Retrieval of mergeinfo unsupported by 'http://svnserver/myrepo'". Following are the steps I used to upgrade my repository.
  • Check the Subversion server software version:
    • Logon to the computer on which the repository server software is running. From the command line, execute svnadmin --version to get the server software version.
    • Execute svn --version to check the client software.
  • The server software version may be different from the repository version. To check the actual repository (layout) version number:
    • Navigate to <repository_dir>/db and open the file format. For SVN 1.5 compatibility, it should read something like:
        3
        layout shared 1000
      

      The key number here is 3. For SVN 1.4, this number is 2 and for SVN 1.6, 4.

  • To upgrade the repository, the server command svnadmin upgrade <repos_dir> is often sufficient (as is the case going from SVN 1.4 to 1.5). Here's the help documentation for this command:
      Upgrade the repository located at REPOS_PATH to the latest supported
      schema version.
    
      This functionality is provided as a convenience for repository
      administrators who wish to make use of new Subversion functionality
      without having to undertake a potentially costly full repository dump
      and load operation.  As such, the upgrade performs only the minimum
      amount of work needed to accomplish this while still maintaining the
      integrity of the repository.  It does not guarantee the most optimized
      repository state as a dump and subsequent load would.
    
    
  • Depending on which user did the update, it might be necessary to update the owner of the repository files. On Ubuntu Linux I had to issue the command sudo chmod -R www-data myrepo to change the owner of files from root back to www-data (the Apache user). Otherwise, trying to commit (remotely) to the repository will result in an error something like Can't open file '/path/to/repo/db/txn-current-lock': Permission denied

    Here's what others recommend:

    # chown -R www-data:www-data /var/svn/*
    # chmod -R 770 /var/svn/*
    
    assume that /var/svn/ is where are all your repositories
    

    (from svnform) and:

    $ sudo chown -R www-data:subversion myproject
    $ sudo chmod -R g+rws myproject
    

    (from ubuntu help).

Sunday, November 1, 2009

The "LdrpWalkImportDescriptor() failed to probe XXX.dll for its manifest, ntstatus 0xc0150002" Error and Manifiests

I got this error the other day:

error: LDR: LdrpWalkImportDescriptor() failed to probe QtCored4.dll for its manifest, ntstatus 0xc0150002

I did some googling, and here's what I found out:
  • The error may be a red herring, it's really a SideBySide DLL error. Look in the Event Viewer (see Control Panel, Administrative Tools) for the real error [Mombu, MSDN Social]. It turned out the Microsoft.VC80.DebugCRT DLL could not be found.
  • Usually occurs because of missing DLLs, or DLLs with the incorrect version number (as specified in the DLL's manifest) on the deployment machine.
  • Solutions:

    • Recompile the offending DLL(s) [Nabble, Bytes]
    • Recompile the offending DLL(s), but make sure the DLL project is configured to embed the manifest in the DLL. Have a look at the "dependentAssembly" tag in the generated YourDLLName.intermediate.manifest file. It must be the same as the "dependentAssembly" version in the manifest file generated for your EXE project. Make sure the same service packs are installed (i.e. same msvc) on the machine that built the DLL and the one that built the EXE [Trolltech Lists]
    • Recompile the offending DLL(s), or download and install MSVC Redist SP1 [OpenCV Wiki]

  • FAQ on manifests [CodeGuru]
Here's what worked for me: I checked the manifest file in the DLL that caused the error -- QtCore4d.dll in this example -- and noticed it required the Microsoft.VC80.DebugCRT DLL of a certain version. A colleague of mine compiled the DLL, so I had easy access to the manifest since an "intermediate" copy is stored in the DLL project's build directory. If that wasn't the case, I could use mt.exe from Microsoft to extract it from the DLL. I then inspected the manifest generated by Visual Studio when I compiled my EXE project. It turned out my EXE manifest required a version of the Microsoft.VC80.DebugCRT DLL that was older than that required by the QtCore4d.dll DLL, which means my machine had older DLLs than that required by QtCored4.dll. I simply applied a few Microsoft Visual Studio updates, recompiled my EXE project (not the DLL project), and the newly generated manifest showed the dependent DLL (Microsoft.VC80.DebugCRT) version to be the same as that in the QtCored4.dll manifest. Everything worked fine afterwards.

Sunday, October 18, 2009

Deploying a Django Application on Apache WSGI on Windows

Following are some notes I made during my last install of a Django based web application on an Apache web server running on Windows.

This assumes a Django application is being installed on a computer with no prior Django installs. I also describe a particular example, but the same steps can be applied to many applications, just replace my application specifics with your application specifics.

  • Install Python 2.6.
    • Run the MSI installer and install in C:\Programs.
    • Create the following environment variable: PYTHON_HOME=C:\Programs\Python26 (see System Properties/Advanced/Environment Variables).
    • Append the newly created variable to your PATH variable. Also append %PYTHON_HOME%\Scripts and %PYTHON_HOME%\Lib
    • Open a command line prompt, execute the command python. This should start the Python interactive interpreter.
  • Install Django 1.1.
    • Unpack the distribution (usually a tar.gz or .zip file) in some temporary directory. You might need to install (the free and excellent) 7-Zip for this.
    • Open a command line prompt in the directory Django was unpacked in, most likely Django-1.1.
    • Execute python setup.py install (or setup.py install).
    • To check if the install went correctly, you should be able to import the Django module in Python. Start Python from the command line, and execute:
        import django
        django.VERSION
                
  • Install Apache 2.2.
    • Runs the Windows MSI installer provided from the Apache web site.
    • From a web browser, enter the URL http://localhost. A valid web page hosted be Apache should be displayed.
  • Install the modwsgi module.
    • The module file will be named something like mod_wsgi-win32-ap22py26-2.6.so (http://code.google.com/p/modwsgi/downloads/list).
    • Copy it to the modules directory of the Apache installation. E.g., C:/Program Files/Apache Software Foundation/Apache2.2/modules.
    • Rename it to mod_wsgi.so.
    • Open Apache's http.conf file.
      • Add the line LoadModule wsgi_module modules/mod_wsgi.so before all the other LoadModule entries.
      • Configure Apache for your Django project by adding the following to end of http.conf:
        # Static content
        
        Alias /media/ C:/Programs/TestDjango/mysite/media/
        
        <Directory C:/Programs/TestDjango/mysite/media/>
        Order deny,allow
        Allow from all
        </Directory>
        
        # Django dynamic content
        
        WSGIScriptAlias / C:/Programs/TestDjango/mysite/apache/django.wsgi
        
        <Directory C:/Programs/TestDjango/mysite/apache>
        Order deny,allow
        Allow from all
        </Directory>
        

        Where TestDjango is the Django project root. The paths below TestDjango will be specific to your project. This configuration serves all static media via the URL space /media/ and all the rest via WSGI and Django.

      • You may need to create the django.wsgi script if it's not already created. To do so, create a file django.wsgi and add the following to it:
            import os
            import sys
        
            sys.path.append('C:/Programs/TestDjango')
            os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
        
            import django.core.handlers.wsgi
            application = django.core.handlers.wsgi.WSGIHandler()
                      

        Note that sys.path.append('C:/Programs/TestDjango') is only needed if your project (TestDjango) is not on Python's path, PYTHONPATH.

    • Restart Apache. For this you can use the Apache Service Monitor from the taskbar tray.
    • From a web browser, attempt to hit the Django application's web page, such as http://localhost/mysite.

Thursday, October 15, 2009

Software Engineering Code of Ethics and Professional Practice

Following is the short "preamble" version of the IEEE-CS and ACM endorsed Software Engineering Code of Ethics and Professional Practice (also found on the online ethics site, as a PDF, and at the ACM site):
Software Engineering Code of Ethics and Professional Practice

Software engineers shall commit themselves to making the analysis, specification, design, development, testing and maintenance of software a beneficial and respected profession. In accordance with their commitment to the health, safety and welfare of the public, software engineers shall adhere to the following Eight Principles:

1. PUBLIC - Software engineers shall act consistently with the public interest.
2. CLIENT AND EMPLOYER - Software engineers shall act in a manner that is in the best interests of their client and employer consistent with the public interest.
3. PRODUCT - Software engineers shall ensure that their products and related modifications meet the highest professional standards possible.
4. JUDGMENT - Software engineers shall maintain integrity and independence in their professional judgment.
5. MANAGEMENT - Software engineering managers and leaders shall subscribe to and promote an ethical approach to the management of software development and maintenance.
6. PROFESSION - Software engineers shall advance the integrity and reputation of the profession consistent with the public interest.
7. COLLEAGUES - Software engineers shall be fair to and supportive of their colleagues.
8. SELF - Software engineers shall participate in lifelong learning regarding the practice of their profession and shall promote an ethical approach to the practice of the profession.

IEEE-CS/ACM Joint Task Force on Software Engineering Ethics and Professional Practices (version 5.2)

Wednesday, October 14, 2009

The Duct Tape Programmer Posts (Joel and Bob)

What is the Duct Tape Programmer? He is the smart, pragmatic Keep It Simple Stupid (KISS) software developer, whose top priority is to ship as soon as possible a "good enough" product (but not garbage) that satisfies the users needs. At least that's my summary from the original "The Duct Tape Programmer" blog post, by Joel Spolsky and Uncle Bob's comments on that post.

Some main points from both of these posts:
  • Keep it simple. Using advanced, usually more complicated, tools and designs (e.g. COM, multithreading, C++, templates) only when absolutely necessary. Be careful of over using a tool and of over engineering the solution.
  • Good (smart) software developers know when the aforementioned tools are needed and when to avoid them, and are not afraid to make the decision to use or not use them, or assert there views on the matter.
  • Be pragmatic: "A 50%-good solution that people actually have solves more problems and survives longer than a 99% solution that nobody has" [Joel].
  • One of the most important, perhaps the most important, feature of a (software) product is to ship the product as soon as possible. "It's great to rewrite your code and make it cleaner and by the third time it'll actually be pretty. But that's not the point --- you're not here to write code; you're here to ship products" [Jamie Zawinski, from Joel]. Nevertheless, don't ship garbage: "The programmer who spends weeks building the perfect structure does just as much harm to the project as the programmer who hacks a bunch of crap together. Neither have struck the balance that's required" [Bob]

Here are some follow-ups by Bob:
Echoes from the Stone Age
TDD Derangement Syndrome

Saturday, September 19, 2009

C++: Interoperability of Libraries Compiled by Different Compilers

Is it possible to link to libraries compiled with different compilers? I get asked this question a lot. Usually I ramble about this or that; I won't do that here. Rather, here's a nice concise answer from Rob K on stackoverflow. Quote:
The above quote is specific to MinGW and Visual Studio, but in general the same rules apply between any two compilers. Speaking of MinGW, the Mixing Compiler page on MinGW's Wiki (and the older page here) also address this issue.

Here are more resources:



Sunday, September 13, 2009

PyDev: Workaround for the Undefined Class/Static Attribute Error

PyDev will incorrectly identify class (static) attributes as "undefined" if they are dynamically added to a class. Consider the following class:
class Quantity:
    def __init__(self, name, unit):
        self.name = name
        self.unit = unit

# Add some class/static attributes after class creation

Quantity.VOLTAGE = Quantity("Voltage", "volts")
Quantity.COUNTS = Quantity("Counts" , "counts")
Now, if we use a class attribute, such as VOLTAGE, PyDev will flag it with an "Undefined variable from import: VOLTAGE" error, even though it is valid.
print(Quantity.VOLTAGE) # <-- Flagged as an error
To work around this, add the annotation @DynamicAttrs to the class's docstring, as follows:
class Quantity:
    """ @DynamicAttrs """
    def __init__(self, name, unit):
        self.name = name
        self.unit = unit
Reference: Fabio on PyDev's user list.

Joel Spolsky's Talk on Being Number One (Business of Software)

Can be viewed here. Some main points I captured from the presentation:
  • Make people happy.
    • Put the user in control.
    • Positive feedback.
  • Obsess over aesthetics.
    • Skins are not the answer.
    • Modernist architecture is not the answer (decadence is still important in the software industry).
    • Not the same as being pretty; capture and convey some message or theme.
  • Observe the culture code.
    • If necessary, define one and develop it.
    • Care about it, embrace it.