Play around with chrome headless

source code

https://github.com/lwpro2/ChromeHeadless

1. get the chrome remote interface package
npm install chrome-remote-interface

2. run the code

cdp({
..
    },
    async client => {

    let {data} = await Page.captureScreenshot({
        format: 'png',
    });

});

and even easier if using puppeteer

    const browser = await puppeteer.launch();
    const page = await browser.newPage();

    await page.goto('https://lwpro2.wordpress.com');
    await page.screenshot({ path: 'blog.png' });

Advertisements

Not able to query on geode server

using gfsh to query, always returned me “could not create an instance of class xxx”, or some serialization/deserialization error.

while from client side, both persist and retrieving worked fine.

hope it’s not a bug of the compatibility, but not sure what’s the reason at the moment.

=============================

finally sort out the issue, need to configure

read-serialized 

on the server side before starting the server

For a starter

convert number to English words

/**
  * @author lwpro
  * @since 10/17/2017
  * @version 1
  */
object NumberTranslator extends App {

  def translateSingle(num: Int): String = {
    num match {
      case 0 => "zero"
      case 1 => "one"
      case 2 => "two"
      case 3 => "three"
      case 4 => "four"
      case 5 => "five"
      case 6 => "six"
      case 7 => "seven"
      case 8 => "eight"
      case 9 => "nine"
    }
  }

    def translateDouble(num: Int): String = {

      num match {
        case 10 => "ten"
        case 11 => "elven"
        case 12 => "twelve"
        case 13 => "thirteen"
        case 14 => "fourteen"
        case 15 => "fifteen"
        case 16 => "sixteen"
        case 17 => "seventeen"
        case 18 => "eighteen"
        case 19 => "nineteen"
        case 20 => "twenty"
        case x if 21 until 30 contains x => "twenty " concat (translateSingle(x - 20))
        case 30 => "thirty"
        case x if 31 until 40 contains x => "thirty " concat (translateSingle(x - 30))
        case 40 => "forty"
        case x if 41 until 50 contains x => "forty " concat (translateSingle(x - 40))
        case 50 => "fifty"
        case x if 51 until 60 contains x => "fifty " concat (translateSingle(x - 50))
        case 60 => "sixty"
        case x if 61 until 70 contains x => "sixty " concat (translateSingle(x - 60))
        case 70 => "seventy"
        case x if 71 until 80 contains x => "seventy " concat (translateSingle(x - 70))
        case 80 => "eighty"
        case x if 81 until 90 contains x => "eightty " concat (translateSingle(x - 80))
        case 90 => "ninety"
        case x if 90 until 100 contains x => "ninety " concat (translateSingle(x - 90))
      }
    }


    def translateBlock(num: Int) = {
      num match {
        case x if 0 until 10 contains x => translateSingle(num)
        case x if 10 until 100 contains x => translateDouble(num)
        case x if (100 until 1000 contains x) && (x %100 == 0) => translateSingle(num / 100) concat " hundred"
        case x if x % 100 < 10 => translateSingle(num / 100) concat " hundred and " concat (translateSingle(num % 100) )
        case _ => translateSingle(num / 100) concat " hundred and " concat (translateDouble(num % 100) )
      }
    }

  for (i <- 0 until 1000)
    println( i.toString concat("::") concat translateBlock(i))


  def translateWhole (num: Int) = {
    num toString() length  match {
      case x if 0 until 3 contains x => translateBlock(num)
      case x if 4 until 6 contains x => translateBlock(num / 1000) concat("thousand and ") concat(translateBlock(num %1000))
      case x if 7 until 9 contains x => translateBlock(num / 1000000) concat("million and ") concat translateBlock(num % 1000 /1000) concat("thousand and ") concat(translateBlock(num %1000 /1000 % 1000))
    }
  }

  }