Popular New Releases in Boilerplate
vite
create-vite@2.9.2
nuxt.js
ant-design-pro
electron-react-boilerplate
4.5.0
ignite
v7.10.9
Popular Libraries in Boilerplate
by h5bp javascript
52642 MIT
A professional front-end template for building fast, robust, and adaptable web apps or sites.
by vitejs typescript
40832 MIT
Next generation frontend tooling. It's fast!
by nuxt javascript
39155 NOASSERTION
The Intuitive Vue(2) Framework
by ant-design typescript
30014 MIT
👨🏻💻👩🏻💻 Use Ant Design like a Pro!
by react-boilerplate javascript
28264 MIT
:fire: A highly scalable, offline-first foundation with the best developer experience and a focus on performance and best practices.
by kriasoft typescript
21150 MIT
React Starter Kit — front-end starter kit using React, Relay, GraphQL, and JAM stack architecture
by electron-react-boilerplate typescript
19281 MIT
A Foundation for Scalable Cross-Platform Apps
by dhg css
18379 MIT
Skeleton: A Dead Simple, Responsive Boilerplate for Mobile-Friendly Development
by SimulatedGREG javascript
14317 MIT
An Electron & Vue.js quick start boilerplate with vue-cli scaffolding, common Vue plugins, electron-packager/electron-builder, unit/e2e testing, vue-devtools, and webpack.
Trending New libraries in Boilerplate
by vitejs typescript
40832 MIT
Next generation frontend tooling. It's fast!
by amplication typescript
7019 Apache-2.0
Amplication is an open‑source development tool. It helps you develop quality Node.js applications without spending time on repetitive coding tasks.
by benawad typescript
3410 MIT
Prettier for File Structures
by laravel php
3281 MIT
Tailwind scaffolding for the Laravel framework.
by testjavascript javascript
1892
✅ Master the art of the most powerful testing technique for Node.js: Component tests. Including super-comprehensive best practices list and an example app (November 2021)
by pankod typescript
1627
A well-structured production-ready frontend boilerplate with Typescript, Jest, testing-library, styled-component, Sass, Css, .env, Fetch, Axios, Reverse Proxy, Bundle Analyzer and 30+ plugin. For now, only creates projects for React and Next.js. https://pankod.github.io/superplate/
by laravel-frontend-presets php
1536 MIT
A TALL (Tailwind CSS, Alpine.js, Laravel and Livewire) Preset for Laravel
by flareact javascript
1393 MIT
Edge-rendered React framework built for Cloudflare Workers
by react-boilerplate typescript
1335 MIT
:fire: Setup Create React App with React Boilerplate. Highly scalable & Best DX & Performance Focused & Best practices.
Top Authors in Boilerplate
1
23 Libraries
640
2
19 Libraries
747
3
15 Libraries
31646
4
14 Libraries
178
5
14 Libraries
2987
6
13 Libraries
563
7
10 Libraries
3281
8
10 Libraries
69
9
9 Libraries
1759
10
9 Libraries
134
1
23 Libraries
640
2
19 Libraries
747
3
15 Libraries
31646
4
14 Libraries
178
5
14 Libraries
2987
6
13 Libraries
563
7
10 Libraries
3281
8
10 Libraries
69
9
9 Libraries
1759
10
9 Libraries
134
Trending Kits in Boilerplate
No Trending Kits are available at this moment for Boilerplate
Trending Discussions on Boilerplate
Is Kotlin's runCatching..also equivalent to try..finally?
How do I resolve error message: "Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-default option"
ESlint - Error: Must use import to load ES Module
Why are asynchronous runtimes like Tokio necessary?
Best practice when dealing with C++ iostreams
.NET 6.0 C# "new console template" - how to read CLI arguments?
Can I use DerivingVia to derive instances for data types isomorphic to tuples
Jetpack compose check if a function has been run in preview mode
AVPlayer AVPlayerWaitingWhileEvaluatingBufferingRateReason slow loading for larger videos
How to apply one signature test to multiple positionals
QUESTION
Is Kotlin's runCatching..also equivalent to try..finally?
Asked 2022-Mar-25 at 11:32I want to run cleanup code after a certain block of code completes, regardless of exceptions. This is not a closeable resource and I cannot use try-with-resources (or Kotlin's use
).
In Java, I could do the following:
1try {
2 // ... Run some code
3} catch(Exception ex) {
4 // ... Handle exception
5} finally {
6 // ... Cleanup code
7}
8
Is the following Kotlin code equivalent?
1try {
2 // ... Run some code
3} catch(Exception ex) {
4 // ... Handle exception
5} finally {
6 // ... Cleanup code
7}
8runCatching {
9 // ... Run some code
10}.also {
11 // ... Cleanup code
12}.onFailure {
13 // ... Handle exception
14}
15
Edit: added boilerplate exception handling - my concern is with ensuring the cleanup code runs, and maintainability.
ANSWER
Answered 2021-Oct-28 at 14:24As per Kotlin's doc for runCatching
:
Calls the specified function block and returns its encapsulated result if invocation was successful, catching any Throwable exception that was thrown from the block function execution and encapsulating it as a failure.
Even if finally
always runs after a try
block and also
always runs after a runCatching
, they do not serve the same purpose.
finally
doesn't receive any argument and cannot operate on the values of the try
block, while also
receives the Result of the runCatching
block.
TLDR; .runCatching{}.also{}
is a more advanced try{}finally{}
QUESTION
How do I resolve error message: "Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-default option"
Asked 2022-Mar-19 at 21:08I'm new to Android development and I'm currently building my first real app. I'm trying to implement a MVVM architecture and because of that I'm having a viewModel for each fragment and each viewModel has a viewModelFactory. At least, this is how I understood it has to be.
I use the boilerplate code everyone seems to use for the factory:
1class ExampleViewModelFactory(private val exampleDao: ExampleDao) : ViewModelProvider.Factory {
2 override fun <T : ViewModel> create(modelClass: Class<T>): T {
3 if (modelClass.isAssignableFrom(exampleViewModel::class.java)) {
4 @Suppress("UNCHECKED_CAST")
5 return ExampleViewModel(exampleDao) as T
6 }
7 throw IllegalArgumentException("Unknown ViewModel class")
8 }
9}
10
Now the problem is, that the compiler is giving me the following error:
e: C:\Users\ ...\ExampleViewModel.kt: (64, 7): Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-default option
And this error is produced by the viewModelFactory class I have implemented in the viewModel. I really can't tell what this means and I cant find anything helpful or even related to my specific problem. I basically followed some basic tutorials about creating your first app, but I keep on running into errors like this. In most cases, I was able to fix the problem by myself, but this time it's different.
I know that a lot of you have a lot of experience and knowledge, so I hope that some of you find the time to help me and give me a hint what I can do to fix this.
ANSWER
Answered 2022-Feb-25 at 16:53It seems like you are either directly or indirectly (through some other library) depending on Lifecycle 2.5.0-alpha01
.
As per this issue:
You need to temporarily add following to your
build.gradle
:
1class ExampleViewModelFactory(private val exampleDao: ExampleDao) : ViewModelProvider.Factory {
2 override fun <T : ViewModel> create(modelClass: Class<T>): T {
3 if (modelClass.isAssignableFrom(exampleViewModel::class.java)) {
4 @Suppress("UNCHECKED_CAST")
5 return ExampleViewModel(exampleDao) as T
6 }
7 throw IllegalArgumentException("Unknown ViewModel class")
8 }
9}
10tasks.withType(KotlinCompile).configureEach {
11 kotlinOptions {
12 freeCompilerArgs += [
13 "-Xjvm-default=all",
14 ]
15 }
16}
17
Note that in certain circumstances you may want to use all-compatibility
instead of all
, learn more about that in Jebrain's blogpost.
Starting with kotlin 1.6.20 you won't need touch build.gradle for more information see KT-47000
QUESTION
ESlint - Error: Must use import to load ES Module
Asked 2022-Mar-17 at 12:13I am currently setting up a boilerplate with React, Typescript, styled components, webpack etc. and I am getting an error when trying to run eslint:
Error: Must use import to load ES Module
Here is a more verbose version of the error:
1/Users/ben/Desktop/development projects/react-boilerplate-styled-context/src/api/api.ts
2 0:0 error Parsing error: Must use import to load ES Module: /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js
3require() of ES modules is not supported.
4require() of /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/babel-eslint/lib/require-from-eslint.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
5Instead rename definition.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/package.json
6
The error occurs in every single one of my .js and .ts/ .tsx files where I only use import
or the file doesn't even have an import at all. I understand what the error is saying but I have no idea why it is being thrown when in fact I only use imports or even no imports at all in some files.
Here is my package.json where I trigger the linter from using npm run lint:eslint:quiet
:
1/Users/ben/Desktop/development projects/react-boilerplate-styled-context/src/api/api.ts
2 0:0 error Parsing error: Must use import to load ES Module: /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js
3require() of ES modules is not supported.
4require() of /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/babel-eslint/lib/require-from-eslint.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
5Instead rename definition.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/package.json
6{
7 "name": "my-react-boilerplate",
8 "version": "1.0.0",
9 "description": "",
10 "main": "index.tsx",
11 "directories": {
12 "test": "test"
13 },
14 "engines": {
15 "node": ">=14.0.0"
16 },
17 "type": "module",
18 "scripts": {
19 "build": "webpack --config webpack.prod.js",
20 "dev": "webpack serve --config webpack.dev.js",
21 "lint": "npm run typecheck && npm run lint:css && npm run lint:eslint:quiet",
22 "lint:css": "stylelint './src/**/*.{js,ts,tsx}'",
23 "lint:eslint:quiet": "eslint --ext .ts,.tsx,.js,.jsx ./src --no-error-on-unmatched-pattern --quiet",
24 "lint:eslint": "eslint --ext .ts,.tsx,.js,.jsx ./src --no-error-on-unmatched-pattern",
25 "lint:eslint:fix": "eslint --ext .ts,.tsx,.js,.jsx ./src --no-error-on-unmatched-pattern --quiet --fix",
26 "test": "cross-env NODE_ENV=test jest --coverage",
27 "test:watch": "cross-env NODE_ENV=test jest --watchAll",
28 "typecheck": "tsc --noEmit",
29 "precommit": "npm run lint"
30 },
31 "lint-staged": {
32 "*.{ts,tsx,js,jsx}": [
33 "npm run lint:eslint:fix",
34 "git add --force"
35 ],
36 "*.{md,json}": [
37 "prettier --write",
38 "git add --force"
39 ]
40 },
41 "husky": {
42 "hooks": {
43 "pre-commit": "npx lint-staged && npm run typecheck"
44 }
45 },
46 "resolutions": {
47 "styled-components": "^5"
48 },
49 "author": "",
50 "license": "ISC",
51 "devDependencies": {
52 "@babel/core": "^7.5.4",
53 "@babel/plugin-proposal-class-properties": "^7.5.0",
54 "@babel/preset-env": "^7.5.4",
55 "@babel/preset-react": "^7.0.0",
56 "@types/history": "^4.7.6",
57 "@types/react": "^17.0.29",
58 "@types/react-dom": "^17.0.9",
59 "@types/react-router": "^5.1.17",
60 "@types/react-router-dom": "^5.1.5",
61 "@types/styled-components": "^5.1.15",
62 "@typescript-eslint/eslint-plugin": "^5.0.0",
63 "babel-cli": "^6.26.0",
64 "babel-eslint": "^10.0.2",
65 "babel-loader": "^8.0.0-beta.6",
66 "babel-polyfill": "^6.26.0",
67 "babel-preset-env": "^1.7.0",
68 "babel-preset-react": "^6.24.1",
69 "babel-preset-stage-2": "^6.24.1",
70 "clean-webpack-plugin": "^4.0.0",
71 "dotenv-webpack": "^7.0.3",
72 "error-overlay-webpack-plugin": "^1.0.0",
73 "eslint": "^8.0.0",
74 "eslint-config-airbnb": "^18.2.0",
75 "eslint-config-prettier": "^8.3.0",
76 "eslint-config-with-prettier": "^6.0.0",
77 "eslint-plugin-compat": "^3.3.0",
78 "eslint-plugin-import": "^2.25.2",
79 "eslint-plugin-jsx-a11y": "^6.2.3",
80 "eslint-plugin-prettier": "^4.0.0",
81 "eslint-plugin-react": "^7.14.2",
82 "eslint-plugin-react-hooks": "^4.2.0",
83 "extract-text-webpack-plugin": "^3.0.2",
84 "file-loader": "^6.2.0",
85 "html-webpack-plugin": "^5.3.2",
86 "husky": "^7.0.2",
87 "prettier": "^2.4.1",
88 "raw-loader": "^4.0.2",
89 "style-loader": "^3.3.0",
90 "stylelint": "^13.13.1",
91 "stylelint-config-recommended": "^5.0.0",
92 "stylelint-config-styled-components": "^0.1.1",
93 "stylelint-processor-styled-components": "^1.10.0",
94 "ts-loader": "^9.2.6",
95 "tslint": "^6.1.3",
96 "typescript": "^4.4.4",
97 "url-loader": "^4.1.1",
98 "webpack": "^5.58.2",
99 "webpack-cli": "^4.2.0",
100 "webpack-dev-server": "^4.3.1",
101 "webpack-merge": "^5.3.0"
102 },
103 "dependencies": {
104 "history": "^4.10.0",
105 "process": "^0.11.10",
106 "react": "^17.0.1",
107 "react-dom": "^17.0.1",
108 "react-router-dom": "^5.2.0",
109 "styled-components": "^5.2.1"
110 }
111}
112
Here is my .eslintrc file:
1/Users/ben/Desktop/development projects/react-boilerplate-styled-context/src/api/api.ts
2 0:0 error Parsing error: Must use import to load ES Module: /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js
3require() of ES modules is not supported.
4require() of /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/babel-eslint/lib/require-from-eslint.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
5Instead rename definition.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/package.json
6{
7 "name": "my-react-boilerplate",
8 "version": "1.0.0",
9 "description": "",
10 "main": "index.tsx",
11 "directories": {
12 "test": "test"
13 },
14 "engines": {
15 "node": ">=14.0.0"
16 },
17 "type": "module",
18 "scripts": {
19 "build": "webpack --config webpack.prod.js",
20 "dev": "webpack serve --config webpack.dev.js",
21 "lint": "npm run typecheck && npm run lint:css && npm run lint:eslint:quiet",
22 "lint:css": "stylelint './src/**/*.{js,ts,tsx}'",
23 "lint:eslint:quiet": "eslint --ext .ts,.tsx,.js,.jsx ./src --no-error-on-unmatched-pattern --quiet",
24 "lint:eslint": "eslint --ext .ts,.tsx,.js,.jsx ./src --no-error-on-unmatched-pattern",
25 "lint:eslint:fix": "eslint --ext .ts,.tsx,.js,.jsx ./src --no-error-on-unmatched-pattern --quiet --fix",
26 "test": "cross-env NODE_ENV=test jest --coverage",
27 "test:watch": "cross-env NODE_ENV=test jest --watchAll",
28 "typecheck": "tsc --noEmit",
29 "precommit": "npm run lint"
30 },
31 "lint-staged": {
32 "*.{ts,tsx,js,jsx}": [
33 "npm run lint:eslint:fix",
34 "git add --force"
35 ],
36 "*.{md,json}": [
37 "prettier --write",
38 "git add --force"
39 ]
40 },
41 "husky": {
42 "hooks": {
43 "pre-commit": "npx lint-staged && npm run typecheck"
44 }
45 },
46 "resolutions": {
47 "styled-components": "^5"
48 },
49 "author": "",
50 "license": "ISC",
51 "devDependencies": {
52 "@babel/core": "^7.5.4",
53 "@babel/plugin-proposal-class-properties": "^7.5.0",
54 "@babel/preset-env": "^7.5.4",
55 "@babel/preset-react": "^7.0.0",
56 "@types/history": "^4.7.6",
57 "@types/react": "^17.0.29",
58 "@types/react-dom": "^17.0.9",
59 "@types/react-router": "^5.1.17",
60 "@types/react-router-dom": "^5.1.5",
61 "@types/styled-components": "^5.1.15",
62 "@typescript-eslint/eslint-plugin": "^5.0.0",
63 "babel-cli": "^6.26.0",
64 "babel-eslint": "^10.0.2",
65 "babel-loader": "^8.0.0-beta.6",
66 "babel-polyfill": "^6.26.0",
67 "babel-preset-env": "^1.7.0",
68 "babel-preset-react": "^6.24.1",
69 "babel-preset-stage-2": "^6.24.1",
70 "clean-webpack-plugin": "^4.0.0",
71 "dotenv-webpack": "^7.0.3",
72 "error-overlay-webpack-plugin": "^1.0.0",
73 "eslint": "^8.0.0",
74 "eslint-config-airbnb": "^18.2.0",
75 "eslint-config-prettier": "^8.3.0",
76 "eslint-config-with-prettier": "^6.0.0",
77 "eslint-plugin-compat": "^3.3.0",
78 "eslint-plugin-import": "^2.25.2",
79 "eslint-plugin-jsx-a11y": "^6.2.3",
80 "eslint-plugin-prettier": "^4.0.0",
81 "eslint-plugin-react": "^7.14.2",
82 "eslint-plugin-react-hooks": "^4.2.0",
83 "extract-text-webpack-plugin": "^3.0.2",
84 "file-loader": "^6.2.0",
85 "html-webpack-plugin": "^5.3.2",
86 "husky": "^7.0.2",
87 "prettier": "^2.4.1",
88 "raw-loader": "^4.0.2",
89 "style-loader": "^3.3.0",
90 "stylelint": "^13.13.1",
91 "stylelint-config-recommended": "^5.0.0",
92 "stylelint-config-styled-components": "^0.1.1",
93 "stylelint-processor-styled-components": "^1.10.0",
94 "ts-loader": "^9.2.6",
95 "tslint": "^6.1.3",
96 "typescript": "^4.4.4",
97 "url-loader": "^4.1.1",
98 "webpack": "^5.58.2",
99 "webpack-cli": "^4.2.0",
100 "webpack-dev-server": "^4.3.1",
101 "webpack-merge": "^5.3.0"
102 },
103 "dependencies": {
104 "history": "^4.10.0",
105 "process": "^0.11.10",
106 "react": "^17.0.1",
107 "react-dom": "^17.0.1",
108 "react-router-dom": "^5.2.0",
109 "styled-components": "^5.2.1"
110 }
111}
112{
113 "extends": ["airbnb", "prettier"],
114 "parser": "babel-eslint",
115 "plugins": ["prettier", "@typescript-eslint"],
116 "parserOptions": {
117 "ecmaVersion": 8,
118 "ecmaFeatures": {
119 "experimentalObjectRestSpread": true,
120 "impliedStrict": true,
121 "classes": true
122 }
123 },
124 "env": {
125 "browser": true,
126 "node": true,
127 "jest": true
128 },
129 "rules": {
130 "arrow-body-style": ["error", "as-needed"],
131 "class-methods-use-this": 0,
132 "react/jsx-filename-extension": 0,
133 "global-require": 0,
134 "react/destructuring-assignment": 0,
135 "import/named": 2,
136 "linebreak-style": 0,
137 "import/no-dynamic-require": 0,
138 "import/no-named-as-default": 0,
139 "import/no-unresolved": 2,
140 "import/prefer-default-export": 0,
141 "semi": [2, "always"],
142 "max-len": [
143 "error",
144 {
145 "code": 80,
146 "ignoreUrls": true,
147 "ignoreComments": true,
148 "ignoreStrings": true,
149 "ignoreTemplateLiterals": true
150 }
151 ],
152 "new-cap": [
153 2,
154 {
155 "capIsNew": false,
156 "newIsCap": true
157 }
158 ],
159 "no-param-reassign": 0,
160 "no-shadow": 0,
161 "no-tabs": 2,
162 "no-underscore-dangle": 0,
163 "react/forbid-prop-types": [
164 "error",
165 {
166 "forbid": ["any"]
167 }
168 ],
169 "import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
170 "react/jsx-no-bind": [
171 "error",
172 {
173 "ignoreRefs": true,
174 "allowArrowFunctions": true,
175 "allowBind": false
176 }
177 ],
178 "react/no-unknown-property": [
179 2,
180 {
181 "ignore": ["itemscope", "itemtype", "itemprop"]
182 }
183 ]
184 }
185}
186
And i'm not sure if relevant but also my tsconfig.eslint.json file:
1/Users/ben/Desktop/development projects/react-boilerplate-styled-context/src/api/api.ts
2 0:0 error Parsing error: Must use import to load ES Module: /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js
3require() of ES modules is not supported.
4require() of /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/babel-eslint/lib/require-from-eslint.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
5Instead rename definition.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/package.json
6{
7 "name": "my-react-boilerplate",
8 "version": "1.0.0",
9 "description": "",
10 "main": "index.tsx",
11 "directories": {
12 "test": "test"
13 },
14 "engines": {
15 "node": ">=14.0.0"
16 },
17 "type": "module",
18 "scripts": {
19 "build": "webpack --config webpack.prod.js",
20 "dev": "webpack serve --config webpack.dev.js",
21 "lint": "npm run typecheck && npm run lint:css && npm run lint:eslint:quiet",
22 "lint:css": "stylelint './src/**/*.{js,ts,tsx}'",
23 "lint:eslint:quiet": "eslint --ext .ts,.tsx,.js,.jsx ./src --no-error-on-unmatched-pattern --quiet",
24 "lint:eslint": "eslint --ext .ts,.tsx,.js,.jsx ./src --no-error-on-unmatched-pattern",
25 "lint:eslint:fix": "eslint --ext .ts,.tsx,.js,.jsx ./src --no-error-on-unmatched-pattern --quiet --fix",
26 "test": "cross-env NODE_ENV=test jest --coverage",
27 "test:watch": "cross-env NODE_ENV=test jest --watchAll",
28 "typecheck": "tsc --noEmit",
29 "precommit": "npm run lint"
30 },
31 "lint-staged": {
32 "*.{ts,tsx,js,jsx}": [
33 "npm run lint:eslint:fix",
34 "git add --force"
35 ],
36 "*.{md,json}": [
37 "prettier --write",
38 "git add --force"
39 ]
40 },
41 "husky": {
42 "hooks": {
43 "pre-commit": "npx lint-staged && npm run typecheck"
44 }
45 },
46 "resolutions": {
47 "styled-components": "^5"
48 },
49 "author": "",
50 "license": "ISC",
51 "devDependencies": {
52 "@babel/core": "^7.5.4",
53 "@babel/plugin-proposal-class-properties": "^7.5.0",
54 "@babel/preset-env": "^7.5.4",
55 "@babel/preset-react": "^7.0.0",
56 "@types/history": "^4.7.6",
57 "@types/react": "^17.0.29",
58 "@types/react-dom": "^17.0.9",
59 "@types/react-router": "^5.1.17",
60 "@types/react-router-dom": "^5.1.5",
61 "@types/styled-components": "^5.1.15",
62 "@typescript-eslint/eslint-plugin": "^5.0.0",
63 "babel-cli": "^6.26.0",
64 "babel-eslint": "^10.0.2",
65 "babel-loader": "^8.0.0-beta.6",
66 "babel-polyfill": "^6.26.0",
67 "babel-preset-env": "^1.7.0",
68 "babel-preset-react": "^6.24.1",
69 "babel-preset-stage-2": "^6.24.1",
70 "clean-webpack-plugin": "^4.0.0",
71 "dotenv-webpack": "^7.0.3",
72 "error-overlay-webpack-plugin": "^1.0.0",
73 "eslint": "^8.0.0",
74 "eslint-config-airbnb": "^18.2.0",
75 "eslint-config-prettier": "^8.3.0",
76 "eslint-config-with-prettier": "^6.0.0",
77 "eslint-plugin-compat": "^3.3.0",
78 "eslint-plugin-import": "^2.25.2",
79 "eslint-plugin-jsx-a11y": "^6.2.3",
80 "eslint-plugin-prettier": "^4.0.0",
81 "eslint-plugin-react": "^7.14.2",
82 "eslint-plugin-react-hooks": "^4.2.0",
83 "extract-text-webpack-plugin": "^3.0.2",
84 "file-loader": "^6.2.0",
85 "html-webpack-plugin": "^5.3.2",
86 "husky": "^7.0.2",
87 "prettier": "^2.4.1",
88 "raw-loader": "^4.0.2",
89 "style-loader": "^3.3.0",
90 "stylelint": "^13.13.1",
91 "stylelint-config-recommended": "^5.0.0",
92 "stylelint-config-styled-components": "^0.1.1",
93 "stylelint-processor-styled-components": "^1.10.0",
94 "ts-loader": "^9.2.6",
95 "tslint": "^6.1.3",
96 "typescript": "^4.4.4",
97 "url-loader": "^4.1.1",
98 "webpack": "^5.58.2",
99 "webpack-cli": "^4.2.0",
100 "webpack-dev-server": "^4.3.1",
101 "webpack-merge": "^5.3.0"
102 },
103 "dependencies": {
104 "history": "^4.10.0",
105 "process": "^0.11.10",
106 "react": "^17.0.1",
107 "react-dom": "^17.0.1",
108 "react-router-dom": "^5.2.0",
109 "styled-components": "^5.2.1"
110 }
111}
112{
113 "extends": ["airbnb", "prettier"],
114 "parser": "babel-eslint",
115 "plugins": ["prettier", "@typescript-eslint"],
116 "parserOptions": {
117 "ecmaVersion": 8,
118 "ecmaFeatures": {
119 "experimentalObjectRestSpread": true,
120 "impliedStrict": true,
121 "classes": true
122 }
123 },
124 "env": {
125 "browser": true,
126 "node": true,
127 "jest": true
128 },
129 "rules": {
130 "arrow-body-style": ["error", "as-needed"],
131 "class-methods-use-this": 0,
132 "react/jsx-filename-extension": 0,
133 "global-require": 0,
134 "react/destructuring-assignment": 0,
135 "import/named": 2,
136 "linebreak-style": 0,
137 "import/no-dynamic-require": 0,
138 "import/no-named-as-default": 0,
139 "import/no-unresolved": 2,
140 "import/prefer-default-export": 0,
141 "semi": [2, "always"],
142 "max-len": [
143 "error",
144 {
145 "code": 80,
146 "ignoreUrls": true,
147 "ignoreComments": true,
148 "ignoreStrings": true,
149 "ignoreTemplateLiterals": true
150 }
151 ],
152 "new-cap": [
153 2,
154 {
155 "capIsNew": false,
156 "newIsCap": true
157 }
158 ],
159 "no-param-reassign": 0,
160 "no-shadow": 0,
161 "no-tabs": 2,
162 "no-underscore-dangle": 0,
163 "react/forbid-prop-types": [
164 "error",
165 {
166 "forbid": ["any"]
167 }
168 ],
169 "import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
170 "react/jsx-no-bind": [
171 "error",
172 {
173 "ignoreRefs": true,
174 "allowArrowFunctions": true,
175 "allowBind": false
176 }
177 ],
178 "react/no-unknown-property": [
179 2,
180 {
181 "ignore": ["itemscope", "itemtype", "itemprop"]
182 }
183 ]
184 }
185}
186{
187 "extends": "./tsconfig.json",
188 "include": ["./src/**/*.ts", "./src/**/*.tsx", "./src/**/*.js"],
189 "exclude": ["node_modules/**", "build/**", "coverage/**"]
190}
191
Not sure if anyone has come across this before? Googling the error does not present any useful forums or raised bugs, most of them just state not to use require
in your files which I am not.
ANSWER
Answered 2022-Mar-15 at 16:08I think the problem is that you are trying to use the deprecated babel-eslint parser, last updated a year ago, which looks like it doesn't support ES6 modules. Updating to the latest parser seems to work, at least for simple linting.
So, do this:
- In package.json, update the line
"babel-eslint": "^10.0.2",
to"@babel/eslint-parser": "^7.5.4",
. This works with the code above but it may be better to use the latest version, which at the time of writing is 7.16.3. - Run
npm i
from a terminal/command prompt in the folder - In .eslintrc, update the parser line
"parser": "babel-eslint",
to"parser": "@babel/eslint-parser",
- In .eslintrc, add
"requireConfigFile": false,
to the parserOptions section (underneath"ecmaVersion": 8,
) (I needed this or babel was looking for config files I don't have) - Run the command to lint a file
Then, for me with just your two configuration files, the error goes away and I get appropriate linting errors.
QUESTION
Why are asynchronous runtimes like Tokio necessary?
Asked 2022-Mar-04 at 21:46My first experience doing a computer system project was building a server using vanilla Java and then a client on an Android phone. Since then, I've found that there are a lot of frameworks to help manage scalability and remove the need to write boilerplate code.
I'm trying to understand what services like Tokio and Rayon enable.
I came across this paragraph on the Tokio tutorial page and I'm having a hard time understanding it
When you write your application in an asynchronous manner, you enable it to scale much better by reducing the cost of doing many things at the same time. However, asynchronous Rust code does not run on its own, so you must choose a runtime to execute it.
I first thought a "runtime" might refer to where the binary can run, but it looks like Tokio just provides functions that are already available in the Rust standard library while Rayon implements functions that aren't in the standard library.
Are the standard implementations for asynchronous functions written poorly in the standard library or am I not understanding what service Tokio is providing?
ANSWER
Answered 2022-Mar-04 at 21:41Rust currently does not provide an async runtime in the standard library. For full details, see Asynchronous Programming in Rust, and particularly the chapter on "The Async Ecosystem."
Rust currently provides only the bare essentials for writing async code. Importantly, executors, tasks, reactors, combinators, and low-level I/O futures and traits are not yet provided in the standard library. In the meantime, community-provided async ecosystems fill in these gaps.
Rust has very strict backward compatibility requirements, and they haven't chosen to lock-in a specific runtime. There are reasons to pick one over another (features versus size for example), and making it part of the standard library would impose certain choices that aren't clearly the right ones for all projects. This may change in the future as the community projects better explore this space and help determine the best mix of choices without the strong backward compatibility promises.
QUESTION
Best practice when dealing with C++ iostreams
Asked 2022-Mar-03 at 13:00I'm writing a command-line utility for some text processing. I need a helper function (or two) that does the following:
- If the filename is
-
, return standard input/output; - Otherwise, create and open a file, check for error, and return it.
And here comes my question: what is the best practice to design/implement such a function? What should it look like?
I first considered the old-school FILE*
:
1FILE *open_for_read(const char *filename)
2{
3 if (strcmp(filename, "-") == 0)
4 {
5 return stdin;
6 }
7 else
8 {
9 auto fp = fopen(filename, "r");
10 if (fp == NULL)
11 {
12 throw runtime_error(filename);
13 }
14 return fp;
15 }
16}
17
It works, and it's safe to fclose(stdin)
later on (in case one doesn't forget to), but then I would lose access to the stream methods such as std::getline
.
So I figure, the modern C++ way would be to use smart pointers with streams. At first, I tried
1FILE *open_for_read(const char *filename)
2{
3 if (strcmp(filename, "-") == 0)
4 {
5 return stdin;
6 }
7 else
8 {
9 auto fp = fopen(filename, "r");
10 if (fp == NULL)
11 {
12 throw runtime_error(filename);
13 }
14 return fp;
15 }
16}
17unique_ptr<istream> open_for_read(const string& filename);
18
This works for ifstream
but not for cin
, because you can't delete cin
. So I have to supply a custom deleter (that does nothing) for the cin
case. But suddenly, it fails to compile, because apparently, when supplied a custom deleter, the unique_ptr
becomes a different type.
Eventually, after many tweaks and searches on StackOverflow, this is the best I can come up with:
1FILE *open_for_read(const char *filename)
2{
3 if (strcmp(filename, "-") == 0)
4 {
5 return stdin;
6 }
7 else
8 {
9 auto fp = fopen(filename, "r");
10 if (fp == NULL)
11 {
12 throw runtime_error(filename);
13 }
14 return fp;
15 }
16}
17unique_ptr<istream> open_for_read(const string& filename);
18unique_ptr<istream, void (*)(istream *)> open_for_read(const string &filename)
19{
20 if (filename == "-")
21 {
22 return {static_cast<istream *>(&cin), [](istream *) {}};
23 }
24 else
25 {
26 unique_ptr<istream, void (*)(istream *)> pifs{new ifstream(filename), [](istream *is)
27 {
28 delete static_cast<ifstream *>(is);
29 }};
30 if (!pifs->good())
31 {
32 throw runtime_error(filename);
33 }
34 return pifs;
35 }
36}
37
It is type-safe and memory-safe (or at least I believe so; do correct me if I'm wrong), but this looks kind of ugly and boilerplate, and above all, it is such a headache to just get it to compile.
Am I doing it wrong and missing something here? There's gotta be a better way.
ANSWER
Answered 2022-Mar-03 at 11:42I would probably make it into
1FILE *open_for_read(const char *filename)
2{
3 if (strcmp(filename, "-") == 0)
4 {
5 return stdin;
6 }
7 else
8 {
9 auto fp = fopen(filename, "r");
10 if (fp == NULL)
11 {
12 throw runtime_error(filename);
13 }
14 return fp;
15 }
16}
17unique_ptr<istream> open_for_read(const string& filename);
18unique_ptr<istream, void (*)(istream *)> open_for_read(const string &filename)
19{
20 if (filename == "-")
21 {
22 return {static_cast<istream *>(&cin), [](istream *) {}};
23 }
24 else
25 {
26 unique_ptr<istream, void (*)(istream *)> pifs{new ifstream(filename), [](istream *is)
27 {
28 delete static_cast<ifstream *>(is);
29 }};
30 if (!pifs->good())
31 {
32 throw runtime_error(filename);
33 }
34 return pifs;
35 }
36}
37std::istream& open_for_read(std::ifstream& ifs, const std::string& filename) {
38 return filename == "-" ? std::cin : (ifs.open(filename), ifs);
39}
40
and then supply an ifstream
to the function.
1FILE *open_for_read(const char *filename)
2{
3 if (strcmp(filename, "-") == 0)
4 {
5 return stdin;
6 }
7 else
8 {
9 auto fp = fopen(filename, "r");
10 if (fp == NULL)
11 {
12 throw runtime_error(filename);
13 }
14 return fp;
15 }
16}
17unique_ptr<istream> open_for_read(const string& filename);
18unique_ptr<istream, void (*)(istream *)> open_for_read(const string &filename)
19{
20 if (filename == "-")
21 {
22 return {static_cast<istream *>(&cin), [](istream *) {}};
23 }
24 else
25 {
26 unique_ptr<istream, void (*)(istream *)> pifs{new ifstream(filename), [](istream *is)
27 {
28 delete static_cast<ifstream *>(is);
29 }};
30 if (!pifs->good())
31 {
32 throw runtime_error(filename);
33 }
34 return pifs;
35 }
36}
37std::istream& open_for_read(std::ifstream& ifs, const std::string& filename) {
38 return filename == "-" ? std::cin : (ifs.open(filename), ifs);
39}
40std::ifstream ifs;
41auto& is = open_for_read(ifs, the_filename);
42
43// now use `is` everywhere:
44if(!is) { /* error */ }
45
46while(std::getline(is, line)) {
47 // ...
48}
49
ifs
will, if it was opened, be closed when it goes out of scope as usual.
A throwing version might look like this:
1FILE *open_for_read(const char *filename)
2{
3 if (strcmp(filename, "-") == 0)
4 {
5 return stdin;
6 }
7 else
8 {
9 auto fp = fopen(filename, "r");
10 if (fp == NULL)
11 {
12 throw runtime_error(filename);
13 }
14 return fp;
15 }
16}
17unique_ptr<istream> open_for_read(const string& filename);
18unique_ptr<istream, void (*)(istream *)> open_for_read(const string &filename)
19{
20 if (filename == "-")
21 {
22 return {static_cast<istream *>(&cin), [](istream *) {}};
23 }
24 else
25 {
26 unique_ptr<istream, void (*)(istream *)> pifs{new ifstream(filename), [](istream *is)
27 {
28 delete static_cast<ifstream *>(is);
29 }};
30 if (!pifs->good())
31 {
32 throw runtime_error(filename);
33 }
34 return pifs;
35 }
36}
37std::istream& open_for_read(std::ifstream& ifs, const std::string& filename) {
38 return filename == "-" ? std::cin : (ifs.open(filename), ifs);
39}
40std::ifstream ifs;
41auto& is = open_for_read(ifs, the_filename);
42
43// now use `is` everywhere:
44if(!is) { /* error */ }
45
46while(std::getline(is, line)) {
47 // ...
48}
49std::istream& open_for_read(std::ifstream& ifs, const std::string& filename) {
50 if(filename == "-") return std::cin;
51 ifs.open(filename);
52 if(!ifs) throw std::runtime_error(filename + ": " + std::strerror(errno));
53 return ifs;
54}
55
QUESTION
.NET 6.0 C# "new console template" - how to read CLI arguments?
Asked 2022-Feb-25 at 07:39Now that .NET 6.0 is out, what appears to have be a radical update to the default CLI project template is the absence of the familiar boilerplate being reduced to the following:
1// See https://aka.ms/new-console-template for more information
2Console.WriteLine("Hello, World!");
3
What is not clear (and I have been trying to find documentation thus far, to no avail) is how does one access the command-line arguments passed to the executable's entrypoint class?
ANSWER
Answered 2021-Nov-28 at 11:00You can access the command line arguments from anywhere in your code using the Environment class.
In particular, you can use Environment.GetCommandLineArgs:
1// See https://aka.ms/new-console-template for more information
2Console.WriteLine("Hello, World!");
3string name = Environment.GetCommandLineArgs()[1];
4Console.WriteLine($"Hello, {name}!");
5
Note that the first element in the array contains the path of the executable and the arguments passed to the program start with the second element, i.e. at index 1.
QUESTION
Can I use DerivingVia to derive instances for data types isomorphic to tuples
Asked 2022-Feb-21 at 11:48Given the following data type
1data Both a b = Both { left :: a, right :: b }
2
I can write instances for Applicative etc. like so (omitting Functor here as we can use DeriveFunctor
):
1data Both a b = Both { left :: a, right :: b }
2instance Monoid a => Applicative (Both a) where
3 pure x = Both mempty x
4 Both u f <*> Both v x = Both (u <> v) (f x)
5
Since Both
is isomorphic to (a,b)
, I'm wondering whether I can use DerivingVia
to derive the instance:
1data Both a b = Both { left :: a, right :: b }
2instance Monoid a => Applicative (Both a) where
3 pure x = Both mempty x
4 Both u f <*> Both v x = Both (u <> v) (f x)
5data Both a b = ... deriving Applicative via ((,) a)
6
which results in error messages like:
1data Both a b = Both { left :: a, right :: b }
2instance Monoid a => Applicative (Both a) where
3 pure x = Both mempty x
4 Both u f <*> Both v x = Both (u <> v) (f x)
5data Both a b = ... deriving Applicative via ((,) a)
6 • Couldn't match representation of type ‘(a, a1)’
7 with that of ‘Both a a1’
8 arising from the coercion of the method ‘pure’
9 from type ‘forall a1. a1 -> (a, a1)’
10 to type ‘forall a1. a1 -> Both a a1’
11 • When deriving the instance for (Applicative (Both a))
12
which I interpret as "the compiler doesn't know how to turn Both
into (,)
". How do I tell the compiler to do that using the obvious way?
I've seen this question and the answers, but I'm hoping for a solution that requires less boilerplate.
ANSWER
Answered 2022-Feb-21 at 11:18Inspired by this answer, and with the help of the generic-data
package one can write:
1data Both a b = Both { left :: a, right :: b }
2instance Monoid a => Applicative (Both a) where
3 pure x = Both mempty x
4 Both u f <*> Both v x = Both (u <> v) (f x)
5data Both a b = ... deriving Applicative via ((,) a)
6 • Couldn't match representation of type ‘(a, a1)’
7 with that of ‘Both a a1’
8 arising from the coercion of the method ‘pure’
9 from type ‘forall a1. a1 -> (a, a1)’
10 to type ‘forall a1. a1 -> Both a a1’
11 • When deriving the instance for (Applicative (Both a))
12{-# LANGUAGE DeriveGeneric, DerivingStrategies, DerivingVia #-}
13
14import GHC.Generics
15import Generic.Data
16
17data Both a b = Both {left :: a, right :: b}
18 deriving stock (Generic1)
19 deriving (Functor, Applicative) via Generically1 (Both a)
20
QUESTION
Jetpack compose check if a function has been run in preview mode
Asked 2022-Feb-08 at 17:01Is this possible to check if a function has been run in preview mode in Jetpack compose? I have a function that returns a proper string to use in the app but this function uses some objects which disable preview mode for @Composable
components. What I could do is to pass val isPreview: Boolean = false
flag to every component and then run a simplified function if the flag is true
but this adds some boilerplate code to every composable.
ANSWER
Answered 2021-Oct-28 at 08:10This will violate the functional paradigm of a composable function. It should be stateless and will not care if its running in preview mode or in an actual app or else, you will encounter unexpected bugs in the future when the app gets very large to manage.
You should try to refactor or restructure your composable so that it will only depend on the string directly as a parameter. The preview mode can send a hardcoded string for this composable but for your actual app, you can call that function that returns the proper string (which uses some objects).
More about "Thinking in Compose" here
QUESTION
AVPlayer AVPlayerWaitingWhileEvaluatingBufferingRateReason slow loading for larger videos
Asked 2022-Feb-07 at 17:31I have an AVPlayer that is playing a moderately large video (~150mb). When loading the video initially, I find that the player remains idle for upwards of 10-15 seconds in the AVPlayerWaitingWhileEvaluatingBufferingRateReason
state. My question is simple: how can I prevent AVPlayer from "evaluating the buffering rate reason" for this long and instead move to immediately playing the video?
I am using a custom resource loader (although this same behaviour is exhibited without using a custom resource loader). Here is the relevant code for creating the AVPlayer (all standard boilerplate):
1AVURLAsset * const playerAsset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
2[[playerAsset resourceLoader] setDelegate:self queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)];
3
4AVPlayerItem * const playerItem = [[AVPlayerItem alloc] initWithAsset:playerAsset];
5
6AVPlayer * const player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
7[player play];
8_player = player;
9
I then have a method for handling the data request, which I can use to get more information about what the AVPlayer is attempting to load:
1AVURLAsset * const playerAsset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
2[[playerAsset resourceLoader] setDelegate:self queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)];
3
4AVPlayerItem * const playerItem = [[AVPlayerItem alloc] initWithAsset:playerAsset];
5
6AVPlayer * const player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
7[player play];
8_player = player;
9-(void)handleDataRequest:(AVAssetResourceLoadingDataRequest *)dataRequest loadingRequest:(AVAssetResourceLoadingRequest *)loadingRequest {
10
11 NSLog(@"handleDataRequest: %lld-%lld (%@)",[dataRequest requestedOffset],[dataRequest requestedOffset] + [dataRequest requestedLength],[[self player] reasonForWaitingToPlay]);
12
13 NSMutableURLRequest * const request = ... // construct the request
14 [request setValue:[NSString stringWithFormat:@"bytes=%lld-%lld",[dataRequest requestedOffset],[dataRequest requestedOffset] + [dataRequest requestedLength]] forHTTPHeaderField:@"Range"];
15
16 NSURLSession * const downloadURLSession = ... // get the session
17 NSURLSessionDataTask * const dataTask = [downloadURLSession dataTaskWithRequest:request];
18 [dataTask resume];
19
20}
21
Now, on to the issue. Suppose the video length is ~100mb, here's the result of that handleDataRequest
log in the above method:
1AVURLAsset * const playerAsset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
2[[playerAsset resourceLoader] setDelegate:self queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)];
3
4AVPlayerItem * const playerItem = [[AVPlayerItem alloc] initWithAsset:playerAsset];
5
6AVPlayer * const player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
7[player play];
8_player = player;
9-(void)handleDataRequest:(AVAssetResourceLoadingDataRequest *)dataRequest loadingRequest:(AVAssetResourceLoadingRequest *)loadingRequest {
10
11 NSLog(@"handleDataRequest: %lld-%lld (%@)",[dataRequest requestedOffset],[dataRequest requestedOffset] + [dataRequest requestedLength],[[self player] reasonForWaitingToPlay]);
12
13 NSMutableURLRequest * const request = ... // construct the request
14 [request setValue:[NSString stringWithFormat:@"bytes=%lld-%lld",[dataRequest requestedOffset],[dataRequest requestedOffset] + [dataRequest requestedLength]] forHTTPHeaderField:@"Range"];
15
16 NSURLSession * const downloadURLSession = ... // get the session
17 NSURLSessionDataTask * const dataTask = [downloadURLSession dataTaskWithRequest:request];
18 [dataTask resume];
19
20}
21handleDataRequest: 0-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
22handleDataRequest: 3080192-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
23handleDataRequest: 5570560-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
24handleDataRequest: 7143424-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
25handleDataRequest: 9699328-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
26handleDataRequest: 12713984-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
27handleDataRequest: 14811136-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
28handleDataRequest: 17235968-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
29handleDataRequest: 20054016-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
30handleDataRequest: 22675456-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
31handleDataRequest: 25427968-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
32handleDataRequest: 28311552-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
33handleDataRequest: 30932992-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
34handleDataRequest: 32374784-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
35handleDataRequest: 35192832-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
36handleDataRequest: 37224448-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
37handleDataRequest: 39780352-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
38handleDataRequest: 41549824-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
39handleDataRequest: 43778048-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
40handleDataRequest: 46465024-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
41handleDataRequest: 49414144-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
42handleDataRequest: 52166656-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
43handleDataRequest: 54984704-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
44handleDataRequest: 57802752-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
45handleDataRequest: 60293120-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
46handleDataRequest: 62783488-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
47handleDataRequest: 65732608-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
48handleDataRequest: 68550656-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
49handleDataRequest: 70975488-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
50handleDataRequest: 73531392-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
51handleDataRequest: 76480512-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
52handleDataRequest: 79495168-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
53handleDataRequest: 82313216-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
54handleDataRequest: 83951616-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
55handleDataRequest: 86573056-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
56handleDataRequest: 88866816-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
57handleDataRequest: 91422720-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
58handleDataRequest: 92667904-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
59handleDataRequest: 95289344-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
60handleDataRequest: 98172928-100000000 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
61handleDataRequest: 32768-5570560 (AVPlayerWaitingWhileEvaluatingBufferingRateReason)
62handleDataRequest: 2032769-5570560 (AVPlayerWaitingToMinimizeStallsReason)
63handleDataRequest: 4032770-5570560 (AVPlayerWaitingToMinimizeStallsReason)
64handleDataRequest: 5668864-22675456 ((null))
65handleDataRequest: 7668865-22675456 ((null))
66handleDataRequest: 9668866-22675456 ((null))
67handleDataRequest: 11668867-22675456 ((null))
68handleDataRequest: 13668868-22675456 ((null))
69
As you can see, there's nearly 40 HTTP requests just to evaluate the buffering state reason. This takes a very long amount of time.
Here's what I've tried:
- Use AVPlayer's
playImmediatelyAtRate:
instead ofplay
I saw this suggestion online. I suppose the logic is that playing immediately would do just that, play immediately. This does not work as the player still takes the time (and the requests) to evaluate the buffering rate reason before playing.
- Set AVPlayer's
automaticallyWaitsToMinimizeStalling
toNO
Seems reasonable. We can tell the player not to wait to minimize stalling. Unfortunately, this fails as the player still makes the same requests to evaluate the buffering rate before playing (oddly enough, however, the reasonForWaitingToPlay
is null
while this is taking place).
- Call the loading request's
finishLoading
method to immediately accelerate the buffering rate evaluation
The logic here was that instead of firing actual HTTP requests while the AVPlayer was evaluating the buffering rate, I could immediately signal that loading was finished. The results of this varied. In some tests, the video would play immediately but only play for a couple of seconds whereas in other tests, the video failed to play at all and would time out.
In conclusion, is there any way to avoid this delay when playing larger videos? Is it truly necessary that the AVPlayer must evaluate the buffering rate prior to starting a video?
ANSWER
Answered 2022-Feb-07 at 17:31Apple has confirmed that the issue is not the size of the video, but instead a malformed MP4 with too many moof+mdat atoms.
At this point in time, this has been determined to be working as intended. Although, I would like to see some way to avoid this initial buffering in the future, even if the MP4 is malformed.
QUESTION
How to apply one signature test to multiple positionals
Asked 2022-Feb-03 at 16:01I wrote some code in https://github.com/p6steve/raku-Physics-Measure that looks for a Measure type in each maths operation and hands off the work to non-standard methods that adjust Unit and Error aspects alongside returning the new value:
1multi infix:<+> ( Measure:D $left, Real:D $right ) is export {
2 my $result = $left.clone;
3 my $argument = $right;
4 return $result.add-const( $argument );
5}
6multi infix:<+> ( Real:D $left, Measure:D $right ) is export {
7 my $result = $right.clone;
8 my $argument = $left;
9 return $result.add-const( $argument );
10}
11multi infix:<+> ( Measure:D $left, Measure:D $right ) is export {
12 my ( $result, $argument ) = infix-prep( $left, $right );
13 return $result.add( $argument );
14}
15
This pattern is repeated 4 times for <[+-*/]> so it amounts to quite a lot of boilerplate; I'd like to reduce that a bit.
So, is there a more terse way to apply a single Measure|Real test in the signature to both Positionals in a way that the multi is triggered if both or one but not neither match and that the position is preserved for the intransigent operations <[-/]>?
I am not sure that getting to no multis is the most elegant - perhaps just compress the Real-Measure and Measure-Real to one?
ANSWER
Answered 2021-Dec-30 at 03:53There are a few ways to approach this but what I'd probably do – and a generally useful pattern – is to use a subset to create a slightly over-inclusive multi and then redispatch the case you shouldn't have included. For the example you provided, that might look a bit like:
1multi infix:<+> ( Measure:D $left, Real:D $right ) is export {
2 my $result = $left.clone;
3 my $argument = $right;
4 return $result.add-const( $argument );
5}
6multi infix:<+> ( Real:D $left, Measure:D $right ) is export {
7 my $result = $right.clone;
8 my $argument = $left;
9 return $result.add-const( $argument );
10}
11multi infix:<+> ( Measure:D $left, Measure:D $right ) is export {
12 my ( $result, $argument ) = infix-prep( $left, $right );
13 return $result.add( $argument );
14}
15subset RealOrMeasure where Real | Measure;
16multi infix:<+> ( RealOrMeasure:D $left, RealOrMeasure:D $right ) {
17 given $left, $right {
18 when Real, Real { nextsame }
19 when Real, Measure { $right.clone.add-const($left) }
20 when Measure, Real { $left.clone.add-const($right) }
21 when Measure, Measure { my ($result, $argument) = infix-prep $left, $right;
22 $result.add($argument)}}
23
24}
25
(Note: I haven't tested this code with Measure
; let me know if it doesn't work. But the general idea should be workable.)
Community Discussions contain sources that include Stack Exchange Network
Tutorials and Learning Resources in Boilerplate
Tutorials and Learning Resources are not available at this moment for Boilerplate