Boilerplate generator - backbone.js

I'm looking for something similar to yeoman generator for creating boilerplate. But for creating boilerplate inside a existing project. I want to automate a creation of a new view on a large project, which includes the name of the view, and it would create a directories and a javascript for the view, a template, a style for the template, and then declare stuff on some specific file.
e.g. generate MyView
would create something like this
|-app
| '--views
| '-- MyView/MyView.js
| '--templates
| '-- MyView/MyView.html
| '-- MyView/MyView.less
|
| '--styles.less <- #include templates/MyView.less
| '--loader.js <- my_view : views/MyView.js

Related

What is a way to create a unique name for a file given it's name and a namespace value in the same directory?

I have to create a file name for a file that will exist with other files with the same or similar name in the same folder.
I have two values that will be used to define the name. The namespace and the class name.
So if there are a team of users and user A creates a Person class they have to give it a unique namespace name so if user B creates a Person class does not conflict with user A's class name.
Traditionally, namespaces are defined something like,
com.amazon.category.people
http://www.amazon.com/2022/categories/7.0.0
I'm ok with joining the namespace with the class name to create a unique phrase like so:
com.amazon.category.people::Person
BUT Here's the problem. When I'm creating a file, the filesystem doesn't like all those dots or colons Actually, I don't like them because multiple reasons. I thought about replacing all dots and colons with underscore.
com_amazon_category_people_Person.json
That's the best I've come up with. It won't work well with the other type of namespace:
http___www_amazon_com_2022_categories_7.0.0_Person
Are there any answers this problem?
Names containing dots aren't a problem for any OS, as far as I know. What you can do is either:
Put the files in a folder hierarchy, where every folder is the name of a namespace segment, like this:
+-me
| +-topchetoeu
| | +-myprogram
| | +-Program.json
| +-somebodyelse
| +-calculator
| +-Add.json
| +-Subtract.json
| +-Divide.json
| +-Multiply.json
+-com
+-microsoft
+-windows
+-Spyware.json
Another solution would be to separate the namespace segments with dashes, and the class name with a # symbol, resulting in something like this:
me-topchetoeu-myprogram#Program.json
me-somebodyelse-calculator#Add.json
me-somebodyelse-calculator#Subtract.json
me-somebodyelse-calculator#Divide.json
me-somebodyelse-calculator#Multiply.json
com-microsoft-windows#Spyware.json
etc...

Combining multiple external datasets with cucumber/selenium test environments

When developing automated tests using cucumber and selenium webdriver in java, I use excel spreadsheets as datasets for the gherkin scenarios instead of the traditional Examples tables, using a simple table with only the row numbers in my feature files. This works very well when doing tests that only make use of data from one spreadsheet at a time, but when implementing tests that make use of multiple spreadsheets, how does one ensure the it iterates over every combination.
For example, when testing multiple configurations and their impact on the main interface, I provide the configuration data, let's say 3 combinations of different configurations, using the first spreadsheet, and in my gherkin feature I only enter the row numbers and use the code to handle the actual reading of data.
When the user uses configuration from row <ExcelRow>
...
Examples:
| ExcelRow |
| 1 |
| 2 |
| 3 |
The problem arises when I want to test such configurations with different combinations of inputs in the main interface, also provided via a separate excel spreadsheet. I want configuration from row 1 to be run with all rows from the second spreadsheet, before moving on to row 2's configuration and so on.
Manually using the examples table to do the combinations does the job when working with smaller data sets
Examples:
| ConfigRow | InputRow |
| 1 | 1 |
| 1 | 2 |
| 2 | 1 |
| 2 | 2 |
| 3 | 1 |
| 3 | 2 |
The problem arises when using very large datasets, where the examples table starts to clutter the feature file despite only containing the row numbers.
I tried implementing the actual input testing as a single step that loops over the entire excel spreadsheet for each configuration, but that forced me to do my assertions in the same loop and not in the Then step.
If you want to mention only config row in feature file and you want that some other rows to be executed for each config row then you may want to utilize cucumber-guice and make it #ScenarioScoped . Cucumber-guice can initialize same classes for each scenario independently. You would need these dependencies in your pom
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-guice</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.3</version>
<scope>test</scope>
</dependency>
Then , in a global class you can do
import io.cucumber.guice.ScenarioScoped;
#ScenarioScoped
public class Global {
public Helpers help;
//constructor
public Global() {
//helper class would contain code that does all the second excel sheet work
help = new Helpers();
}
}
In step def you can do
//import Global and guice dependencies
import yourPackage.Global;
import com.google.inject.Inject;
...
...
public class stepDef {
#Inject
Global global;
#When ("the user uses configuration from row {int}")
public void useConfigs(){
global.help.doSomeExcelWork();
}
#Then ("I assert from excel sheet")
public void doAssertions(){
//do assertions here. These
global.help.doAssertion();
}
}
Your helper class could be something like this
public class Helper {
public void doSomeExcelWork(){
//do excel work
}
public void doAssertion(){
//return values for your assertions
}
}
Your feature file would look like
When the user uses configuration from row <ExcelRow>
Examples:
| ExcelRow |
| 1 |
| 2 |
Then I assert from excel sheet
Now , for all your examples (scenarios) global would be injected independently and the then statement also would be called for each example row
I am not sure if that is possible to do via Cucumber. You may try searching for Cucumber Java dynamic examples generation like here.
I just would like to question if Cucumber/Gherkin are the right tools for what you wanted to achieve. The primary goal of Gherkin / Cucumber / Specflow scenarios is demonstrate the behavior of the system to anyone reading the feature file. So hiding the data in "linked" files can be accepted if they hold a complex piece of data which is as a single unit, provided the file name demonstrates what is special about the data inside.
What you might be looking for are Parameterized Tests and Data Providers that are available in JUnit 5 and TestNG 2, 3. If you write automation framework in the way that Cucumber, or other test framework becomes only a thin wrapper around it which "assembles" the test, you can generate tests on the fly.
For example your step: "When the user uses configuration from row", becomes
public void whenUserUsesConfiguration(SutConfiguration configuration) {
// your configuration setup goes here
// but you do not read configuration from file in this method
}
Method above can be used in both Cucumber steps and JUnit/TestNG test without loosing any readability, or understandability.
By splitting your tests into two parts, one for understanding general system behavior and accessible to all stakeholders, and the one that check lots of small nuances, but both using the same framework will allow you to have greater flexibility, and more pleasant development experience.

