Showing posts with label development. Show all posts
Showing posts with label development. Show all posts

Wednesday, June 12, 2019

It's all about the integers



As previously discussed in Floating point madness, the handling of fractional year, month, day, week, hour, and minute components of ISO 8601 dates and times is fraught with all kinds of peril. At the time, I chose a solution that was pretty immediately obvious, could be implemented quickly, solved a real problem with degenerate cases, and seemed intuitive. Even at the time, I mentioned it would only work for most cases, not all. Unfortunately, issue 24 highlights that working for most cases isn't good enough. Is there a solution that can work for all cases?


Wednesday, January 30, 2019

Floating point madness

In the course of squaring away sub-microsecond precision in aniso8601, the discussion came up that fractional components in general are rounded instead of truncated at maximum representable precision which can lead to the same kinds of problems pointed out in issue 10. At the time I pushed back because I figured it would lead to 'floating point madness' trying to get the correct behavior in all cases. Recently I was convinced to capitulate as I ran into a series of issues in my own use. Issue 21 covers this in some detail, but for those that want a complete breakdown, read on.


Wednesday, November 28, 2018

Simple federated sign-on with Amazon Cognito Part 2 - The code

Now that we've got the general setup out of the way in part 1, it's time to dig into how the cognito.js code actually works. Keep in mind it's dependent on js-sha256 for the SHA256 implementation, which is included for you if you use the example index.html file.


Tuesday, November 27, 2018

Simple federated sign-on with Amazon Cognito Part 1 - The "basics"

I recently found myself needing to climb the learning curve for adding federated user sign-in to a webpage with Amazon Cognito. What follows is a quick summary of how you can do the same. For those who want to jump ahead, they can just take a look at the matching Bitbucket Snippet.


Thursday, October 25, 2018

aniso8601 and sub-microsecond precision

After more false starts than I can count, aniso8601 is finally ready to handle sub-microsecond precision. Anyone following the (now approaching 3 year old) issue #10 will know that a solution wasn't immediately obvious. However, after fairly constant requests for "I want to parse an ISO 8601 timestamp and receive an X" and "why do you only support parsing to X and Y, I need to the parse result to be a Z" I came to the realization what people really wanted was a parser that just parses and to be able to build those parse results into whatever fits their use case best. Enter the 'builder' kwarg.

TLDR: New optional 'builder' keyword argument for all parse methods, 'relative' keyword argument going away. Default behavior is the same as always.

Monday, February 23, 2015

MSP430 GCC 3.2.3

A couple of people have asked about version 3.2.3 of the official TI version of GCC for the MSP430. The source link was broken, but it's fixed now. Updated versions of the msp430-gcc-support-files, msp430-elf-binutils, msp430-elf-gcc, and msp430-elf-gdb packages are now available in my Copr repository. And yes, I plan on tracking TI releases in that repo.

Sunday, February 15, 2015

MSP430 and Fedora 21 - The same but different

If you've tried doing any work with the GCC compiler officially packaged by the Fedora Project, you've probably run into issues when trying to link. The issue is correctly identified on that bug report, the strip step of building the RPM needs to be worked around. Unfortunately the maintainer of those packages hasn't stepped forward to push a fix.

I considered fixing the issue myself, but I'd recently discovered that TI and Red Hat have started work on their own supported version of the GNU toolchain for the MSP430. Instead of fixing the current packages (which are packaging source that is over 4 years old now), I packaged the new TI / Red Hat version. Sure, it was time consuming, but when you have a new yo-yo your brother got you for Christmas, the compile time just flies by.


Thursday, October 9, 2014

Android MIME type without a ContentResolver

Sometimes in Android you'll find yourself needing a MIME type for a given Uri. The conventional wisdom is to use a ContentResolver, which is great if you have a Uri that a ContentProvider knows about. If you have a 'file://' Uri with no corresponding ContentProvider, the popular solution is to use the MimeTypeMap. Unfortunately, if you are dealing with files from the *nix world, files often do not have extensions making a MimeTypeMap based solution incomplete.

Instead, I use something like the below code that uses methods from the URLConnection class. Note that it only works if the Uri has a 'file://' prefix, and points to media that is local, and accessible by your application. It also assumes the extension (if present) is correct. If you don't trust the extensions, use the guessContentTypeFromStream method first. It should be easily modifiable to other Uris.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public static String getMimetypeFromUri(Uri uri) {
 /**
 * Returns a String representing the mimetype for a given Uri.
 *
 * @param uri  the uri to get a mimetype from
 * @return a String reprensenting the mimetype for the given uri,
 *         the 'generic' mimetype if a better one cannot be inferred
 */

 //First, try to guess from the path
 String resultMimetype;

 resultMimetype = URLConnection.guessContentTypeFromName(uri.toString());

 if (resultMimetype == null)
 {
  //Try to get the mimetype by reading the file
  File file = new File(uri.toString());
  FileInputStream fileInputStream;

  try
  {
   fileInputStream = new FileInputStream(file);

   resultMimetype = URLConnection.guessContentTypeFromStream(fileInputStream);

   fileInputStream.close();
  }
  catch (FileNotFoundException e) {
   e.printStackTrace();

   resultMimetype = "*/*";
  }
  catch (IOException e) {
   e.printStackTrace();

   resultMimetype = "*/*";
  }
 }

 return resultMimetype;
}

