George Opritescu

Developer from somewhere

angular4 No provider for ControlContainer

Problem: Received error: No provider for ControlContainer!

Solution:

  • forgot to include FormsModule besides ReactiveFormsModule in my app.module.ts :)
Read More

typescript this implicitly has type 'any'

Problem: received this error in typescript: ‘this’ implicitly has type ‘any’ because it does not have a type annotation.

Solution:

foo.on('error', function(this: Foo, err: any) {
Read More

redux-form conditional validation

Problem: want to conditionally validate some fields in a form

Solution:

// dispatch when you know which field you want to "set as required"
dispatch(change('formName', 'nameOfFieldRequired', required));

...
// and after, in your validation function:
validate: (values) => {
  const errors = {}
  const { nameOfFieldRequired, nameOfField } = values;
  if (nameOfFieldRequired && !nameOfField) {
    errors.nameOfField = 'Field is required!';
  }
  return errors;
}
Read More

curl with proxy

Problem: want to make a curl request using a proxy.

Solution:

  • Specify -x flag like in the example below ( assuming you have a proxy server running at localhost, on port 8080) :
curl -v -x http://localhost:8080 http://some.other.url
Read More

fix vscode flow Type aliases can be used only in a .ts file

Problem: Type aliases can be used only in a .ts file appears when working with flowtype.

Solution:

  • found here
  • go to Code -> Preferences -> Settings
  • in your workspace make this change:
{
  "javascript.validate.enable": false
}
Read More

HtmlWebpackPlugin insert dynamic value

Problem: add a value in index.html depending on a condition

Solution:

  • modify webpack file, to have this ( notice the someValue key ):
new HtmlWebpackPlugin({
      someValue: someValue,
      filename: 'index.html',
    }),
  • then modify index.html with your logic, and make use of the value, like in the following snippet:
<%=  htmlWebpackPlugin.options.someValue %>
Read More

generate range of numbers in es6

Problem: want to generate an array containing all values up to a number.

Solution:

  • Found here
  • […Array(n).keys()]
Read More

go RPC failed; HTTP 301 curl 22 The requested URL returned error 301

Problem: received this message when trying to install gopkg.in/go-playground/validator.v9

RPC failed; HTTP 301 curl 22 The requested URL returned error: 301

Solution: Found here:

git config --global http.https://gopkg.in.followRedirects true
Read More

webpack ignore plugin

The ignore plugin was useful to reduce the size of moment.js. Found this answer, which gave this useful snippet:

new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/) // Ignore all optional deps of moment.js

Couple that with the BundleAnalyzerPlugin ( config has to be done in webpack.config.js ) :

new BundleAnalyzerPlugin({
  reportFilename: 'report.html',
  // Automatically open report in default browser
  openAnalyzer: false,
  // If `true`, Webpack Stats JSON file will be generated in bundles output directory
  generateStatsFile: false,
  // Name of Webpack Stats JSON file that will be generated if `generateStatsFile` is `true`.
  // Relative to bundles output directory.
  statsFilename: 'stats.json',
  // Options for `stats.toJson()` method.
  // For example you can exclude sources of your modules from stats file with `source: false` option.
  // See more options here: https://github.com/webpack/webpack/blob/webpack-1/lib/Stats.js#L21
  statsOptions: null,
  // Log level. Can be 'info', 'warn', 'error' or 'silent'.
  logLevel: 'info'
}),

and you have a really nice way of seeing what causes your js file to be so big.

Read More

useful aliases for profiling go performance

Problem: I never remember the syntax for go tool pprof

Solution: have these aliases saved.

alias cpuprof="go test -v -run TestMyPerf -cpuprofile cpu.out; go tool pprof mypkg.test cpu.out"
alias memprof="go test -v -run TestMyPerf -memprofile mem.out; go tool pprof --alloc_space mypkg.test mem.out"
Read More