VSCode dynamic JSON schema validation [closed] - visual-studio-code

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have built project for a web application configuration. It includes generated (from TypeScript) JSONSchemas. To simplify - user can configure things like forms - field order (string[]), hidden fields(string[]) etc. JSON Schmeas are very helpful for users, who aren't too familiar with the configuration, and it validates some errors, that could rise from mistakes in the configuration.
But they cannot help in every situation - in those string arrays - user can put any string, and the schema will be valid.
What I would want to make - is some dynamic validation - when the user opens [ for the field order - he has to choose from the list of fields, that would be fetched from the APIs.
Something, like when you type packageName: "" in the package.json dependencies - it gets a version for the given package.
I would think, that I would have to make some VSCode extension for this - but I don't know - where to start. Can someone point me in the direction - an example, where someone uses real time JSON schema validation would be grateful.

Found an answer by digging through vscode source code. Searched all files, that contains package.json and dependencies (regex search (package.json[\s\S\n]*dependencies)|(dependencies[\s\S\n]*package.json)) and found a class PackageJSONContribution and this was exactly what I was looking for.
Then I made a simple extension using yo code (as from the example of Your first extension).
Some interfaces and classes I was unable to import from vscode, I just made a local copies for my extension. Made my own class FooJSONContribution with the only difference -
it's getDocumentSelector() function changed to
public getDocumentSelector(): vscode.DocumentSelector {
return [{ language: 'json', scheme: '*', pattern: '**/foo.json' }];
}
Adjusted extensions package.json activationEvents and added "onLanguage:json" (this could be optimised).
Adjusted activate event of the extension by adding
const contribution = new FooJSONContribution(xhr, true);
const disposableCompletionItemProvider = vscode.languages.registerCompletionItemProvider(
contribution.getDocumentSelector(),
new JSONCompletionItemProvider(contribution),
'"',
':'
);
context.subscriptions.push(disposableCompletionItemProvider);
And that's it. All of the foo.json files now work like package.json files -
Things I need to do now - adjust the code of FooJSONContribution.ts to work for my own needs, for my own API's, for my own files.
I Uploaded this example here https://github.com/leqwasd/VsCodeAsyncJsonAutocomplete

Related

VS Code Regex search to remove references based on containing text in string

I am attempting to remove all references of a managed package that is going to be uninstalled that spans throughout code base in VS Code
I have using a query to find the field permissions but am wondering if there is a way to search for the reference outside of specifying the exact field name compared to the field containing only "agf" since they are all using it.
Below is the search query:
<fieldPermissions>
<editable>false</editable>
<field>User.agf_Certified_Product_Owner__c</field>
<readable>false</readable>
</fieldPermissions>
In the field, I want to be able to find and delete the 5 associated lines from multiple files if they match "agf" in any combination. Something like the below:
<fieldPermissions>
<editable>false</editable>
<field>agf</field>
<readable>false</readable>
</fieldPermissions>
With any combination of agf in the field, delete all from any file it appears in.
Not an answer but too long for a comment
You don't have to? Profiles/perm sets don't block package's delete. Probably neither do reports.
You'd use your time better by searching for all instances of agf__ (that's with double underscore), should find fields, objects... used in classes, flows, page layouts etc. And search for agf. (with dot) should find all instances where your Apex code calls their classes marked as global.
Alternatively Apex / VF pages with dependencies on package will have it listed in their "meta.xml", for example
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>54.0</apiVersion>
<packageVersions>
<majorNumber>236</majorNumber>
<minorNumber>1</minorNumber>
<namespace>SBQQ</namespace>
</packageVersions>
<status>Active</status>
</ApexClass>
Last but not least - why not just spawn a dev sandbox and attempt the delete there? If it succeeds - great. If not - it'll list the dependencies that blocked the delete. It'll be "the real thing", it'll smite you even if your VSCode project doesn't contain all flows, layouts and thus could lull you into false sense of security. I'd seriously do it in sandbox and then run all tests for good measure, just in case there are some dynamic soql queries that don't count as hard, delete-blocking references.
After delete's done - fetch Profiles / Permsets from this org and the field references will be gone from the xml.

Add an Intro page to exam in R/exams

