Categories
Amazon Web Services PHP

johnro.net Now on AWS!

My WordPress site is now on AWS! I spent a good chunk of my time debugging the All-in-One WP Migration plugin to get my migration working, and I finally realized I skipped an important step in their migration documentation:

Migrate WordPress from PHP 5 to PHP 7

1. Make sure that all plugins are deactivated. This will ensure your website error is not caused by any third-party software

If you are getting stuck in the “Done Preparing Blogs” stage, then it could be because you didn’t deactivate all the plugins.

Cheers!

Categories
Programming

Happy 2018!

Happy new year! I have been lazy with my posts the past months (years?) so as part of my new resolutions I plan to write more.

While I am here, I will leave a tip on how to better yourself as a software developer/enthusiast: practice, learn, practice. Continue to learn, and repetition is key to nailing information in your brain! Also, check out https://www.pluralsight.com or https://www.lynda.com for study material.

Cheers!

Categories
js nodejs Programming

xlsjs: “Error: Unrecognized ExtProp type: 2 0”?

While working on ETL (Extract, Transform, Load) projects at work, I ran into an unusual issue using xlsjs:

Error: Unrecognized ExtProp type: 2 0

After digging through the `xlsjs` source code, I realized that it was following the MS-XLS Specifications, as it should, and section 2.5.108 ExtProp, the extType value that I was running into was not defined in the table. Seeing as the format structure was related to formatting, I forked the `xlsjs` library and created a version that was more forgiving.

If you are running into this issue and want a workaround, try xlsjs2.

Categories
Computers Linux Mac Programming Random

git: Please properly rename / move files and directories

I get frustrated when I browse a file from a git repository only to realize its history was lost due to improper renaming/moving of the file. It seems common for developers to manually rename/move a file in a git repository by using regular file system commands rather than git commands.

For example, let’s look at the following:

$ mkdir test
$ cd test
$ git init
$ echo "hi" > test.txt
$ git add test.txt
$ git commit -m"add test.txt"
$ mv test.txt test2.txt
$ git status

So what have we here? We start off by creating a new directory called test. We then go into the directory and start a new local git repository using git init. Next we create a new file called test.txt that contains simple text “hi”. test.txt is then added and committed to the repository. Finally, we use the mv command to rename the file to test2.txt.

git status shows us the result:

Git status after 'mv'
Result of git status

This is not what we were expecting. This shows that the original file test.txt was deleted and now there is an untracked new file called test2.txt, when it really should say that test.txt was renamed to test2.txt.

Btw, this goes for moving files as well. For example, rather than renaming the file, if it was moved to, say, a different folder, e.g. newFolder/test.txt, the result would be the same.

So how can this be solved? It’s actually not far off from the steps above. Let’s start with backtracking by reverting the rename:

$ git checkout test.txt
$ rm test2.txt
$ git mv test.txt test2.txt
$ git status

Running the above commands produces the following result:

Use 'git mv'
Use ‘git mv’ to rename/move files

Much better, isn’t it? Renaming/moving files from git repositories the proper way will allow retention of their history, which is what we want.

Categories
Amazon Web Services Elastic Beanstalk Programming Technology

AWS: EB CLI Throws Exceptions VersionConflict and/or DistributionNotFound

When running EB CLI, do you run into the following error?

$ eb deploy
Traceback (most recent call last):
  File "C:Python34libsite-packagespkg_resources__init__.py", line 635, in _build_master
    ws.require(__requires__)
  File "C:Python34libsite-packagespkg_resources__init__.py", line 942, in require
    needed = self.resolve(parse_requirements(requirements))
  File "C:Python34libsite-packagespkg_resources__init__.py", line 834, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (colorama 0.3.3 (c:python34libsite-packages), Requirement.parse('colorama==0.3.7'), {'awsebcli'})

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:Python34Scriptseb-script.py", line 5, in <module>
    from pkg_resources import load_entry_point
  File "C:Python34libsite-packagespkg_resources__init__.py", line 2900, in <module>
    @_call_aside
  File "C:Python34libsite-packagespkg_resources__init__.py", line 2886, in _call_aside
    f(*args, **kwargs)
  File "C:Python34libsite-packagespkg_resources__init__.py", line 2913, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "C:Python34libsite-packagespkg_resources__init__.py", line 637, in _build_master
    return cls._build_from_requirements(__requires__)
  File "C:Python34libsite-packagespkg_resources__init__.py", line 650, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "C:Python34libsite-packagespkg_resources__init__.py", line 829, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'colorama==0.3.7' distribution was not found and is required by awsebcli

