Monday 28 August 2023
HTML form won't submit (Angular)
Saturday 6 May 2023
Why won't my Angular app include cookies in a POST request?
Recently while working on an Angular web app operating with CORS on localhost against a SpringBoot server I had an issue where my GET requests were fine, but the POST requests (in this case for logout) did not include a cookie. At first I though I had some kind of problem with my CORS config - but this was fine:
var corsConfig = new CorsConfiguration();
corsConfig.setAllowedOriginPatterns(List.of(
"http://localhost:4200",
"http://localhost:8080"));
corsConfig.applyPermitDefaultValues();
corsConfig.setAllowCredentials(true);
It turns out the signature for the POST request use by Angular is slightly different! The second argument is actually for a body. So in my case:
return this.http.post<void>(this.logoutUrl, null, {withCredentials: true});
This might help someone who is starting to question their understanding of CORS (again)
Sunday 24 May 2020
AWS Keyspaces - Managed Cassandra review
- TTL (automatic time-based record expiry) is currently not supported by AWS keyspaces. This alone makes it difficult to port standard Cassandra data models over.
- No cross-region support (yet)
- 1 mb row size limit (similar to DyanmoDb's 400kb item limit). This may be related to the fact that Keyspaces is more closely related to DynamoDb than true Cassandra (as noted by Scilla at https://www.scylladb.com/2019/12/04/managed-cassandra-on-aws-our-take/)
Sunday 13 January 2019
Sending an SMS via Intent in Android
I applied for an excemption for Alchemy, but this wasn't granted. This is understandable I think - Android security has a lot of issues, and excess permissions is definitely one of them - Alchemy is a good citizen and only interacts with a single SMS number, but a malicious applicaiton could easily use the same permissions for nefarious purposes.
Without an exemption, there was no choice but to update Alchemy to avoid using SmsManager. This meant instead requesting an existing SMS app to send the donation SMS instead - via an intent. It took me some time to find out exactly how to do this, but the code required to pre-populate an SMS for a user to send is
Uri uri = Uri.parse("smsto:" + charity.getNumber()); Intent intent = new Intent(Intent.ACTION_SENDTO, uri); intent.setData(uri); intent.putExtra("address", charity.getNumber()); intent.putExtra("sms_body", keyword); intent.putExtra("exit_on_sent", true); if (intent.resolveActivity(getPackageManager()) != null) { startActivityForResult(intent, 1); donationViewModel.recordDonation(this.donations, charity.getName(), smsKeywordToDonation(charity.getCost(keyword))); } else { Toast.makeText(this, "No SMS provider found", Toast.LENGTH_SHORT).show(); }
The full code can be found on Github. Note that, unfortunately, SMS applications generally do not seem to respect the "exit on sent" request, so the user must navigate back manually. A bonus for this change is that Alchemy now doesn't require any additional permissions from the user. Previous donations must now be stored in Alchemy itself, instead of using SMS history. This may cause some loss of data in the migration, but should result in more robust behaviour from now on.
Sunday 4 March 2018
Faster python for data science and scientific computing
Scientific computing and HPC developers will probably be familiar with Intel's C/C++ compiler suite, which can be used to compile your C, C++ and Fortran code instead of the free GCC compilers and can often result in significant performance improvements without changing a single line. Further improvements can be made by swapping out (generally fantastic) open source C maths libraries such as ATLAS or BLAS for equivalent functionality in Intels MKL (Math Kernal Language). Again - this is usually simply a matter of compiling your existing code against Intel's library and can result in very impressive speed gains for very little work.
What has this to do with Python? Most of Python's most famous data science and scientific computing libraries are written in C/C++, with a simple wrapper allowing them to be called easily from python. If you've ever wondered why Numpy, SciPy, scikit-learn and pandas are so much faster than trying to write the same code yourself in native Python, it's because all of the work in a function like np.multiply() is actually carried out in C "under the hood".
Previously, if you had a licence for Intel's compiler suite you could compile these python libraries yourself and take advantage of Intel's speed boost in your python applications, but this required both familiarly with C code compilation, as well as an expensive licence. However Intel have now made available a free pre-compiled Python distribution with all the major packages (numpy, scipy, pandas etc.) based on the popular Anaconda distribution. According to kdnuggets Intel have also re-written some common functions entirely for further optimization - in particular it looks like numpy and scipy's FFT (Fast Fourier Transform) functions have been enhanced significantly. Depending on your workload, using this distribution could boost the execution speed of these libraries by 10-50% without the need for any code change.
If you're interested in optimizing Python code that you wrote yourself and isn't available in any existing (C-implemented) library check out Cython as a way of implementing the most performance sensitive parts of your code in C. Unlike using the Intel distribution linked above, converting part of your code to use Cython can take some development work, however even when using the free GCC compilers you'll see a significant increase in speed over native python code.
Monday 5 February 2018
Pip unable to download packages running in a Ubuntu docker image on kubernetes
/etc/docker/daemon.json and enter google's DNS servers as follows:
{
"dns": ["8.8.8.8", "8.8.4.4"]
}
I was working from a Ubuntu base image, so I created the file as above before installing and starting docker. Keep in mind that as docker images usually don't contain systemmd, it's not all that easy to restart docker once you have installed it, so creating the configuration first is pretty useful. You can find more information on this at https://development.robinwinslow.uk/2016/06/23/fix-docker-networking-dns/
Wednesday 21 June 2017
Alchemy app released (in beta)
Tuesday 20 June 2017
Memory leak with android linearlayout and Picasso
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
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
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
Tuesday 19 July 2016
New LOFAR baseline comparison tool
Tuesday 24 May 2016
Installing AIPS on Ubuntu 16.04
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.
Monday 9 May 2016
New website
Thursday 19 November 2015
Negative diagonal elements in the covariance matrix returned by numpy.polyfit
I ran a command of the form:
p, cov = np.polyfit(x,y,1,w,cov=True),
where x, y and w were arrays of length 3.
The command returned the correct slope and y-intercept values, however the covariance matrix, cov, had strictly negative diagonal terms. This is apparantly because numpy scales the covariance matrix as described in here.
The scaling applied is a factor such that
factor = resids / (len(x) - order - 2.0)
If, like me, you are making a first order polynomial fit to a dataset of 3 values, the denominator has the effect of multiplying the expected matrix by -1. If I was unlucky enough to have 4 points, it would have thrown bigger errors.
In my case, looking at the results here, I could recover the correct values just by multiplying the matrix by minus one. This is a strange weighting to apply to a small dataset - I assume it makes sense if you have many points and the developers wanted to keep numpy.polyfit consistent.
Monday 5 October 2015
Fixing AIPS after upgrading to El Capitan on OSX
The library fix should have been the easiest - AIPS was looking for:
- libsvml.dylib
- libirc.dylib
- libimf.dylib
Tuesday 14 October 2014
Installing LOFAR software on a mac (Mavericks)
I roughly followed the same procedure as for Ubuntu, but with a few differences.
First I used macports to download as many of the dependencies I listed here as I could find. The full list of macports I installed is
The commands I used were:
Boost:
//sincosf(phase_ij_obs - phase_ij_model, &sin_dphase, &cos_dphase); sin_dphase = sin(phase_ij_obs - phase_ij_model); cos_dphase = cos(phase_ij_obs - phase_ij_model);
Probably unnecessary patches:
The first three patches are probably redundant if you remember to include the DUSE_SHMEM=OFF compiler option.
Note that the CMAKE/variants/GNU.cmake file needs to be edited to point to the macports compilers as follows:
set(GNU_C /opt/local/bin/gcc) # GNU C compiler
set(GNU_CXX /opt/local/bin/g++) # GNU C++ compiler
set(GNU_Fortran /opt/local/bin/gfortran) # GNU Fortran compiler
set(GNU_ASM /opt/local/bin/gcc) # GNU assembler
One final thing to do is to add the following lines to the .profile file in your home directory.
Tuesday 7 October 2014
Installing LOFAR software on Ubuntu 12.04
These are some notes on how I installed some LOFAR software on Ubuntu 12.04. They are based on some notes I found on the LOFAR wiki at http://www.lofar.org/operations/doku.php?id=engineering:user_software:ubuntu_12_4.
Install main LOFAR suite
===============================================
N.B. Notes below install to strange directory. Build in one directory, and install everything else into the CASACORE directory (binary)
Dependencies:
libgtkmm-2.4-dev python-matplotlib python-pyfits libatlas-base-dev
mpi-default-bin mpi-default-dev libfreetype6-dev python-setuptools
libxml2-dev libpng12-dev libcfitsio3 libcfitsio3-dev libboost-all-dev
autoconf autoconf-archive autogen automake binutils-dev cmake cmake-curses-gui
cvs doxygen flex gfortran git guile-1.8-dev ipython libblas-dev libblitz0-dev
libboost-all-dev libboost-dev libfftw3-dev libfftw3-doc libgfortran3
libglib2.0-dev libgsl0-dev liblapack-dev liblog4cxx10 liblog4cxx10-dev
libopenmpi-dev libpqxx3-dev libx11-dev mgdiff mpi-default-dev patch pgplot5
python-dev python-numeric python-numpy python-scipy scons subversion-tools
swig bison libbison-dev
tcl tcl-dev tk tk-dev tk8.5-dev tcl8.5-dev
libhdf5-dev (oder: libhdf5-serial-1.8.4 libhdf5-serial-dev)
### "libhdf5-serial" is needed for DAL, it doesn't work with "libhdf5-openmpi"
wcslib-dev liblog4cplus-dev liblog4cplus-1.0-4 cython
###for parmdbplot:
python-sip python-qt4
########## LOFAR software:
Download packages:
##################
mkdir Downloads
cd Downloads
wget ftp://ftp.atnf.csiro.au/pub/software/asap/data/asap_data.tar.bz2
Download and Build Casacore:
############################
tar -xjvf ../Downloads/asap_data.tar.bz2
(This creates the "data" subdirectory)
mkdir BuildDir/casacore
cd BuildDir/casacore
svn co http://casacore.googlecode.com/svn/trunk source
mkdir -p build/opt
cd build/opt
cmake -DBUILD_TESTING=NO -DCMAKE_INSTALL_PREFIX=/opt/lofar-stuff -DUSE_FFTW3=Yes -DUSE_THREADS=YES -DUSE_HDF5=YES -DUSE_OPENMP=YES -DDATA_DIR=/opt/lofar-stuff/data ../../source
make -j12
make install
Install Casacore data:
############################
cd BuildDir/..
tar -xjvf Download/asap_data.tar.bz2
Download and Build pyrap
############################
mkdir /cluster/lofar/BuildDir/pyrap
cd /cluster/lofar/BuildDir/pyrap
svn co http://pyrap.googlecode.com/svn/trunk dev-source
export LOFAR_STUFF_ROOT="/opt/lofar-stuff"
export PATH="${PATH}:${LOFAR_STUFF_ROOT}/bin/"
export LD_LIBRARY_PATH="${LOFAR_STUFF_ROOT}/lib/"
export PYTHONPATH="${LOFAR_STUFF_ROOT}/lib/python/"
ln -s /opt/soft/lofar-stuff/lib/ /opt/soft/lofar-stuff/lib64
cd dev-source/
./batchbuild-trunk.py --casacore-root=/opt/lofar-stuff --prefix=/opt/lofar-stuff --python-prefix=/opt/lofar-stuff/lib/python
Download and Build casarest
###########################
mkdir /cluster/lofar/BuildDir/casarest
cd /cluster/lofar/BuildDir/casarest
svn co https://svn.astron.nl/casarest/trunk/casarest source
mkdir build
cd build
cmake -DCASACORE_ROOT_DIR=/opt/lofar-stuff -DBUILD_ALL=1 -DCMAKE_INSTALL_PREFIX:PATH=/opt/lofar-stuff ../source
make -j12
make install
Download and Build the LOFAR Software
#####################################
Download latest copy of LOFAR software
mkdir -p build/gnu_opt
cd build/gnu_opt
cmake -DCASACORE_ROOT_DIR=/opt/lofar-stuff/ -DBUILD_SHARED_LIBS=ON -DUSE_OPENMP=ON -DBUILD_PACKAGES="ParmDB Calibration DP3 Pipeline MSLofar LofarFT GSM" -DCMAKE_INSTALL_PREFIX:PATH=/opt/lofar-stuff ../../LOFAR/
make -j12
make install
Note: I found that the above instructions installed the pyrap python libraries in a separate folder to where LOFAR was looking, so I just found them in lofar-software/lib/python and manually pasted them into the right directory (the one LOFAR regards as PYTHONPATH)
Tuesday 29 July 2014
Harvard-style referencing using Latex and Mendeley
FUNCTION {write.url}
{
{ skip$ }
}
to get rid of the links to webpages that were appearing in my output. I had a lot of unusual (Russian) names in my references which were giving errors, so I edited the final .bbl file (not the .bib created by mendeley) manually to replace troublesome characters and errors.
Installing AIPS on Ubuntu 14.04
[EDIT]
Some intel processors were giving a little trouble even when following the method linked above. The single offending file was AU7B.FOR, located in 31DEC14/AIPS/SUB (or the equivalent) and the issue was the MONTH parameter declared at the top of the file.
By deleting the MONTH declaration in the FORTAN code and the initialization of MONTH to JAN, FEB etc. a little further down and replacing it with
character (len=3), dimension(12) :: MONTH
MONTH(1) = 'JAN'
MONTH(2) = 'FEB'
MONTH(3) = 'MAR'
MONTH(4) = 'APR'
MONTH(5) = 'MAY'
MONTH(6) = 'JUN'
MONTH(7) = 'JUL'
MONTH(8) = 'AUG'
MONTH(9) = 'SEP'
MONTH(10) = 'OCT'
MONTH(11) = 'NOV'
MONTH(12) = 'DEC'
you can get AIPS to compile with gfortan as usual. I think the problem relates to old fashioned fortran code, modern gfortran and intel processors (I don't seem to have the same trouble with AMD processors, though they are of different vintages).
The resulting aips installation does compile - but there is a serious problem with IMAGR, and likely other tasks too. The best bet is to download an older version of gfortran compatible with AIPS and use that to compile for a fully functional AIPS installation.
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...
-
I've recently installed AIPS (version 31DEC16) on Ubuntu 16.04. Here are my notes on the installation experience. Due to recent compiler...
-
Scientific computing and HPC developers will probably be familiar with Intel's C/C++ compiler suite , which can be used to compile...
-
AWS recently went live with Keyspaces, their managed version of Cassandra ( https://aws.amazon.com/keyspaces/ ). This service is primarily a...
