Do you use express.static(‘public’) OR (path.join(__dirname, ‘public’))? - express

My tree:
├── app.js
├── data
│ └── stuff.json
├── package.json
├── public
│ ├── index.html
│ ├── main.js
├── routes
└── api.js
Below are two lines I’ve used in my app.js file in order to serve the static file public/index.html
This first option works fine. As I understand it, it directs the user to the public directory relative to app.js:
app.use(express.static('public'))
The following second line doesn’t work. As I understand it, this is the absolute path to the public directory.
app.use(express.static(path.join(__dirname, 'public')))
The https://expressjs.com/en/starter/static-files.html seems to suggest the first option, yet most web sites and books encourage the second. Why/When is the second encouraged? And why doesn’t it work for me in this case?

Related

Kotlin Script: Import class across directories/packages

I'm new to Kotlin so forgive me if this is an easy question. I'm writing a kotlin script that I hope will utilize a custom Hashtable implementation to store data from a file. I'm having trouble getting the script to find the HashTable class.
Here is my structure:
.
├── scripts
│   ├── kotlin
│   │   ├── [other scripts]
│   │   └── wordcount.kts
│   └── tests
│   └── wc
│   └── smallfile.txt
└── src
├── main
│   └── kotlin
│      └── dataStructures
│         └── HashTable.kt
└── test
The script is wordcount.kts and the class I'm trying to import is in HashTable.kt. I tried import dataStructures.HashTable and import kotlin.dataStructures.HashTable to no avail. I also tried adjusting the PWD (in IntelliJ runtime configuration) to the project directory, also with no luck. How do I import HashTable correctly? Let me know if I can provide any further information!
import is used to link to things that are on your classpath, so before you can use that you need to allow the compiler to actually find that HashTable class.
You have a couple of options, I would however recommend to rename wordcount.kts to wordcount.main.kts (kotlin script requires the executable to be named x.main.kts for most features to work), HashTable.kt to HashTable.kts and link it with #file:Import(<path-to-hashtable.kts>).
If you can't rename the hashtable you will need to import it either by compiling it to a class file and adding it to the classpath with kotlinc -script -cp <dir-with-.class> wordcount.main.kts. Or compile to a jar and link the jar with #file:DependsOn<path-to-jar> in the script.
For the reference to all this stuff, look here: https://github.com/Kotlin/KEEP/blob/master/proposals/scripting-support.md

Cucumber runner not needed anymore?

Quick question - since when Cucumber doesn't need any separate runner class with steps glued etc? Nothing else is needed currently after adding JUnit dependency to pom.xml? I've just setup a simple project and as I can see nothing besides chromedriver, step definitions, feature files and Selenium/JUnit/Cucumber dependencies is needed. Was it always like that? Because I remember these projects were uneasy to setup because of that class and few other things. Was I just stupid back then, or did something change and it's easy now?
Quite a few things have improved! Just not the thing you mentioned.
When you are using the CLI (either directly or through IDEA) Cucumber will search the entire class path for step definitions and feature files. This means that things usually just work.
To integrate with JUnit4 you will still need a runner class. However unless you tell it otherwise with #CucumberOptions the runner class will look for features and glue in the package and subpackages it is in.
So if you put everything in the right group and in the same package no additional configuration is needed. You should make use of this!
There is a little gotcha when using maven. If you put your feature files in the src/test/java folder, maven won't copy them to your class path. Features should always go into src/test/resources.
~/Projects/cucumber/cucumber-jvm/examples/calculator-java-junit4$ tree
.
├── pom.xml
└── src
├── main
│   └── java
│   └── io
│   └── cucumber
│   └── examples
│   └── calculator
│   └── RpnCalculator.java
└── test
├── java
│   └── io
│   └── cucumber
│   └── examples
│   └── calculator
│   ├── RpnCalculatorSteps.java
│   └── RunCucumberTest.java
└── resources
├── cucumber.properties
└── io
└── cucumber
└── examples
└── calculator
└── basic_arithmetic.feature
You can also do the 10 minute tutorial to get a fresh start: https://cucumber.io/docs/guides/10-minute-tutorial/

Use module from parent directory in rust