I ran into this error today. Apparently it was caused by installing AWS CLI after EB CLI:
pip install awscli
Reinstalling EB CLI solved the issue:
pip install awsebcli

Categories
js Programming React

React: react-router and dynamic page title

I have been learning React for the past few weeks, and I am loving it. I spent today learning react-router at https://github.com/reactjs/react-router-tutorial. After going through it and implementing a lot of it in my app, I realized that it did not cover one thing that I really need: dynamic page title.

I have googled and looked at different examples of how others have done it (e.g. react-document-title, document.title) but I finally decided to tinker on my own and see if I can come up with my own implementation. (I know… another one???)

My sample code will be added to the result of lesson 3 from the tutorial I linked above:

App.js:

import React from 'react'
import { Link } from 'react-router'

export default React.createClass({
  render() {
    return <div>
      <h1>
        React Router Tutorial
      </h1>
      <ul role="nav">
        <li>
          <Link to="/about">About</Link>
        </li>
        <li>
          <Link to="/repos">Repos</Link>
        </li>
      </ul>
    </div>
  }
})

index.js:

import React from 'react'
import { render } from 'react-dom'
import { Router, Route, hashHistory } from 'react-router'
import App from './modules/App'
import About from './modules/About'
import Repos from './modules/Repos'

render((
  <Router history={hashHistory}>
    <Route path="/" component={App}/>
    <Route path="/repos" component={Repos}/>
    <Route path="/about" component={About}/>
  </Router>
), document.getElementById('app'))

Looking at index.js, I thought why not add a title attribute on the Route nodes directly? That would be the most convenient location, in my mind.

index.js:

import React from 'react'
import { render } from 'react-dom'
import { Router, Route, hashHistory } from 'react-router'
import App from './modules/App'
import About from './modules/About'
import Repos from './modules/Repos'

render((
  <Router history={hashHistory}>
    <Route path="/" component={App}/>
    <Route path="/repos" title="Repositories" component={Repos}/>
    <Route path="/about" title="About Me" component={About}/>
  </Router>
), document.getElementById('app'))

We added it to routing, but how will App get its value? This part is easy.

App.jsx:

import React from 'react'
import { Link } from 'react-router'

export default React.createClass({
  render() {
    return <div>
      <h1>
        {this.props.children.props.route.title}
      </h1>
      <ul role="nav">
        <li>
          <Link to="/about">About</Link>
        </li>
        <li>
          <Link to="/repos">Repos</Link>
        </li>
      </ul>
    </div>
  }
})

That’s it.

Categories
Programming

camelCase? underscore? dashes??

I think it’s always confusing to know which to use, but I won’t get into that here. Instead, I will list the differences for future reference:

  • camelCase
  • PascalCase
  • snake_case
  • train-case
  • StUdLyCaPs
  • UPPERCASE
  • lowercase

Juggling multiple programming languages on a daily basis, this still gives me a headache.

Categories
Mac PHP Random

Homebrew PHP Upgrade: “configure: error: Cannot find libz”

I was routinely upgrading my packages on Homebrew when I ran into the following error:

$ brew upgrade
==> Upgrading 1 outdated package, with result:
homebrew/php/php70 7.0.4
==> Upgrading homebrew/php/php70
==> Downloading https://php.net/get/php-7.0.4.tar.bz2/from/this/mirror
Already downloaded: /Library/Caches/Homebrew/php70-7.0.4
==> ./configure --prefix=/usr/local/Cellar/php70/7.0.4 --localstatedir=/usr/local/var --sysconfdir=/usr/local/etc/php/7.0 --with-config-file-path=/usr/local/etc/php/7.0 --wi
Last 15 lines from /Users/johnro/Library/Logs/Homebrew/php70/01.configure:
checking for OpenSSL support... yes
checking for Kerberos support... /usr
checking whether to use system default cipher list instead of hardcoded value... no
checking for krb5-config... /usr/bin/krb5-config
checking for RAND_egd... no
checking for pkg-config... no
checking for OpenSSL version... >= 0.9.8
checking for CRYPTO_free in -lcrypto... yes
checking for SSL_CTX_set_ssl_version in -lssl... yes
checking for PCRE library to use... bundled
checking whether to enable the SQLite3 extension... yes
checking bundled sqlite3 library... yes
checking for ZLIB support... yes
checking if the location of ZLIB install directory is defined... no
configure: error: Cannot find libz

