note that unset FLY_REGIONS["a100-40gb"] is incorrectly quoted: it gets expanded as a glob (like ls files.[ch]pp). for instance it will match a file called FLY_REGIONSa if it exist, so you’ll end...
I make great use of associative arrays (hashmaps) to reduce calls to an sqlite database I store static information in. I make an API call to return 10 values I care about for a data point. I store...
I make great use of associative arrays (hashmaps) to reduce calls to an sqlite database I store static information in.
I make an API call to return 10 values I care about for a data point. I store these values in the database for future use. I also store them in the associate array val_one[${dataPoint}]="${value_one}". By doing this, if I need that data point later in the script (or on a future run, in which I'm getting the data from the sqlite db instead of an additional API call), I can call function getValOne "${dataPoint}"
function getValOne {
if [[ -z "${1}" ]]; then
echo "give me a data point u luddite"
return 1
fi
if [[ -n "${val_one[${1}]}" ]]; then
# Value already assigned
return 0
fi
# No value assigned, get one from sqlite
val_one["${1}"]="$(sqlite3 [...])"
}
It's sped up my scripts a decent amount that have a large number of potential sqlite lookups.
Unfortunately, I've started having to pad my array elements with an underscore, as some of my data points are mixed strings of integers and letters. Every now and then a string beginning with an integer will be interpreted (I forget, it's either interpreted lexicographically and it shouldn't be, or it shouldn't be and it is. Either way, padding with a leading underscore fixed that.)
Oh I see, so part of this is that SQLite isn’t running at all times? Then yeah if the same constraint is applied to redis I think you’re right. In terms of processes you could of course just run...
Oh I see, so part of this is that SQLite isn’t running at all times? Then yeah if the same constraint is applied to redis I think you’re right. In terms of processes you could of course just run one redis process that is single threaded, but it sounds like that may not fit your solution
Anything would be a better drop-in solution. My primary job is a patient care facing role in healthcare, I'm pretty far from anything tech, IT, or development. I started tinkering around on Ubuntu...
Anything would be a better drop-in solution. My primary job is a patient care facing role in healthcare, I'm pretty far from anything tech, IT, or development. I started tinkering around on Ubuntu as a teen back in 2007, and all of my *nix experience comes from using it for hobby/passion projects over the years. I should have learned Python, or something, years ago. But I just didn't have the time or mental fortitude when I could cop out and be like "Eh, bash script".
note that unset FLY_REGIONS["a100-40gb"] is incorrectly quoted: it gets expanded as a glob (like ls files.[ch]pp). for instance it will match a file called FLY_REGIONSa if it exist, so you’ll end up unsetting the variable FLY_REGIONSa instead of index a100-40gb of FLY_REGIONS
you want something like unset "FLY_REGIONS[a100-40gb]"
Thank you for all these bash posts by the way. I'm loving it.
I make great use of associative arrays (hashmaps) to reduce calls to an sqlite database I store static information in.
I make an API call to return 10 values I care about for a data point. I store these values in the database for future use. I also store them in the associate array
val_one[${dataPoint}]="${value_one}". By doing this, if I need that data point later in the script (or on a future run, in which I'm getting the data from the sqlite db instead of an additional API call), I can call functiongetValOne "${dataPoint}"It's sped up my scripts a decent amount that have a large number of potential sqlite lookups.
Unfortunately, I've started having to pad my array elements with an underscore, as some of my data points are mixed strings of integers and letters. Every now and then a string beginning with an integer will be interpreted (I forget, it's either interpreted lexicographically and it shouldn't be, or it shouldn't be and it is. Either way, padding with a leading underscore fixed that.)
Ha, I both love and hate this. Redis would probably be a pretty easy drop-in solution?
Oh I see, so part of this is that SQLite isn’t running at all times? Then yeah if the same constraint is applied to redis I think you’re right. In terms of processes you could of course just run one redis process that is single threaded, but it sounds like that may not fit your solution
Good point, I forgot that’s how SQLite works.
Anything would be a better drop-in solution. My primary job is a patient care facing role in healthcare, I'm pretty far from anything tech, IT, or development. I started tinkering around on Ubuntu as a teen back in 2007, and all of my *nix experience comes from using it for hobby/passion projects over the years. I should have learned Python, or something, years ago. But I just didn't have the time or mental fortitude when I could cop out and be like "Eh, bash script".
speaking of unexpected places where hashmaps are built-in, POSIX C has them