Friday, 14 July 2023

Collation of livetime (liverc) results for a user

I race little toy cars for plastic trophies! 

In all, i've got 6 RC cars. Not just your average kmart, warehouse, wallmart put some AA batteries in and watch them crawl along at a top speed of "walking pace", no way.

My 1/10th on-road car will do at least 60km/h (38mph) down our back straight, and it's 1/8th big brother will do something like 80-85km/h (50mph-ish). Some of our club members have cars, on our 85m back straight, will top 109km/h... impressive right!

Our results are collected via a transponder system from mylaps, everytime our cars passes over a wire, the transponder communicates with the timing computer and it logs its lap. 
Now this is where my problem started.... 

The results were hard to read on the website. All the data was there but it was hard to compare your first qualifying round to the second and then to your finals, because they showed on different pages. Therefor you needed lots of tabs open if you didn't want to go back and forth.

Initially i started writing this in PHP, i have a server that is always on the internet, so i just lodged it as part of my site. Using a fetch routine, i would go and get the page that had results on it, and then parse the page, looking for the results, collate them and then just show all the results in one hit. It wasn't the most elegant thing, but it worked. 

As you can guess i ran into a few problems, but i got there in the end. 

With that done, my thought was that now every time someone wanted to use this, my server was the one fetching all the results, and that could be quite taxing on page responses. 

So idea 2 then came to mind, lets write this in Javascript! The server would serve up the site, and the javascript would essentially do all the heavy lifting locally, it would be more or less like the user was browsing the site as it was coming from their computer. 
Ran into lots of issues here, the big one was CORS or Cross-origin resource sharing. Basically i couldn't grab the site locally then serve it up to you. This is pretty much how scammers work lol. 

I had been talking to a friend at work randomly about being able to get data from pages that didn't have any sort of API. He had recently come across a project that turned any website into an API! In walks wrapAPI!

So this ended up being magic, wrote the whole thing out to be just fetch and parsing data. 

Work pivoted for me, and i started working with react, which mean't i needed a project to work on, so i thought i would further refine this tool to be written in react, javascript worked, but it was very cumbersome.

Anyhow - long story short, i got practice with react, racers at our local clubs now get to enjoy a tool that shows all their race data in one hit, not having to have multiple tabs open, everyone wins!

Check out my collation tool

Wednesday, 31 May 2023

Slow speed using Evoluent mouse with linux mint 21.1

Recently i installed a fresh copy of linux mint 21.1

I've got a nice new 4K monitor that someone donated to me, which then hooked up to another donated PC fitted with a Nvidia 1060 6GB GPU nicely. 

While that's not impressive, it is for me. I always get the hand-me-downs, which is why i like running linux so much as these machines are always fast, they just out perform windows even when being old. 

Anyhow, i also have a nice Evoluent Vertical 4 Mouse, This mouse is great if you have some OOS (occupational over use syndrome). Stemming from my Cad days this mouse really saved my wrist from horrible all day pains

So with my 4K monitor, i scaled the 4K image up 200%, so both monitors were approx the same resolution. However the mouse point was slow. 

Even with the speed sliders at full, it was a real slog to try and get the pointer from one screen to another.

I thought it was something to do with the scaling that i had done with the driver, but when i tried another mouse, i didn't see the same effect, therefor leading me to assume that it was something special with this mouse. 

I found a great post in the end about increasing the mouse sensitivity. trying this out proved to be the fix that i needed. 

To see the current settings, use:

xinput --list-props "HOLTEK Evoluent VerticalMouse 4" | grep -i 158

Then to try new settings use: 

xinput --set-prop 8 158 2.000000 0.000000 0.000000 0.000000 2.000000 0.000000 0.000000 0.000000 1.000000

According to the post, the values you want to be tweaking are the two "2.00000" from the above command. These are the X and Y axis respectively 

Once i found mine, as suggested, i popped this into my ~/.bashrc, so that everytime the computer reboots, it will set the values i want.

Now.. where is my coffee....

Monday, 4 May 2020

Functions in aliases for bash



Thought i'd share a little nugget.

So i do a few commands in linux that are repetitive in nature, so i often alias them out so i'm lazy and don't have to type as much.
For instance, one of my repetitive commands is `git grep`, which is a great tool for going through your git repo to search those reg expressions.
So in my ~/.bashrc, i have
alias ggrep="git grep"
Now, all i do is ggrep <my search>

