I want to cache hundreds of images while the splash-screen is displayed.
Following the guide from : https://docs.expo.io/versions/latest/sdk/app-loading#__next
I dont want to type one by one like :
async _cacheResourcesAsync() {
const images = [
require('./assets/images/image1.png'),
require('./assets/images/image2.png'),
require('./assets/images/image3.png'),
require('./assets/images/image4.png'),
require('./assets/images/image5.png'),
require('./assets/images/image6.png'),
...
];
const cacheImages = images.map((image) => {
return Asset.fromModule(image).downloadAsync();
});
return Promise.all(cacheImages)
}
I'v noticed that I cannot do something like (./assets/images/*) :
async _cacheResourcesAsync() {
const images = [
require('./assets/images/*')
...
];
}
Is there a way to reference the full folder on _cacheResourcesAsync() ?
What you're looking for is called dynamic imports (eg: in webpack), and it's not available in React Native. Here is a description of how you can do that in React Native, both through automation and through a Babel plugin. Given that individual-maintainer Babel plugins don't seem to survive very well between even minor upgrades of Babel, I'd highly suggest the automation approach, akin to what is laid out in the article linked to above.
For my part, though, I'd probably do it in bash and tie it into my build process (through package.json's "scripts"). It'd be something like this:
#!/bin/bash -exu
# The paths are relative to the script's parent directory.
DIRS_TO_BUILD=( ./src/res ./images ./assets );
cd `dirname $0`
HEREDIR=`pwd`
for DIR in "${DIRS_TO_BUILD[#]}"
do
cd "$HEREDIR/$DIR"
rm index.js
FILES=`ls -1QBb | grep -E '.js($|x|on)' | sort -u`
for FILE in $FILES
do
if [ -f "$FILE" ]
then
BASENAME=`basename "$FILE" .js`
BASENAME=`basename "$BASENAME" .jsx`
BASENAME=`basename "$BASENAME" .json`
echo "export const $BASENAME = require(\"./$FILE\");" >> index.js
fi
done
done
Resist the urge to call this script like import * as MyAssets from "./assets", because that'll kill tree shaking when it arrives.
You can modify that script to instead/also generate a call to loadAsync in order to prefetch all the assets. Such a modification is left as an exercise for the reader.
Hack instead for cache
A simple and effective way would be to bundle your assets in the app.JSON file. So when you will make a build those images will also come in the build and the app wouldn't have to search for those images in amazon CDN. This will increase your file size for sure but will make the assets offline and reloading faster.
Related
I hope you are all doing well. I've been recently trying to modify the AutoDesk reference application to allow me to create a heat-map with my own sensors data and my own model. However, I have been having difficulties. Has anyone done something similar before? Do you have to create two separate .env files or do you just change both the credentials for the FORGE_ID portion and the CSV portion in the same one?
Thank You, (I attached an example of what it looks like with only the CSV portion change.)
Changed CSV portion
The .env file must be unique as it is loaded by the dotenv package to add all these values as environment variable (NodeJS access these variables with process.env.[VARIABLE_NAME]).
To ensure your .env file is used by dotenv, you must set your ENV to local, if you look at /server/router/index.js, you will find these lines :
if (process.env.ENV == "local") {
require("dotenv").config({
path: __dirname + "/../.env",
});
}
As you are on MacOS you could try this command : export ENV=local && npm run dev to start your server in dev mode.
The CSV portion you showed should work, just put all these lines into your current .env file and you should be able to use your own model AND add your own sensors data.
When working on compiled documents (LaTeX, RMarkdown, etc), I usually set up a rule for make using inotifywait to watch the input files and automatically rebuild the output file whenever the input files change.
For example:
dependencies = main.tex
main.pdf: $(dependencies)
latexmk -lualatex --shell-escape $<
watch:
while true; do inotifywait --event modify $(dependencies); $(MAKE); done
I'm now trying to migrate from make to snakemake. How can I set up something similar with snakemake?
Using Snakemake you get the power of Python. For example, you can use inotify python module to wait for updates and run the snakemake.snakemake function each time you detect updates. But it would be much easier to reuse the bash script that you have already: while true; do inotifywait --event modify $(dependencies); snakemake; done.
I have a list of image files (jpg, png, etc...) that the dot before the suffix was replaced with # this makes the file unrecognizable to the Android os. In dos, it would be easy. How can I do it in js easily because I've never used js before?
If you're using Node.js, you can use the fs module.
I haven't been able to make time to test a solution, but a naive implementation would look probably like this:
// Import the fs module
const fs = require('fs');
// Read all files in directory
var files = fs.readDirSync('/path/to/images/folder/');
// Loop through the files and rename each file
files.forEach(path => fs.rename(path, path.replace('#', '.')));
I'm using recess to compile and compress my LESS files, but i'm having some troubles with a specific Firefox css to convert an Img to grayscale, here is a snippet of the LESS code
.colorgray {
filter : url("data:svg+xml;utf8,<svg id='sometest'>mores-tuff-here</svg>");
}
I run recess --compress test.less > test.min.css
and the output of cat test.min.css is
.colorgray{filter:url("data:svg+xml;utf8,<svgid='sometest'>mores-tuff-here</svg>")}
And you may notice, svg id="sometest" is rendered as svgid="sometest", if i only try with the --compile flag, i get the result that i expect:
.colorgray {
filter: url("data:svg+xml;utf8,<svg id='sometest'>mores-tuff-here</svg>");
}
Anyone know what i am doing wrong or if there is a way to tell the recess minifier to ignore that line?
edit: seems to be a problem with yui-compressor, it strips every whitespace on a data, is there a way to turn that option off?
I had to create a new file (filters.svg) and put the content there (mores-tuff-here)
and ended using:
.colorgray {
filter : url(filter.svg);
}
I am looking for the way to mount NTFS hard disk on FreeBSD 6.2 in read/write mode.
searching google, I found that NTFS-3G can be a help.
Using NTFS-3G, there is no problem when I try to mount/unmount NTFS manually:
mount: ntfs-3g /dev/ad1s1 /home/admin/data -o uid=1002,
or
umount: umount /home/admin/data
But I have a problem when try to mount ntfs hard disk automatically at boot time.
I have tried:
adding fstab: /dev/ad1s1 /home/admin/data ntfs-3g uid=1002 0 0
make a script, that automatically mount ntfs partition at start up, on /usr/local/etc/rc.d/ directory.
But it is still failed.
The script works well when it is executed manually.
Does anyone know an alternative method/ solution to have read/write access NTFS on FreeBSD 6.2?
Thanks.
What level was your script running at? Was it a S99, or lower?
It sounds like either there is a dependency that isn't loaded at the time you mount, or that the user who is trying to mount using the script isn't able to succeed.
In your script I suggest adding a sudo to make sure that the mount is being performed by root:
/sbin/sudo /sbin/mount ntfs-3g /dev/ad1s1 /home/admin/data -o uid=1002, etc
Swap the sbin for wherever the binaries are.
After some ways I tried before.
The last, I tried to add ntfs-3g support by change the mount script on mount.c
Like this:
use_mountprog(const char *vfstype)
{
/* XXX: We need to get away from implementing external mount
* programs for every filesystem, and move towards having
* each filesystem properly implement the nmount() system call.
*/
unsigned int i;
const char *fs[] = {
"cd9660", "mfs", "msdosfs", "nfs", "nfs4", "ntfs",
"nwfs", "nullfs", "portalfs", "smbfs", "udf", "unionfs",
"ntfs-3g"
NULL
};
for (i = 0; fs[i] != NULL; ++i) {
if (strcmp(vfstype, fs[i]) == 0)
return (1);
}
return (0);
}
Recompile the mount program, and it works!
Thanks...