Wednesday, 21 June 2017
Alchemy app released (in beta)
I've finally published the beta version of Alchemy on the play store. It's still in beta, but it seems to be working well. Give it a shot if you're looking for a different way to donate to charity!
Tuesday, 20 June 2017
Memory leak with android linearlayout and Picasso
I recently ran into an issue using Picasso with Android's linearlayout. I was using Picasso to load images from a url into a linearlayout, handling errors with Picasso's build object as follows:
Picasso.Builder builder = new Picasso.Builder(this.mContext);
builder.listener(new Picasso.Listener()
{
@Override
public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception)
{
picasso.load(mThumbIds[0]).into(imageView); // on failure just load the default image
}
});
Picasso picasso= builder.build();
I was recycling the images correctly with convertView (using a viewholder class), but I couldn't track down the source of a memory leak which occured every time a new image was loaded - eventually causing the app to crash. The leak however when away when I stopped using Picasso's builder, instead just using a simple try catch setup.
try{
Picasso.with(mContext).load(logo_url).placeholder(R.drawable.alchemy).into(holder.imageView);
}
catch (Throwable e){
Picasso.with(mContext).load(R.drawable.alchemy).into(holder.imageView);
}
Sunday, 28 May 2017
Installing OpenCV3 for Python 3 on Windows
I need to use python for face recognition as part of the server for a charity app I'm working on. The app is supposed to show charity logos, but in the case of smaller charities, sometimes the google custom search I use to search for the logos returns instead a picture with a person in it. I need to identify cases where this happens and use a placeholder image instead.
My first attempt to install opencv was through pip from anaconda:
pip install opencv-python
However this gave me the following error when I tried to import cv2:
ImportError: DLL load failed: The specified module could not be found.
I uninstalled the anaconda version and found a 64 bit wheel of opencv for python 3.6 at http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv. Downloading this and installing it with pip worked perfectly. I don't know why the original error occured, but it looks like python 3 support might not be great with opencv at the moment.
However this gave me the following error when I tried to import cv2:
ImportError: DLL load failed: The specified module could not be found.
I uninstalled the anaconda version and found a 64 bit wheel of opencv for python 3.6 at http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv. Downloading this and installing it with pip worked perfectly. I don't know why the original error occured, but it looks like python 3 support might not be great with opencv at the moment.
Thursday, 18 May 2017
Using Python 3 to extract files from an encrypted archive with a password
Recently I needed to use python to extract the contents of a password-protected zip archive and I came across a few issues I thought would be good to document.
Python has a build in zipfile library that is really good at handling zip files, but unfortunately has a few limitations when it comes to encrypted zip files. This is how Python3 can be used to extract a file from an encrypted zip archive:
The first issue that I came across was some unclear documentation for the "open" method of zipfile in Python 3. The open method uses the "pwd" argument to pass the password for the file, but in Python 3 you need to convert this to bytes before calling open. Unfortunately, the library only seems to support CRC-32 based encryption - meaning that the default linux zip encryption will work, but AES will not. I was also unable to get this to work with 7zip and WinZip.
Python has a build in zipfile library that is really good at handling zip files, but unfortunately has a few limitations when it comes to encrypted zip files. This is how Python3 can be used to extract a file from an encrypted zip archive:
The first issue that I came across was some unclear documentation for the "open" method of zipfile in Python 3. The open method uses the "pwd" argument to pass the password for the file, but in Python 3 you need to convert this to bytes before calling open. Unfortunately, the library only seems to support CRC-32 based encryption - meaning that the default linux zip encryption will work, but AES will not. I was also unable to get this to work with 7zip and WinZip.
Saturday, 22 April 2017
New website design
It had been a while since I updated my website so I found a new template from http://themes.3rdwavemedia.com and redesigned the whole site. I particularly like the github and blog integration with the new theme - hopefully that will encourage me to write more here too, especially as I'm working on the new Alchemy app.
Tuesday, 19 July 2016
New LOFAR baseline comparison tool
I've written a new tool for comparing the lengths of different baselines to a single LOFAR station. It should be useful when looking for delay and rate solutions with FRING or a similar task. The tool is located at http://www.colmcoughlan.com/lofar.html.
Tuesday, 24 May 2016
Installing AIPS on Ubuntu 16.04
I've recently installed AIPS (version 31DEC16) on Ubuntu 16.04. Here are my notes on the installation experience. Due to recent compiler work on AIPS this was a much better experience than on recent new versions of Ubuntu. Note that this was a "text" (compile-from-source) install - if you just need to use AIPS you will likely get a faster experience using the pre-compiled binaries available from the binary installation (see http://www.aips.nrao.edu/dec16.shtml for full instructions)
As before, the Ubuntu dependencies are:
libx11-dev and its dependancies
x11proto-xext-dev
libxext-dev
libxpm-dev
libncurses5-dev
libncursesw5-dev
libbsd-dev
libedit-dev
I use gcc and gfortran to compile AIPS - you need to specify their location in the AIPS installer (/usr/bin/gfortran is both the fortran compiler and the linker for me, while /usr/bin/gcc compiles for C). I also have trouble with the fortran compiler flags -axWPT and -ip options, so I turn them off both for gfortran and gcc. XAS isn't built using these directives however, so you need to go to Y/SERVERS and edit XAS.SHR to remove the use of the axWPT and -ip flags when compiling the TV server.
A new problem with this combination of Ubuntu and AIPS is an errant "-c" ending up in the link command for making XAS after XAS.SHR is run. This means you will get an error that XAS failed to link, but if you open the makefile at Y/SERVERS/XAS/makefile and remove the "-c" option from the LOCALOPTS_LNX64 variable, then you can just type "make" to correctly make and set up XAS (I did this in a separate terminal while the rest of the installation was proceeding). Make sure the executable xas file has been successfully moved to LNX64/LOAD.
Make sure to add
sssin 5000/tcp SSSIN # AIPS TV
ssslock 5002/tcp SSSLOCK # AIPS TV Lock
msgserv 5008/tcp MSGSERV # AIPS Message Server
tekserv 5009/tcp TEKSERV # AIPS TekServer
aipsmt0 5010/tcp AIPSMT0
aipsmt1 5011/tcp AIPSMT1
aipsmt2 5012/tcp AIPSMT2
aipsmt3 5013/tcp AIPSMT3
aipsmt4 5014/tcp AIPSMT4
aipsmt5 5015/tcp AIPSMT5
aipsmt6 5016/tcp AIPSMT6
aipsmt7 5017/tcp AIPSMT7
to /etc/services to get AIPS to run properly. To do this you may need to open the file as root.
One last thing - add the aips path to your profile so you can run it straight from the terminal. For me the line was ". /home/colm/aips/LOGIN.SH; $CDTST". The CDTST bit at the end is needed if you intend to compile custom AIPS tasks.
As before, the Ubuntu dependencies are:
libx11-dev and its dependancies
x11proto-xext-dev
libxext-dev
libxpm-dev
libncurses5-dev
libncursesw5-dev
libbsd-dev
libedit-dev
I use gcc and gfortran to compile AIPS - you need to specify their location in the AIPS installer (/usr/bin/gfortran is both the fortran compiler and the linker for me, while /usr/bin/gcc compiles for C). I also have trouble with the fortran compiler flags -axWPT and -ip options, so I turn them off both for gfortran and gcc. XAS isn't built using these directives however, so you need to go to Y/SERVERS and edit XAS.SHR to remove the use of the axWPT and -ip flags when compiling the TV server.
A new problem with this combination of Ubuntu and AIPS is an errant "-c" ending up in the link command for making XAS after XAS.SHR is run. This means you will get an error that XAS failed to link, but if you open the makefile at Y/SERVERS/XAS/makefile and remove the "-c" option from the LOCALOPTS_LNX64 variable, then you can just type "make" to correctly make and set up XAS (I did this in a separate terminal while the rest of the installation was proceeding). Make sure the executable xas file has been successfully moved to LNX64/LOAD.
Make sure to add
sssin 5000/tcp SSSIN # AIPS TV
ssslock 5002/tcp SSSLOCK # AIPS TV Lock
msgserv 5008/tcp MSGSERV # AIPS Message Server
tekserv 5009/tcp TEKSERV # AIPS TekServer
aipsmt0 5010/tcp AIPSMT0
aipsmt1 5011/tcp AIPSMT1
aipsmt2 5012/tcp AIPSMT2
aipsmt3 5013/tcp AIPSMT3
aipsmt4 5014/tcp AIPSMT4
aipsmt5 5015/tcp AIPSMT5
aipsmt6 5016/tcp AIPSMT6
aipsmt7 5017/tcp AIPSMT7
to /etc/services to get AIPS to run properly. To do this you may need to open the file as root.
One last thing - add the aips path to your profile so you can run it straight from the terminal. For me the line was ". /home/colm/aips/LOGIN.SH; $CDTST". The CDTST bit at the end is needed if you intend to compile custom AIPS tasks.
Subscribe to:
Posts (Atom)
HTML form won't submit (Angular)
It turns out if you mix normal HTML forms with Angular ones (i.e. using FormsModule) Angular will disable the default behaviour of forms on...
-
It turns out if you mix normal HTML forms with Angular ones (i.e. using FormsModule) Angular will disable the default behaviour of forms on...
-
Recently while working on an Angular web app operating with CORS on localhost against a SpringBoot server I had an issue where my GET reque...
-
Recently I needed to use python to extract the contents of a password-protected zip archive and I came across a few issues I thought would b...