Wednesday, September 10, 2014

Updating to CUDA 6.5 on Fedora 20

Assuming you installed CUDA 6 following my previous guide, updating to 6.5 is pretty simple, first, remove the old (Fedora 19) repo:


# yum remove cuda-repo-fedora19


Now, update to the new Fedora 20 CUDA 6.5 repo:


# rpm -ivh http://developer.download.nvidia.com/compute/cuda/repos/fedora20/x86_64/cuda-repo-fedora20-6.5-14.x86_64.rpm


Update CUDA (still haven't fixed the EULA spam):


# yum update cuda cuda-cross


Finally, update the paths you export to the following:


export PATH=/usr/local/cuda-6.5/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-6.5/lib64:$LD_LIBRARY_PATH


Note for users of the RPM Fusion 'akmod-nvidia' package: The above will update your driver to the Nvidia version of 'akmod-nvidia' (340.29-2 at the time of this writing) unless you are running the newer version from the RPM Fusion testing repo. This was fine with me. I do not know if it is possible to successfully use CUDA 6.5 with an older driver.

Monday, August 18, 2014

The great date parser race

Recently I've had a couple of conversations that made me wonder about Python parsers for ISO 8601. A topic I have a personal interest in.

The first conversation was about how a library providing some fundamental functionality turned out to be a bottleneck in a much larger program.

The second was about how slow regular expressions seem to be on ARM systems.

Parsing dates is a pretty fundamental function, and my date parser runs on ARM (and some of its competition (pyiso8601) uses regular expressions), so let's race!


Wednesday, August 6, 2014

aniso8601, now parsing 100% more durations with commas

My ISO8601 parser for Python (aniso8601) just hit version 0.83. As requested, I've added support for parsing durations where the decimal fraction is specified with a comma.

If you are one of those people that's into such things, the new version is up on PyPI. I don't handle the packages for various distros, so I can't help with those...

Saturday, July 12, 2014

MSP430F5529 LaunchPad 'Project0.2' - GDB on Fedora 20

When I initially promised "more depth" on mspdebug, I honestly believed it would be more user friendly. But frankly, the more I played with it, the less I wanted to use it as a debugger. Fortunately, it can function as a bridge to GDB which is a much more pleasant debugger to work with. Getting mspdebug to play well with GDB was not straightforward, but I'm pleased to say I have a solution that works.


Tuesday, July 1, 2014

MSP430F5529 LaunchPad 'Project0.1'

Quite awhile ago I wrote a little tutorial on how to do the MSP430F5529 'Project0' on Fedora 20. At that time, I promised a follow-up tutorial on using mspdebug. This isn't that tutorial. This is 'Project0' again, but showing using multiple source files, a header file, and cleaning up all but one compiler warning. The mspdebug tutorial is coming 'soon'.


Saturday, March 8, 2014

Stratum Mining Block Headers - A Worked Example

Anybody spending any significant amount of time on the internet lately knows that tulip bulbs, er, I mean, cryptocurrencies are a hot topic. As such, it seems like there are a lot of projects out there looking to implement related technologies.

Stratum mining is one of those technologies. It is currently the in-vogue replacement for the older 'get-work' protocol, and everyone seems to want to write their own implementation. Unfortunately, the official documentation is severely lacking in any kind of worked example, a weakness I hope to rectify here.

This is not intended be a complete document on the ins and outs of the communication aspect of Stratum, that is something I feel like the official documentation does well. This is merely intended to show a worked example of generating a block header based on information provided to a Stratum client by a Stratum server. Think of  it as the 'back of the book' answer for a homework problem. Also note, this is for a Scrypt based coin, though the process should be the same for double SHA-256 based currencies.

If it helps you, you can send me a Bitcoin tip so maybe I can afford the fancy ramen this week: 18ymUR1XyZ68NCzjrzYtMRP2ztk8LjAgBL


Sunday, February 2, 2014

MSP430F5529 LaunchPad 'Project0' on Fedora 20

Recently TI launched another MSP430 LaunchPad, the MSP430F5529. While the "Project0"  (caution, PDF link) tutorial they provide is great if you intend to use Windows and CCS, it falls short if you intend to use mspgcc and Linux. This guide will hopefully fill in the blanks for doing the Project0 tutorial on Fedora 20.


Wednesday, December 18, 2013

Setting up CUDA on Fedora 20

Installing Nvidia's CUDA on Fedora is pretty simple, but the official documentation (warning, PDF link) falls a little short if you are using the Nvidia drivers packaged by RPM Fusion. If you are using the officially packaged Nvidia drivers, just follow the official docs, otherwise follow along after the break.