Is it possible to structure a rust project in this way?
Directory structure:
src
├── a
│   └── bin1.rs
├── b
│   ├── bin2.rs
└── common
├── mod.rs
from Cargo.toml:
[[bin]]
name = "bin1"
path = "src/a/bin1.rs"
[[bin]]
name = "bin2"
path = "src/b/bin2.rs"
I would like to be able to use the common module in bin1.rs and bin2.rs. It's possible by adding the path attribute before the import:
#[path="../common/mod.rs"]
mod code;
Is there a way for bin1.rs and bin2.rs to use common without having to hardcode the path?
The recommended method to share code between binaries is to have a src/lib.rs file. Both binaries automatically have access to anything accessible through this lib.rs file as a separate crate.
Then you would simply define a mod common; in the src/lib.rs file. If your crate is called my_crate, your binaries would be able to use it with
use my_crate::common::Foo;

Conditional loading of Dojo modules

Let me first present directory structure of what I have
/
├── dojo/
├── dojox/
├── dijit/
└── app/
├── a/
│ └── moduleA.js
├── b/
│ └── moduleA.js
└── c/
I'm trying to configure Dojo to be able to load moduleA.js in following way:
require(["app/moduleA"]
and in the same time resolve it according to below pseudocode:
if moduleA exists in c
load "app/c/moduleA.js"
else if moduleA exists in b
load "app/b/moduleA.js"
else if moduleA exists in a
load "app/a/moduleA.js"
else
standard fail, same as when no module is defined
It would be great if order a, b and c could be passed as array for instance ["app/c/moduleA", "app/b/moduleA", "app/a/moduleA"].
I was looking into documentation hoping to find something, but no luck. https://dojotoolkit.org/reference-guide/1.7/loader/amd.html#module-identifiers was closest I got. There is packages.location property, but it takes string to load module, so I guess it has no additional logic regards to arrays.
Any idea how to solve this problem?

Can I attach a storyboard to a Static Library

I have a very simple single view application that I need to convert into a library.
I believe I am off to the correct start of going to my project settings and then adding a Cocoa Touch Static Library. After doing that I moved my ViewController.h, ViewController.m and Main.storyboard files to the new library directory.
I then went to my applications project settings and added my new library to the "Link Binary With Libraries". Then under the general tab I set the Main interface to nothing since I had moved the storyboard to the new library directory.
Then I went to my libraries project settings and add the Main.storyboard to the Copy Files. Lastly I deleted the two default .h and .m files that were created when I added the library and then added the ViewController.m file to the libraries Compile sources.
The app loads a blank screen and gives warnings because it can't access any of the inputs on the storyboard. How do I get library to load the storyboard or is this just completely wrong?
You need to make sure that the application (not the library) is copying the storyboard.
You should probably build a resource bundle for your resources (a zipped file that ends with .bundle).
There is a hack you could try if you really want to get down to one file, Embedded Frameworks.
Although frameworks are an improvement over libraries, Xcode ignores any resources contained within frameworks. So if you have xibs, images, sounds, or other files in your framework, Xcode won't see them. An embedded framework is a way to trick Xcode into seeing the included resources.
You can see the structure here.
KFData.embeddedframework
├── KFData.framework
│ ├── Headers -> Versions/Current/Headers
│ ├── KFData -> Versions/Current/KFData
│ ├── Resources -> Versions/Current/Resources
│ └── Versions
│ ├── A
│ │ ├── Headers
│ │ │ ├── ..
│ │ ├── KFData
│ │ └── Resources
│ │ ├── ACKNOWLEDGEMENTS
│ │ ├── Info.plist
│ │ ├── LICENSE
│ │ ├── KFData.bundle
│ │ │ ├── ..
│ │ ├── KFData.xcconfig
│ │ └── VERSION
│ └── Current -> A
└── Resources
├── KFData-Acknowledgements -> ../KFData.framework/Resources/ACKNOWLEDGEMENTS
├── KFData-License -> ../KFData.framework/Resources/LICENSE
├── KFData-Version -> ../KFData.framework/Resources/VERSION
├── KFData.bundle -> ../KFData.framework/Resources/KFData.bundle
└── KFData.xcconfig -> ../KFData.framework/Resources/KFData.xcconfig