George Opritescu

Developer from somewhere

centos install epel

Problem: need epel to install extra packages.

Solution:

sudo yum install epel-release
Read More

javascript map async await

Problem: want to obtain the text from an array of elements

Solution:

  • Promise.all and async await map:
const childrenTable = await driver.findElement(By.css('table'))
const childrenEntries = await childrenTable.findElements(By.css('tr'))
const childrenText = await Promise.all(childrenEntries.map(async (cd) => cd.getText()))
Read More

selenium webdriver chrome headless

Problem: wanted to use chrome headless in selenium tests.

Solution: found here. Since I’m using chrome 61, I don’t need to set the binary to chrome.

    const options = new chromeDriver.Options()
    options.addArguments(
        'headless',
        // Use --disable-gpu to avoid an error from a missing Mesa library, as per
        // https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
        'disable-gpu',
    )
    const browser = new webdriver.Builder()
        .forBrowser(targetBrowser)
        .setChromeOptions(options)
        .build();
    // ... do your thing here    
Read More

create-react-app environment variables

Problem: wanted to pass environment variables to an app created with create-react-app ( in development )

This is how I did it ( not exactly sure which version of react-scripts I’m using, since I ejected the config ):

  • create a .env.development file, in your app’s root folder and add your variables there:
API_URL=http://api.local
  • open config/envs.js and add your variable to the object in getClientEnvironment function:
      {
        // Useful for determining whether we’re running in production mode.
        // Most importantly, it switches React into the correct mode.
        NODE_ENV: process.env.NODE_ENV || 'development',
        // Useful for resolving the correct path to static assets in `public`.
        // For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
        // This should only be used as an escape hatch. Normally you would put
        // images into the `src` and `import` them in code to get their paths.
        PUBLIC_URL: publicUrl,
        API_URL: process.env.API_URL,
      }
Read More

golang build time object for specific datetime

Problem: want to have a datetime for a specific day, at a specific hour

Solution: one possible solution here:

func Bod(t time.Time) time.Time {
    year, month, day := t.Date()
    return time.Date(year, month, day, 0, 0, 0, 0, t.Location())
}
Read More

node reverse proxy

Problem: want to setup a reverse proxy for some urls

Solution: use http-proxy-middleware:

const express = require('express');
const proxy = require('http-proxy-middleware');
const app = express();

const whereRequestsShouldBeProxiedTo = 'http://your.host'

const shouldProxy = req => {
    const prefixes = ['/api']

    return prefixes.find(e => req.url.startsWith(e))
}

const revProxy = proxy({
    target: whereRequestsShouldBeProxiedTo,
    changeOrigin: true,
})

app.use((req, res, next) => {
    if(shouldProxy(req)) {
        revProxy(req, res, next)
    } else {
        next()
    }
})

app.listen(3005)
Read More

remove yellow color from fields chrome autocomplete

Problem: want to get rid of the yellow color that appears when chrome autofills a field.

Solution: found here

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0px 1000px white inset !important;
}
Read More

python profile block

Problem:

Solution:

  • step 1
// some code here
Read More

convert dot file to png

Problem: have a dot file I’d like to view as a png.

Solution: found here

  • install graphviz
brew install graphviz
  • generate png:
dot -Tpng DocName.dot -o DocName.png
Read More

kotlin data class spring default constructor

Problem: data class generated by kotlin does not have a no arg constructor.

Solution: Solution found here. Add kotlin-noarg to build.gradle ( change if using other versions, more lines than needed are shown for context ) :

buildscript {
    ext {
        kotlinVersion = '1.1.4-3'
        springBootVersion = '2.0.0.M3'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
        classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
        classpath("org.jetbrains.kotlin:kotlin-noarg:${kotlinVersion}")
    }
}

...

apply plugin: "kotlin-jpa"
Read More