Something i learn't today however, is passing an argument to an alias.
My work has a lot of test boxes scattered around connected to different gear, so i ssh a lot to these. since the are all nicely formatted to tb<something a rather>, i decided i would now like to replace ssh tb0933 with tb 0933.
To do this is easy enough, but unlike a standard bash shell, we can't pass in the variable and just access like $x. Instead what we have to do is to create a function, and then call it.
So in the very simple case of the above my command equates to
alias tb='function ssh_tb=() { ssh tb$@; }; ssh_tb'
So expanding on this, we define the function ssh_tb() which when called, will execute the command ssh tb$@, and then at the end of this, we call it.

Easy!

Thursday, 26 March 2020

Linux device trees



Such a great resource at https://source.android.com/devices/architecture/dto/syntax

Thursday, 18 July 2019

Key bindings in linux for spotify



Had issues with my keyboard and the play button not working with spotify... (this was my work one).

So if you're play button is not working with spotify, then try this guys suggestion, http://shkspr.mobi/blog/2011/12/linux-spotify-keybindings/


Sunday, 16 December 2018

Videos not playing in opera on linux


So, it's no secret i've loved opera since the day i first installed it, I think i joined the opera revolution around the 3.62 mark in 1999 apparently! (man i'm old). Anyhow - read up more about the opera history here https://en.wikipedia.org/wiki/History_of_the_Opera_web_browser

Since i'm this fancy new software developer type person,  i have it installed as my browser of choice at work, but we run linux here since the platforms we use are linux as well. I'm not complaining mind you, i like linux too!

But the support for playing videos is lacking :( (wuh waaahhh), I believe this is due to the license with Mpeg's and not being able to distribute the codec with the program.
From this post it appears that Opera doesn't have the rights to distribute the codec with the program. however! Google does (cos they probably have deeper pockets right?)

Anyhow - very easy to fix, we simply copy over the top of the libffmpeg.so that we have in our opera directory with one from the google chromium browser :)

sudo cp /usr/lib/chromium-browser/libffmpeg.so /usr/lib/x86_64-linux-gnu/opera/


Restart the browser and things should be all good again :)


Tuesday, 4 December 2018

Measuring function time in linux using C


Measuring Time 

So in my job recently i had to time how long it took for a module to be plugged in before that module became "ready" ... the answer was 46 seconds.. but some careful polling changes and a change how firmware was loaded mean't that got chopped in half almost to 26 seconds!

But that's not the point, the point was how did i do such timing.

The original way i found was to use to use clock(). Clock returns an approximation of the processor time used by the program.
Using the following code..

#include <time.h>
#include <stdio.h> 
int main() 
{ 
   clock_t start, stop, length; 
   start = clock(); 
   
   function_to_be_time(parameters); 
   
   stop = clock(); 

   length = (double) stop - start / CLOCKS_PER_SEC; 

   printf("Time for your function was %ld\n", length); 
   
   return; 
} 

Now, this works mind you! but there's a gotchya here, oh yes, you saw that coming didn't you.. go on - admit it..
I probably didn't read the manual (RTFM!) for clock properly.... because the times i was getting back for my function calling didn't make sense compared to time stamped outputs!?
Clock() is returning time used by the program... i know - that didn't make sense, but it does if you mention the word threading.
See i was in a multi-threaded enviroment. So while this was timing my function in this "program" (ie thread!) my "program" had been running differently (in time) from other functions (ie threads!) that made up the entired module "ready" process.

Take 2. 

So instead, i used clock_gettime() with CLOCK_MONOTONIC.
This gave me a much better accuracy across my module insertion process, and started giving me numbers that made sense with other time stamped debug statements.

So.. using the following code,
#include <time.h>
#include <stdio.h>

/* Convert the timespec struct into a seconds value
static double TimeToSeconds(struct timespec* ts)
{
   return (double)ts->tv_sec + (double)ts->tv_nsec / 1000000000.0;
}

int main()
{
    struct timespec start, stop;
    double time_spent = 0;
    clock_gettime(CLOCK_MONOTONIC, &start);

    <YOUR FUNCTION GOES HERE>

    clock_gettime(CLOCK_MONOTONIC, &stop);
    time_spent = TimeToSeconds(&stop) - TimeToSeconds(&start);
    
    printf("your function time was %ld\n", time_spent);

    return;
}

Hopefully that helps someone with timing issues in threads etc.. lemme know if it works for you :)

Lastly - so i don't forget (possibly)... time stamping..
I'm just gonna post the code

time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf("Time Stamp is [%d:%d:%d]\n", 
        timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);

All good fun :)