Sunday, October 28, 2018

Using ODBC with classic ASP in IIS

I have a website developed in classic ASP with ADO. Basically, the IIS in Windows 10 (64 Bits) still supports running ASP. You will able to run ASP pages after installing the IIS with ASP enabled.


Go to Control Panel > Program > Programs and Features > Turn Windows Features on or of > Internet Information Service > World Wide Web Services > ASP



It is now all set for ASP pages.

However, there is still one more thing to do for running a ASP page with ODBC connection. 

Working with 64-bit Systems

Unfortunately there are no 64-bit ODBC drivers, so on 64-bit systems you will have to run your applications in 32-bit mode. To do so, use the following steps:
  1. On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
  2. In the Connections pane, click Application Pools.
  3. Highlight the application pool for your application, then click Advanced Settings... in the Actions pane.
  4. In the Advanced Settings dialog, specify True for Enable 32-Bit Applications.
  5. Click OK to close the Advanced Settings dialog.


It is all done.








Friday, August 31, 2018

timedelta64[D] is always coerced to timedelta64[ns]

I encountered the same problem when calculating timedelta in a dataframe. It even ended with an error when I tried to call the days attribute. I am using Numpy 1.6.1
AttributeError: 'Series' object has no attribute 'days'
Problem
df_trans['DELTA'] = df_trans['DATE2'] - df_trans['DATE1']
print df_trans['DELTA'].dtype
timedelta64[ns]
print df_trans['DELTA']
0 8 days, 00:00:00
1 15 days, 00:00:00
2 5 days, 00:00:00
df_trans['DELTA'] = df_trans['DELTA'].astype('timedelta64[D]')
print df_trans['DELTA'].dtype
Name: DELTA, dtype: timedelta64[D]
print df_trans['DELTA']
0 8 days, 00:00:00
1 15 days, 00:00:00
2 5 days, 00:00:00
Nothing changed at all
print df_trans['DELTA'].days
AttributeError: 'Series' object has no attribute 'days'
I get rid of the problem by putting it in to a list for the conversion.
            Ss_timedelta = df_trans['DATE2'] - df_trans['DATE1']
            ls_timedelta = Ss_timedelta.values.astype('timedelta64[D]').tolist()
            for i in range(0, len(ls_timedelta)):
                    ls_timedelta[i] = ls_timedelta[i].days / 1000                        
            df_trans['HOLDDAYS'] = pd.Series(ls_timedelta)
Full discussion at GitHub
https://github.com/pydata/xarray/issues/1143

Tuesday, August 21, 2018

Download csv into DataFrame



import urllib
import urllib2
import csv
import pandas

#Calling this function will download a csv and return it in a dataframe
#21 AUG 2018
#David Tsang

def downloadasdataframe(url):

    req = urllib2.Request(url)
    response = urllib2.urlopen(req)
    reader = csv.reader(response)
    ls_data = list(reader)
    headers = ls_data[0]
    df_data = pandas.DataFrame.from_records(ls_data[1:], columns=headers)
    return df_data

Monday, August 6, 2018

Unable to find vcvarsall.bat - TA-lib




I hit the "Unable to find vcvarsall.bat" when installing TA-Lib using PIP. I am running Python 2.7.8 on Windows 10 64bits.

Here is how I get rid of the problem.

1. Downloading Microsoft Visual C++ Compiler for Python 2.7

https://www.microsoft.com/en-us/download/confirmation.aspx?id=44266

If you are running other version of python, you may seek help from this link

https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcvarsall-bat/

2. Upgrade the setup tools and wheel

pip install --upgrade pip setuptools wheel

check the setuptools version by using pip list.

upgraded my setuptools to 40.0.0


3. Install TA-LIB

pip install TA-LIB


Good to go!

Saturday, May 26, 2018

Fastest way to merge MOV files by using ffmpeg



There was full of sunshine over the week. I wanted to keep some of the video in my dash camera to celebrate summer. The weather was nicely recorded, but it was all saved in separate MOV files for 1 min each. I wanted to combine them into a single file for sharing over YouTube.

Obviously there were bunch of software of doing this, but many of them take too much time for processing. (My CPU fan worked damn hard to cool off). I didn't need to re-encode the files.
There must be some smarter way.

I turned out using ffmpeg. It gave exactly what I needed. The merge of 6 files (6 mins) only took about 1 - 2 mins. This was amazing fast compare with using other software. Thanks ffmpeg!


  1. Install ffmpeg (it is free)
  2. Copy all the mov files into a new blank folder
  3. Create a text file (files.txt) with all the files to be merged in order with the format like this

    file 'file1.mov'
    file 'file2.mov'
    file 'file3.mov'
    file 'file4.mov'
    file 'file5.mov'
    file 'file6.mov'
  4. Run this command in the folder
    ffmpeg -safe 0 -f concat -i files.txt -vcodec copy -acodec copy merged.MOV
  5. The output file merged.mov is ready.
Here is the batch script to do the whole thing nice and easy


@echo off
del merged.mov
del files.txt
for %%i In (*.mov) DO echo file '%%i' >>files.txt
ffmpeg -safe 0 -f concat -i files.txt -vcodec copy merged.MOV





What a lovely day!


Applying SMA10/20, SMA20/50 as trading signals

This is the comparison for results before and after applying SMA10/20 and SMA20/50 in the stock trader. Background Trading 3 stock ma...