API for getting contact info about College or University?

There are lots of resources for getting name, website, accreditation info, etc for higher education institutions such as the College Scorecard API or IPEDS. What I need for this project is to find a general contact information email address for my set of a few hundred colleges and universities. I plan on using Google Sheets and Apps Script to collect this data.
I have a spreadsheet such as
| Name | URL | City | State | Email |
|-----------------------|----------------------|-----------------|-------|-------|
| Prairie State College | www.prairiestate.edu | Chicago Heights | IL | |
| Langston University | www.langston.edu | Langston | OK | |
where I need to fill in the "email" column. Does anyone know any APIs that could help with that? A quick Google search tells me that ldickerson#prairiestate.edu is the contact at Prairie State College, whereas the admissions page of Langston University has luadmissions#langston.edu right on it. Does anyone have any ideas on where I can pull this data from automatically?
There is no direct API that can help you achieve that.
What you can do instead is to use UrlFetchApp from Apps Script and retrieve the page text from the admission/contact pages wanted. Afterwards you can retrieve the email address from the page text retrieved using regex.
The below code does the mentioned above but depending on the page, it may retrieve more than one email address. If you know exactly that the first email in the list is the email address you actually need, you can call email[0] instead.
function findMail() {
var url ="ADMISSION_CONTACT_PAGE_URL";
var pageText = UrlFetchApp.fetch(url).getContentText();
var email = pageText.match(/([a-zA-Z0-9._-]+#[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/gi);
Logger.log(email);
}
Reference
UrlFetchApp Class Apps Script;
Regex Tester.

Hide text lines/text patterns from a generated logfile

As my role as tester (among all the things), I need to review log files for errors. Unfortunatly, the generated output file (file-YYYY-MM-DD.log) displays all kinds of information, not just the errors (or "things that go bad").
My question is; how do I hide the lines I don't want and generate an output file (log) containing the deviations (errors, warnings etc)?
For example, I want to hide:
| I | variable text I do not want, location: /path/to/foo/bar
| W | service X stopped
| W | service X started
The most ideal outcome with the script I want is:
-> Ask question: "Do you want to hide information and warning messages? |
-> Answer: yes --> hide all | I | message (like: no new foo's found in: /location/to/foo.
-> Answer: no --> do nothing (closes script)
The data is from an Unix environment, however the script is going to run in an Windows environment.
Thanks

Saving a RichTextBox to a RTF File

For a project I am working on I am trying to save the contents of a WPF RichTextBox to a RTF file as the title states. I have it working for the most part. However, the file does not preserve newlines. When I save the file ( as you will see below ) it will save everything to one line in the RTF. You can see how it is saved below.
private void butSaveHistory_Click( object sender, RoutedEventArgs e ) {
Microsoft.Win32.SaveFileDialog myDlg = new Microsoft.Win32.SaveFileDialog();
myDlg.DefaultExt = "*.rtf";
myDlg.Filter = "RTF Files|*.rtf";
Nullable<bool> myResult = myDlg.ShowDialog();
if ( myResult == true ) {
/*using ( FileStream myStream = new FileStream( myDlg.FileName, FileMode.OpenOrCreate, FileAccess.Write ) ) {
TextRange myRange = new TextRange( rtbTraffic.Document.ContentStart, rtbTraffic.Document.ContentEnd );
myRange.Save( myStream, DataFormats.Rtf );
myStream.Close();
}*/
rtbTraffic.SelectAll();
rtbTraffic.Selection.Save( new FileStream( myDlg.FileName, FileMode.OpenOrCreate, FileAccess.Write ), DataFormats.Rtf );
}
}
AS you can see I tried two different ways. ( One is commented out ) Neither of these work, they both just save everything to one line when everything in the RichTextBox is on multiple lines.
So how can I get the file to save to multiple lines? Any tips or suggestions would be greatly appreciated.
Note: When saving to a .txt file it saves correctly to multiple lines. However, I cannot save to .txt because the colors and fonts of the RichTextBox need to be preserved.
Edit: This is a sample of what the RichTextBox looks like.
After saving the file it looks like this when i open the RTF in word.
This is what I want it to output.
Edit 2: Adding RTF code
{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}{\f3\fcharset0 Arial;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red0\green0\blue255;\red255\green0\blue0;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs18\f2\b\cf0 \cf0\ql{\f3 {\b0\cf2\highlight1\ltrch 09:10:48 | Thing | STATUS Tube_Heat_Consumer,TUBE_HEAT,3.14209:11:47 | Thing | STATUS Tube_Heat_Consumer,TUBE_HEAT,2.718}{\b0\cf3\highlight1\ltrch 09:58:49 | Thing | STOP STOP}{\b0\cf2\highlight1\ltrch 09:58:49 | Thing | STOP STOP}{\b0\highlight1\ltrch 09:58:57 | Thing | DeRegistration Successful}{\b0\cf4\highlight1\ltrch 09:58:58 | Thing | DeRegistration Failed ( Application is not currently registered ) | 81270401}{\b0\highlight1\ltrch 09:58:58 | Thing | Registration Successful}\li0\ri0\sa0\sb0\fi0\ql\par}
}
} Thing | DeRegistration Failed ( Application is not currently registered ) | 81270401}{\b0\highlight1\ltrch 08:55:21 | Thing | Registration Successful08:55:22 | Thing | DeRegistration Successful08:55:22 | Thing | Registration Successful}{\b0\cf2\highlight1\ltrch 08:55:22 | Thing | Registration Failed ( Application Thing already registered ) | 8127040008:55:22 | Thing | Registration Failed ( Application Thing already registered ) | 81270400}{\b0\highlight1\ltrch 08:55:23 | Thing | DeRegistration Successful08:55:23 | Thing | Registration Successful08:55:24 | Thing | DeRegistration Successful08:55:24 | Thing | Registration Successful08:55:25 | Thing | DeRegistration Successful}\li0\ri0\sa0\sb0\fi0\ql\par}
}
}
From the looks of it it is not encoding \par or \lines correctly.
It will be more simple to answer if you put some example of rtf code you try to save, the result you have and what you want.
I'm not sure of what you want to be in multiple line. The rtf in a more easiest "reading" format for human? Where one line in richtextbox is on one line in rtf format like this:
{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1036\fs18\f2\cf0 \cf0\ql
{\f2 {\ltrch aaaaa}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\ltrch bbbb}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\ltrch }\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\ltrch cccc}\li0\ri0\sa0\sb0\fi0\ql\par}
}
}
in richtextbox I see this
aaaa
bbbb
cccc
I'm not sure of the interest to do that, because newline is encode by \par for end of paragraphs and \line for new line in the current paragraph then when you open the rtf file with a program (MS Word for example) newlines are respected.
And I obtain the same with this:
{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1036\fs18\f2\cf0 \cf0\ql {\f2 {\ltrch aaaaa}\li0\ri0\sa0\sb0\fi0\ql\par}{\f2 {\ltrch bbbb}\li0\ri0\sa0\sb0\fi0\ql\par}{\f2 {\ltrch }\li0\ri0\sa0\sb0\fi0\ql\par}{\f2 {\ltrch cccc}\li0\ri0\sa0\sb0\fi0\ql\par}}}
Don't add the rtf code directly, use Wpf Paragraph and so on.
When you add your new line to RichTextBox use
YourParagraph.Inlines.Add(new LineBreak());
instead of \r\n or something like this.
As you can see in this post, if you add text as plaintext programaticaly to the RichTextBox control, you may have to add this unicode line separator \u2028. And it will normaly converted to \line in the Rtf saved file.
And I recommend you to use the method with TextRange.

Resources