Of course, I did the first thing I always do when running into an error, Google it! And I found this link that suggested running the following:

$ xcode-select --install

After that,

$ brew upgrade

ran fine.

Categories
Programming Random

Apache Drill: Error Starting Drill in Embedded Mode

I’ve been checking out Apache Drill and everything was fine, until today. I tried running Drill in embedded mode, per usual, when I ran into the following exception:

Error: Failure in connecting to Drill: org.apache.drill.exec.rpc.RpcException: CONNECTION : io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.21.62:31010 (state=,code=0)

java.sql.SQLException: Failure in connecting to Drill: org.apache.drill.exec.rpc.RpcException: CONNECTION : io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.21.62:31010

at org.apache.drill.jdbc.impl.DrillConnectionImpl.<init>(DrillConnectionImpl.java:159)

at org.apache.drill.jdbc.impl.DrillJdbc41Factory.newDrillConnection(DrillJdbc41Factory.java:64)

at org.apache.drill.jdbc.impl.DrillFactory.newConnection(DrillFactory.java:69)

at net.hydromatic.avatica.UnregisteredDriver.connect(UnregisteredDriver.java:126)

at org.apache.drill.jdbc.Driver.connect(Driver.java:72)

at sqlline.DatabaseConnection.connect(DatabaseConnection.java:167)

at sqlline.DatabaseConnection.getConnection(DatabaseConnection.java:213)

at sqlline.Commands.connect(Commands.java:1083)

at sqlline.Commands.connect(Commands.java:1015)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at sqlline.ReflectiveCommandHandler.execute(ReflectiveCommandHandler.java:36)

at sqlline.SqlLine.dispatch(SqlLine.java:742)

at sqlline.SqlLine.initArgs(SqlLine.java:528)

at sqlline.SqlLine.begin(SqlLine.java:596)

at sqlline.SqlLine.start(SqlLine.java:375)

at sqlline.SqlLine.main(SqlLine.java:268)

Caused by: org.apache.drill.exec.rpc.RpcException: CONNECTION : io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.21.62:31010

at org.apache.drill.exec.client.DrillClient$FutureHandler.connectionFailed(DrillClient.java:448)

at org.apache.drill.exec.rpc.BasicClient$ConnectionMultiListener$ConnectionHandler.operationComplete(BasicClient.java:237)

at org.apache.drill.exec.rpc.BasicClient$ConnectionMultiListener$ConnectionHandler.operationComplete(BasicClient.java:200)

at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:680)

at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:603)

at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:563)

at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:424)

at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:214)

at io.netty.util.concurrent.PromiseTask$RunnableAdapter.call(PromiseTask.java:38)

at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:120)

at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:357)

at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)

at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)

at java.lang.Thread.run(Thread.java:745)

Caused by: java.util.concurrent.ExecutionException: io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.21.62:31010

at io.netty.util.concurrent.AbstractFuture.get(AbstractFuture.java:47)

at org.apache.drill.exec.rpc.BasicClient$ConnectionMultiListener$ConnectionHandler.operationComplete(BasicClient.java:213)

... 12 more

Caused by: io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.21.62:31010

at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:212)

... 6 more
Categories
Database Linux Mac PHP Programming

PHP: Connect to SQL Server Database on Linux (and Mac OS X)

Microsoft SQL Server
Microsoft SQL Server

I have used PHP to connect to SQL Server plenty of time, and every time I would use the SQLSRV extension. The problem with that is, PHP’s SQLSRV extension is only available for Windows servers. Which wasn’t a problem for me because I would normally develop PHP on Windows machines. It wasn’t until recently I needed SQL Server access on a Linux machine.

It wasn’t as straightforward as I had hoped, and it certainly did not help to learn that the MSSQL PHP extension was removed in version 7.0, which took me a few hours to discover. I am writing this post in hopes that I save some people a few hours of pain, including my future self.