I am using R/exams to generate Moodle exams (Thanks Achim and team). I would like to make an introductory page to set the scenario for the exam. Is there a way to do it? (Now, I am generating a schoice with answerlist blank.)
Thanks!
João Marôco
Usually, I wouldn't do this "inside" the exam but "outside". In Moodle you can include a "Description" in the "General Settings" when editing the quiz. This is where I would put all the general information so that students read this before starting with the actual questions.
If you want to include R-generated content (R output, graphics, data, ...) in this description I would usually include this in "Question 1" rather than as a "Question 0" without any actual questions.
The "description" question type could be used for the latter, though. However, it is currently not supported in exams2moodle() (I'll put it on the wishlist). You could manually work around this in the following steps:
Create a string question with the desired content and set the associated expoints to 0.
Generate the Moodle XML output as usual with exams2moodle().
Open the XML file in a text editor or simply within RStudio and replace <question type="shortanswer"> with <question type="description"> for the relevant questions.
In the XML file omit the <answer>...</answer> for the relevant questions.
Caveat: As you are aware it is technically possible to share the same data across subsequent exercises within the same exam. If .Rnw exercises are used, all variables from the exercises are created in the global environment (.GlobalEnv) and can be easily accessed anyway. If .Rmd exercises are used, it is necessary to set the envir argument to a dedicated shared environment (e.g., .GlobalEnv or a new.env()) in exams2moodle(..., envir = ...). However, if this is done then no random exercises must be drawn in Moodle because this would break up the connections between the exercises (i.e., the first replication in Question 1 is not necessarily followed by by the first replication in Question 2). Instead you have to put together tests with a fixed selection of exercises (i.e., always the first replication for all questions or the second replication for all questions, ...).

How to trigger a function when a custom field is edited/created in redmine

I have been researching about this term for so many hours, but I found anything useful yet.
Hope you can help us building this redmine plugin, or provide us some research links to help us find the correct key.
What we want to build
The thing is we want to update one custom field in redmine (let's name it 'Target_CF') whenever another one is created or updated.
We are looking for incrementing possible values of Target_CF, so we can have all custom field's names available to select.
Of course, we want to achieve this without directly editing Redmine's Core, so we thought developing a plugin would be the best approach.
Our plugin also creates and configures a new custom field (the one mentioned above), but I will let this out of the question, because I think it is not relevant for this.
Where we are right now
We have identified some hooks that could be useful for us, as the following:
:controller_custom_fields_new_after_save
:controller_custom_fields_edit_after_save
We have the following directories/files structure so far:
plugins/
custom_plugin/
init.rb
lib/
hooks.rb
The code we have written
init.rb
require_dependency 'hooks'
Redmine::Plugin.register :custom_plugin do
name 'custom_plugin'
author 'author name'
description 'description text'
version '1.0.0'
end
hooks.rb
class Hooks < Redmine::Hook::ViewListener
def controller_custom_fields_edit_after_save(context={ })
#target_custom_field_name = "Target_CF"
CustomField.find_by_name(#target_custom_field_name).possible_values.push(context[:custom_field].name)
end
end
The result of this code is none. I mean, no erros, no updates, nothing at all. There is no change in our possible values after editing/creating another custom field. We are sure there is something we don't know, some concept or workflow, and due to this we are doing something so badly.
Please, help us understeand what we are missing.
Previously we have succesfully developed another plugin that overwrites certain views. So we have kind of little skills in views related plugins, but zero experience at all at controllers ones.
We are using a Redmine 3.2.0 stack by Bitnami and a mysql database.
Well, finally we found out how to extend base controller's methods. I will post it here so hopefully this can be useful to anyone who finds the same doubts we had.
After some more researching, we conclude that it is mandatory to extend base controllers, in order to not directly modify core methods.
This is our final directories/files structures:
plugins/
custom_plugin/
init.rb
lib/
custom_plugin/
issue_custom_field_patch.rb
We previously stated that we could use some hooks to inject our desired functionality, but it seems not to work that way with controllers. On the other hand, we built a patch which will extend target class functionality.
Our final working code
Init.rb
require 'redmine'
ActionDispatch::Callbacks.to_prepare do
require_dependency 'issue_custom_field'
unless IssueCustomField.included_modules.include? CustomPlugin::IssueCustomFieldPatch
IssueCustomField.send(:include, CustomPlugin::IssueCustomFieldPatch)
end
end
Redmine::Plugin.register :custom_plugin do
name 'custom_plugin'
author 'author name'
description 'description text'
version '1.0.0'
end
issue_custom_field_patch.rb
module CustomPlugin
module IssueCustomFieldPatch
def self.included(base) # :nodoc:
base.extend(ClassMethods)
base.send(:include, InstanceMethods)
base.class_eval do
unloadable
after_save :update_possible_values
end
end
end
module ClassMethods
end
module InstanceMethods
def update_possible_values
self.reload
updatedPossibleValues unless self.name == "Target_CF"
end
private
def updatedPossibleValues
#safe_attrs = ['project', 'description', 'due_date', 'category', 'status', 'assigned_to', 'priority', 'fixed_version', 'author', 'lock_version', 'created_on', 'updated_on', 'start_date', 'done_ratio', 'estimated_hours', 'is_private', 'closed_on']
#custom_fields = IssueCustomField.all.select {|cf| !cf[:position].nil?}.collect {|cf| cf.name}
#possible_values = #safe_attrs + #custom_fields
CustomField.find_by_name("Target_CF").update possible_values: #possible_values
end
end
CustomField.send(:include, IssueCustomFieldPatch)
end
Functionality explained
As we stated in the question, we needed to update Target_CF possible values each time the users create/modify/removes a custom field from Redmine.
We extended IssueCustomField's class's instance methods, triggering our new function 'updatedPossibleValues' after each save. This includes creating new custom fields, and of course, updating existing ones and removing them. Because we reload our list of possible values each time, we had to control if its position were nil. If it is, this means that custom field has been removed.
Because of the ultimate action of this patch, which is the updating of another custom field, this also triggered our function, causing an infinite loop. To prevent this, we linked our functionality to every other custom field which name was not 'Target_CF'. A bit rusty fix, but we couldn't find a better approach.
I hope this can be useful to somebody in the future, as they could invest a fraction of time that we spent on this.
Comments, fixes and improvements are very welcome.
Based on: https://www.redmine.org/projects/redmine/wiki/Plugin_Internals which is a bit outdated, but finally could complete the code with help of another resources and forums.

Qlik Sense Extension (sense-export)

Has anyone used this extension (https://github.com/stefanwalther/sense-export)? It is an export button from GitHub.
It's pretty good, but I have not been able to have a specific filename. The default name is a unique identifier and I need to generate the excel file with a specific name to use it within another tool automatically.
A better place to ask these questions is on the github repository itself, Stefan who created the extension is very active in the Qlik community and I'm sure would be able to provide more detail - unfortunately the extensions by nature are not mainstream and you will not be able to get as much support for them as standard products.
Since it is an extension, you can change / customize the JavaScript to do whatever you want. In your case, in swr-sense-export.js, lines 48 through 53 are:
var exportOpts = {
format: $scope.layout.props.exportFormat,
state: $scope.layout.props.exportState,
filename: $scope.layout.props.exportFileName,
download: true
};
So you could change the filename to whatever you want.

phow_caltech101 to change categories in matlab (vlfeat) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm studying the Caltech101 computer vision dataset using Matlab..
I wanted to classify and train the images of caltech-101 using phow_caltech.m file
but there was a problem, I don't know how to change the categories...
these are what I did.
setup lv_setup
test version : vl_version verbose OK
vl_demo OK
make m_file phow_caltech101.m (copy)
I downloaded caltech101 images at [here][2] by myself and copied to data/caltech-101
>>phow_caltech101 (in command widnow)
I saw fixed example categories (BACKGROUND_Goole, Faces, Faces_easy, Leopards, Motobikes)
I've tried to change the example categories(BACKGROUND_Goole, Faces, Faces_easy, Leopards, Motobikes)
I want to use categories ( accordion, airplanes, anchor, ant in caltech-101)
I changed some codes of phow_caltech101.m but it didn't work...
plz give me some advice ... help me
I look forward to replying your mail or answer thank you~!
this is phow_caltech101 code
C:\VLFEAT\data\caltech-101 ( there are many image folders )
conf.calDir = 'data/caltech-101' ; ( I changed like this in phow_caltech101.m file)
From the help header to phow_caltech101:
The program can also be used to train a model on custom data by pointing CONF.CALDIR to it. Just create a subdirectory for each class and put the training images there. Make sure to adjust
CONF.NUMTRAIN accordingly.
Create a folder (say 'data/myclasses') containing the new classes (image collections) and have conf.caldir point to it, in phow_caltech101.m. That should be the first thing you change. There should be no need to change conf.prefiX if you are still putting the classes under data/.... but you need to adjust conf.numtrain to be the number of training sets you want to use.
caveat: my answer is based entirely on the documentation, I have not run the software.
Edit
Rather than attempt to run the script directly, start by trying to run the following lines at the matlab prompt, to check that you set up your folders correctly:
% the following line should contain the path to your data...
conf.calDir = 'data/caltech-101'; % <-- change this line if necessary
% make sure matlab finds the folder with your data
exist(conf.calDir, 'dir') % should return a "1"
% check the contents of the calibration data folder
classes = dir(conf.calDir)
If the folder does not exist or the contents being listed as classes are incorrect you need to adjust conf.calDir or the location of your data.