I'm currently trying to add scripting functionality to my C++ application by using v8. The goal is to process some data in buffers with JS and then return the result. I think I can generate an ArrayBuffer by using New with an appropriate BackingStore. The result would be a Local. I would now like to run scripts via v8::Script::Compile and v8::Script::Run. What would be the name of the ArrayBuffer - or how can I assign it a name so that it's accessible in the script? Do I need to make it a Globalif I need to run multiple scripts on the same ArrayBuffer?
If you want scripts to be able to access, say, my_array_buffer, then you'll have to install the ArrayBuffer as a property on the global object. See https://v8.dev/docs/embed for an introduction to embedding V8, and the additional examples linked from there. In short, it'll boil down to something like:
global_object->Set(context,
v8::String::NewFromUtf8(isolate, "my_array_buffer"),
array_buffer);
You don't need to store the ArrayBuffer in a Global for this to work.
Related
I am creating a web application in Go.
I have modified my working code so that it can read and write files on both a local filesystem and a bucket of Google Cloud Storage based on a flag.
Basically I included a small package in the middle, and I implemented my-own-pkg.readFile or my-own-pkg.WriteFile and so on...
I have replaced all calls in my code where I read or save files from the local filesystem with calls to my methods.
Finally these methods include a simple switch case that runs the standard code to read/write locally or the code to read/wrote from/to a gcp bucket.
My current problem
In some parts I need to perform a ReadDir to get the list of DirEntries and then cycle though them. I do not want to change my code except for replacing os.readDir with my-own-pkg.ReadDir.
So far I understand that there is not a native function in the gcp module. So I suppose (but here I need your help because I am just guessing) that I would need an implementation of fs.FS for the gcp. It being a new feature of go 1.6 I guess it's too early to find one.
So I am trying to create simply a my-own-pkg.ReadDir(folderpath) function that does the following:
case "local": { }
case "gcp": {
<Use gcp code sample to list objects in my bucket with Query.Prefix = folderpath and
Query.Delimiter="/"
Then create a slice of my-own-pkg.DirEntry (because fs.DkrEntry is just an interface and so it needs to be implemented... :-( ) and return them.
In order to do so I need to implement also the interface fs.DirEntry (which requires the implementation of interface for FileInfo and maybe something else...)
Question 1) is this the right path to follow to solve my issue or is there a better way?
Question 2) (only) if so, does the gcp method that lists object with a prefix and a delimiter return just files? I can't see a method that returns also the list of prefixes found
(If I have prefix/file1.txt and prefix/a/file2.txt I would like to get both "file1.txt" and "a" as files and prefixes...)
I hope I was enough clear... This time I can't include code because it's incomplete... But in case it helps I can paste what I can.
NOTE: by the way go 1.6 allowed me to solve elegantly a similar issue when dealing with assets either embedded or on the filesystem thanks to the existing implementation of fs.FS and the related ReadDirFS. So good if I could follow the same route 🙂
By the way I am going on studying and experimenting so in case I am successful I will contribute as well :-)
I think your abstraction layer is good but you need to know something on Cloud Storage: The directory doesn't exist.
In fact, all the object are put at the root of the bucket / and the fully qualified name of the object is /path/to/object.file. You can filter on a prefix, that return all the object (i.e. file because directory doesn't exist) with the same path prefix.
It's not a full answer to your question but I'm sure that you can think and redesign the rest of your code with this particularity in mind.
I Dart we can read some yaml config files with for example this plugin
https://pub.dartlang.org/packages/safe_config
From what I understand, it is a file access every time.
So I was wondering, is there a clean way to cache those data ?
I could do something like on init do a Config.warmUp() to load the file but then, apart from setting a global var somewhere and then importing it but I don't think this is a "classy" move.
Is there an internal cache or buffer system included in Dart or am I obliged to do this global var stuff ?
PS : It is for an Angular App, so something like localStorage in JS (but hidden to the user would be a potential solution)
You can always use package:yaml to load the data and then just hold on the the result of the loadDocument call. This will be an in-memory data structure (like a YamlMap) that you read from.
If you want to get fancy, you could use package:json_serializable to map the Yaml to a data object. See an example here: https://github.com/dart-lang/json_serializable/blob/master/json_serializable/test/yaml/build_config.dart
I am creating a small program that will help automate the initialization of a virtual environment and startup of a Django server. I would like to share this program with others.
I am looking for a way to create a variable (location of a folder) through the use of an open file browser and store that variable so that the user does not have to enter it in the future.
How can I store new information in my program for future use? I investigated the use of the plist file but cant find any documentation anywhere. Thanks for your help!
You can persistently store simple values in the user's preferences by using the NSUserDefaults class from Cocoa.
The following script asks the user to choose a folder location the first time it is run and then stores the chosen location in the user's defaults. When the script is run again, it returns the stored location without prompting the user. (Change the suiteName and locationKey values as appropriate for your script.)
var currentApp = Application.currentApplication()
currentApp.includeStandardAdditions = true
var suiteName = "your.suite.name";
var locationKey = "your.prefs.key";
var $ud = $.NSUserDefaults.alloc.initWithSuiteName(suiteName);
var $location = $ud.stringForKey(locationKey);
var locationPath = $location.isNil() ? currentApp.chooseFolder() : Path($location.js);
$ud.setObjectForKey($(locationPath.toString()), locationKey);
locationPath
Note that you can also interact with the user's preferences using the defaults command-line tool, e.g.:
defaults read your.suite.name your.prefs.key
defaults delete your.suite.name your.prefs.key
I suggested using plist above, but I just ran across this great tool:
JSON Helper
It is a app that supports scripting. The examples are shown in AppleScript, but should be easily translated to JXA.
JSON Helper is an agent (or scriptable background application) which
allows you to do useful things with JSON (JavaScript Object Notation)
directly from AppleScript. JSON Helper has no interface, and runs in
the background waiting for AppleScripts [or JXA] to ask it to do something,
just like Apple's own System Events does.
JSON Helper contains a
number of commands that help you parse JSON into regular AppleScript
lists and records, and convert AppleScript list and records back into
valid JSON. In addition JSON Helper contains some convenience commands
to allow you to communicate easily with web based APIs.
I try to add AutoSave support to the Core Data File Wrapper example
Now if i have a new/untitled document writeSafelyToURL is called with the NSAutosaveElsewhereOperation type.
The bad thing is, I get this type in both typical use cases
- new file: which store a complete new document by creating the file wrapper and the persistent store file
- save diff: where the file wrapper already exists and only an update is required.
Does somebody else already handled this topic or did somebody already migrated this?
The original sample use the originalStoreURL to distinguish those two use cases, which solution worked best for you?
Thanks
I just created a GUI using guide in MATLAB for a small project I'm working on. I have amongst other things two text fields for from and to dates. Now I'd like to get rid of them and use a Java date select tool. Of course this is not possible using guide so I need to add them manually.
I've managed to get them to show up by putting this code into my Opening_Fcn,
uicomponent(handles, 'style','com.jidesoft.combobox.DateChooserPanel','tag','til2');
using UICOMPONENT.
But even though it shows up I can't access the date select's attributes, for example
get(handles.til2)
returns
??? Reference to non-existent field 'til2'.
How can I fix this?
Unless you edit the saved GUI figure, the basic handles structure will not include your new component by default.
One way to access you component is to store the handle via guidata, by adding the following to your opening function:
handles.til2 = uicomponent(handles, 'style','com.jidesoft.combobox.DateChooserPanel','tag','til2');
guidata(hObject,handles)
Functions that need to access the handle need the line
handles = guidata(hObject)
to return the full handles structure that includes the filed til2