JSON.parse("[" + str.trim().replace(/==>/g,"").replace(/\n/,",").replace(/([a-zA-Z0-9]+)=/g, '"$1": ').replace(/\[([a-zA-Z0-9_.//]+)\]/g, '["$1"]').replace(/\["(\d+)"\]/g, "[$1]").trim() + "]")
Thursday, 7 November 2019
Parsing Gremlin console output into JSON (with node)
JSON.parse("[" + str.trim().replace(/==>/g,"").replace(/\n/,",").replace(/([a-zA-Z0-9]+)=/g, '"$1": ').replace(/\[([a-zA-Z0-9_.//]+)\]/g, '["$1"]').replace(/\["(\d+)"\]/g, "[$1]").trim() + "]")
Wednesday, 7 February 2018
Selenium Webdriver 2 fussing about Firefox version
Starting from version 3, Selenium is using Marionette - the new Firefox driver.
This note is about version 2.
Selenium has its own support pattern: http://www.seleniumhq.org/about/platforms.jsp
Firefox
Support for Firefox is the latest release, the previous release, the latest ESR release and the previous ESR release.For example Selenium 2.40.0 (released on Feb 19, 2014) supports Firefox 27, 26, 24, 17Selenium with Firefox can be run on any platform that Firefox supports for those versions, that also allow users to install a custom Firefox extension.
Find here version release histories:
Here, firefox downloads https://ftp.mozilla.org/pub/firefox/releases/
Installing Firefox v. 44.0 fixed troubles I had with:
MacOS 10.12.6
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]
gem:
cucumber (2.3.2)
selenium-webdriver (2.52.0)
MacOS 10.12.6
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]
gem:
cucumber (2.3.2)
selenium-webdriver (2.52.0)
Friday, 3 November 2017
playing music on hold when launching a bash command
This works using MacOS afplay
Usage:
$ long-running-command [args] | moh_player
If you want to retain colours, run it through script:
$ script -q /dev/null long-running-command [args] | moh_player
!/bin/bash
moh_file=~/Downloads/moh.mp3
afplay $moh_file &
pid=$!
trap "kill $pid" 2
while read line; do echo -e $line; done
kill $pid
Usage:
$ long-running-command [args] | moh_player
If you want to retain colours, run it through script:
$ script -q /dev/null long-running-command [args] | moh_player
Monday, 14 August 2017
Jest: mocking externally dependencies, classes and injecting the class contructor
It started posting a question on Stackoverflow here
Saturday, 12 August 2017
Custom Error in NodeJS v7
Had a lot of trouble with it but finally found this solution on Node v7.10.0 :
Monday, 15 May 2017
Maps of London with zones, tube, santander bikes, universities, Aldi, Sainsbury, Poundland, Home Bargain, Coop
Are you moving into London?
Do you want to know what's up in your neighbourhood?
I am having this problem nowadays, that's why I created a Google My Map with these layers:
- TFL zones
- Underground lines
- Santander bikes (might be disactivated)
- Universities
- Stores location: Aldi, Sainsbury, Poundland, Home Bargain, Coop
Here is the link to the map: https://drive.google.com/open?id=1PVkweUYubQeimWL-Mqq5GTs_NKE&usp=sharing
Friday, 28 April 2017
Android tablet as second monitor on Ubuntu 16.04
Do you want to connect your tablet or mobile phone to your Linux desktop as a second monitor?
So I decided to create a script that configures your X11 server and creates a VNC server automatically.
Yes, is working!
I am using Ubuntu 16.04 and an Android tablet.
It should work for both iOS and Android or any other device capable of running a VNC client.
It can do both landscape and portrait mode.
For androidians, it can also connect to your device through USB!
Let me know how it goes...
Thursday, 13 April 2017
TDD with React, couple of tutorials from semaphoreci community
https://semaphoreci.com/community/tutorials/testing-react-components-with-enzyme-and-mocha
Some notes...
Enzyme gives us several ways to render components for testing: using
You can think of it as rendering "just" the component you want it to.
mount is "real" rendering that will actually render your component into a browser environment. If you are creating full React components (and not just stateless components), you will want to use
Some notes...
Enzyme gives us several ways to render components for testing: using
shallow, mount, and static. shallow ... is used to isolate one component for testing and ensure child components do not affect assertions. You can think of it as rendering "just" the component you want it to.
mount is "real" rendering that will actually render your component into a browser environment. If you are creating full React components (and not just stateless components), you will want to use
mount to do testing on the lifecycle methods of your component. We are using jsdom to accomplish rendering in a browser-like environment, but you could just as easily run it in a browser of your choosing.static ... is used for analyzing the actual HTML output of a componentTuesday, 28 March 2017
Ubuntu dev machine space management
Visualize filesystems usage:
Find working kernel
Sort and display packages size:
Brew cache cleanup
RVM
NPM cache cleanup
df -h
Show disk usage of un/hidden folders
du -sch .[!.]* * |sort -h
Find working kernel
uname -rList installed kernels
dpkg --list | grep linux-image
Sort and display packages size:
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -nCompletely delete a package
sudo apt-get purge packagenameDelete unused packages
sudo apt-get autoremoveClean Apt cache
sudo apt-get clean
Brew cache cleanup
rm -rf $(brew --cache)Brew uninstall
sudo ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
RVM
rvm uninstall ruby-2.3.3Uninstall gems
gem uninstall -aIx
NPM cache cleanup
npm cache cleanYarn (Node.js) cache cleanup
yarn cache clean
Monday, 27 March 2017
Panasonic lx100 camera and photoshop
To load shots taken with the Panasonic LX100 in Photoshop you need to install the last Camera Raw plugin:
https://helpx.adobe.com/camera-raw/kb/camera-raw-plug-in-installer.html
https://helpx.adobe.com/camera-raw/kb/camera-raw-plug-in-installer.html
Wednesday, 15 March 2017
Javascript substack module pattern
Sup!?
So, we are using React to get a photo, send to an API and convert the response into a chart with ChartJS.
Our first attempt involved writing a DataConverter class like this:
This is nice but... we have a class (ECMAScript 2015 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) which has no state at all, wouldn't be better to have a module instead?
Cool uh?!
Hang on!
Take a look at the return call: when this module is called, it is not offering a series of methods.
It is returning a function instead, so this module can be called as a function:
This is nice but apparently the power of NodeJS let's us build more robust code, using the substack module pattern:
Using this pattern we don't have to use the weird module pattern syntax, the code is more elegant and clear... agree???
One catch though, is where this code will be executed: server side or client side with build tools is fine, other cases there is a chance that all this function will be available in the global scope.
This pattern has also ways to expand the behaviour of our modules:
So, we are using React to get a photo, send to an API and convert the response into a chart with ChartJS.
Our first attempt involved writing a DataConverter class like this:
This is nice but... we have a class (ECMAScript 2015 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) which has no state at all, wouldn't be better to have a module instead?
Cool uh?!
Hang on!
Take a look at the return call: when this module is called, it is not offering a series of methods.
It is returning a function instead, so this module can be called as a function:
This is nice but apparently the power of NodeJS let's us build more robust code, using the substack module pattern:
Using this pattern we don't have to use the weird module pattern syntax, the code is more elegant and clear... agree???
One catch though, is where this code will be executed: server side or client side with build tools is fine, other cases there is a chance that all this function will be available in the global scope.
This pattern has also ways to expand the behaviour of our modules:
Wednesday, 9 September 2015
World Bank Indicators: collect and process them in Google Sheet
Hey guys!
I recently found myself in having to process some statistics data about countries performances...
Actually, I'm looking to expat and found this could be an interisting method for picking up a destination.
So what have I found?
World Bank is giving us loads of free data to play with, about countries:
I thought: why don't load a bunch of these data in a sheet, set some filters and see what could be my best place to be?
So here we go, you can download it here: https://docs.google.com/spreadsheets/d/1TyI-98fVfl1BsVGM0t6b6V65WysPulW8Z2zUsYTul04
Follow the instructions on the spreadsheet.
One suggestion: the command inside the sheet for loading indicators will load about 13-15 thousands of them!!!
Use the World Bank web page for finding indicators could be easier: http://data.worldbank.org/
It must be the last bit of an indicator web link, i.e. for GDP
Web link: http://data.worldbank.org/indicator/NY.GDP.MKTP.CD
Indicator: NY.GDP.MKTP.CD
Authorization are for running some Google Apps Script code.
If you are interested in the code, follow this link: http://pavatechpit.blogspot.it/2015/09/world-bank-xml-service-and-google-apps.html
Also, don't forget World Bank data is available on the Google Public Data Explorer project: http://www.google.com/publicdata/explore?ds=d5bncppjof8f9_&hl=en&dl=en
I recently found myself in having to process some statistics data about countries performances...
Actually, I'm looking to expat and found this could be an interisting method for picking up a destination.
So what have I found?
World Bank is giving us loads of free data to play with, about countries:
- GDP,
- electricity access,
- health,
- education,
- etc.
I thought: why don't load a bunch of these data in a sheet, set some filters and see what could be my best place to be?
So here we go, you can download it here: https://docs.google.com/spreadsheets/d/1TyI-98fVfl1BsVGM0t6b6V65WysPulW8Z2zUsYTul04
Follow the instructions on the spreadsheet.
One suggestion: the command inside the sheet for loading indicators will load about 13-15 thousands of them!!!
Use the World Bank web page for finding indicators could be easier: http://data.worldbank.org/
It must be the last bit of an indicator web link, i.e. for GDP
Web link: http://data.worldbank.org/indicator/NY.GDP.MKTP.CD
Indicator: NY.GDP.MKTP.CD
Authorization are for running some Google Apps Script code.
If you are interested in the code, follow this link: http://pavatechpit.blogspot.it/2015/09/world-bank-xml-service-and-google-apps.html
Also, don't forget World Bank data is available on the Google Public Data Explorer project: http://www.google.com/publicdata/explore?ds=d5bncppjof8f9_&hl=en&dl=en
World Bank XML service and Google Apps Script
Hi guys!
Easy task also for a novice as me in Google scripting, I wrote 200 lines in one day for ripping some data from the World Bank XML API service and presenting it in a Google Sheet.
Here the sheet: https://docs.google.com/spreadsheets/d/1TyI-98fVfl1BsVGM0t6b6V65WysPulW8Z2zUsYTul04
Functions are:
loadDataXml()
Given an indicator, fetch XML and process in such a way to export it both as a custom function or from a menu command
getData()
Menu command for loadDataXml()
loadIndicatorsXml ()
Menu command for fetching indicators list as XML in a new sheet
onOpen()
Creates a menu in Google Sheet for launching the functions
Easy task also for a novice as me in Google scripting, I wrote 200 lines in one day for ripping some data from the World Bank XML API service and presenting it in a Google Sheet.
Here the sheet: https://docs.google.com/spreadsheets/d/1TyI-98fVfl1BsVGM0t6b6V65WysPulW8Z2zUsYTul04
Functions are:
- onOpen() : creates a menu in Google Sheet for launching the functions
- average() : average function which supports NULL values, get it here - couldn't find any better on the web
- loadDataXml(): given an indicator, fetch XML and process in such a way to export it both as a custom function or from a menu command
- getData(): menu command for loadDataXml()
- loadIndicatorsXml (): menu command for fetching indicators list as XML in a new sheet
loadDataXml()
Given an indicator, fetch XML and process in such a way to export it both as a custom function or from a menu command
getData()
Menu command for loadDataXml()
loadIndicatorsXml ()
Menu command for fetching indicators list as XML in a new sheet
onOpen()
Creates a menu in Google Sheet for launching the functions
Subscribe to:
Posts (Atom)