How do I connect to a Linux machine (I’m used to RDP in Windows world)?
- SSH
- Start with either PuTTY or Git Bash or Bash subsystem for Windows 10.
What’s the usual root of the website/server?
- /var/www/html/public/
How do I connect to a Linux machine (I’m used to RDP in Windows world)?
What’s the usual root of the website/server?
Regex Sucks!
But I needed to update a form field regex validation, so I tackled it head-on and won.
As a side note, regular expression creation is also one of the best examples of where Test Driven Development (TDD) works well. You really cannot create or maintain a regex without having all the test cases written first.
For a value entered in the field, it:
^([A-Za-z0-9\\\/_\-]|([A-Za-z0-9\\\/_\-][A-Za-z0-9\\\/_\- ]{0,18}[A-Za-z0-9\\\/_\-]))$
Regex Summary:
kkdkd df sdf lk aj33<-- Pass 12345678901234567890<-- Pass kjlf l-Ka034-/\_ kj0<-- Pass adsfdsafsdaf dsfsdfa<-- Pass dlASjd83_-/\dfdsfsda<-- Pass adsfsdas sdafsdafsa<-- Pass: Contains multiple spaces in a row dsfsdf<-- Pass 2<-- Pass 11<-- Pass 111<-- Pass - dsf<-- Pass -df<-- Pass /dsaf<-- Pass \asdf<-- Pass _asdf<-- Pass _ sdfjlksdaflk jasdf<-- Pass 123456789012345678901<-- Fail. More than 20 characters asdf<-- Fail: Starts with a space adsfsdas sdafsdafs#<-- Fail: Ends with a # adsfsdafsdfsdfsadds<-- Fail: Starts with a space dfsdafljkasdfklsdsd <-- Fail: Ends with a space #<-- Fail: Invalid character only <-- Fail: Space only 2 <-- Fail: Ends with space 2<-- Fail: Starts with a space <-- Ignore: Blank line
https://regex101.com/r/2uMivO/6
It took some trial and error to get this and using https://regex101.com was a huge help and time saver.
My final problem was allowing a single character, and that was whee the OR (“|”) came in, adding it to the start of the group.
I’m working on a project that uses ‘webpack’. After pulling in a code update that required developers to clear out node_modules and update yarn, I started receiving the following prompt when running webpack:
The CLI moved to a separate package: webpack-cli
Would you like to install webpack-cli? (That will run yarn add -D webpack-cli) (yes/NO)
(I found running this – even manually running the yarn command – didn’t actually install the CLI and in fact, produced further errors).
Even trying to return the webpack version raised the prompt:
The problem, I have been told, is the version of webpack being loaded with “npm install -g webpack” was higher than the version we actually wanted and included ‘webpack-cli’ being split into a separate package. Specifically, we want to work with version 3.8.1.
You can see in the screenshots above just running “npm install -g webpack” installs version 3.8.3 (incidentally I cannot find a reference to version 3.8.3 on the NPM webpack page or webpack’s GitHub releases page).
The solution:
1) Delete the ‘npm’ and ‘npm-cache’ folder from your user profile Roaming AppData folder (i.e. from the Windows “Run” prompt run %AppData%).
2) Install the specific webpack version. i.e. npm install -g webpack@8.3.1
Now you can run ‘webpack’ as expected.
This is a quick post inspired by a problem I helped a colleague with yesterday.
The problem is a “date.getFullYear is not a function” error was thrown when calling getFullYear() on a TypeScript Date object.
This was happening when the Date object was populated from a deserialized JSON string and the deserialization was silently failing in the background in the app.
It happens due to the format of the date string, and on top of that, the string is in the format “dd/mm/yyyy” (the short date format used by most of the world)..
JavaScript being what it is, it doesn’t like this for dates like “18/05/2018” (18th May) because it actually wants to do a conversion on “05/18/2018” (US short date format).
More importantly, you can’t implicitly deserialize a string representation of a date to a JavaScript Date object. How does the dezerializer (in this case JSON.parase()) know the string is really a date?
There are 2 parts to the answer:
Below you can see it a quick running code sample I whipped up to demonstrate this.
Play around with commenting.uncommenting the “json = “…”;” lines and the “let dataObject: DataObject = JSON.parse(json);” line.
NOTE: You can pop the editor open in a new window by selecting “Edit On StackBlitz” in the bottom-left of the inserted window.
Select the folded-page icon at the top of the left column (below the StackBlizt blue/white icon) to see the list of files.
If you’re using Internet Explorer or there’s just a black window below, here’s the link to the code (and I suggest using a “modern” browser – Chrome and Edge both work): https://stackblitz.com/edit/typescript-riapny.
I’ve just updated Visual Studio 2017 to version 15.7.1 at work and see the Visual Studio team has included a new Stielhandgranate symbol beside the line numbers in the code IDE.
Compare that to the original:
I’m a very practical developer. My learning style has always been to learn how to do something, usually by example, now what it’s called.
As such, I know that I know how to write code with predicates, but I might still fail a multiple-choice test to describe what a predicate is.
So I looked it up again. And it’s really quite simple:
A predicate is a statement (or function) that returns either true or false.
You pass some data into the predicate. The predicate logic then performs a check on the data. Then the function/statement return a true or false result to the caller.
The 2 clearest resources with descriptions and examples I’ve found so far are this StackOverflow answer and this other StackOverflow answer (which is C# oriented).
A common example is a function or short comparison statement you write and pass into a function on a list that then performs a mapping or reduction on the list (e.g. to find a subset of items in the list that contain the value(s) your predicate function or statement is checking for).
For example, if I have a list or array of People objects and each object has an Age property, I can write a predicate …
(Person p) => (p.Age >= 18)
… that I pass into a select() function on the list to return only those people who are age 18 or older.
For example:
var australianDrinkingAgePeople = fullList.Select(Person p => p.Age >= 18);
In this case, it’s a shortcut for writing your own big for loops and if statements over the list (although there’s nothing to say that the select() statement doesn’t implement that logic behind the scenes).
It’s nice to know you can still discover new things after 20 years in the industry.
Last week while investigating a defect of some data import work I’d done in SQL SERVER, one of my initial steps was to query the database for the imported records. For example:
SELECT * FROM [MyTable] WHERE [SomeField] = ‘SomeValue’;
That’s a standard, simple query. Nothing tricky about it.
However, what I had already discovered from inspecting the value returned to the application that uses it, is my value actually had a trailing space (i.e. ‘SomeValue ‘).
What surprised me was when I ran the query above it still returned the record.
That is: [SomeField] actually equals ‘SomeValue ‘ (with a trailing space) in the database record, yet my comparison to ‘SomeValue’ (no trailing space) still returned the record.
It turns out this is a quirk of SQL SERVER’s implementation of SQL.
It also turns out in all my years working with databases I must have been cleansing my data enough to never encounter this (in this instance I was generating SQL statements in Excel and was explicitly told not to touch import values [some of which included an incorrect trailing space]).
Check out this StackExchange question for more information.
Key Stats:
My WordPress-based Knowledge Base site has started displaying an unwanted JavaScript dialogue box on post pages saying:
An embedded page at widgets.wp.com says
Request failed. Returned status of 404
It turns out I’m not the only one with this issue (as this WordPress Support page indicates) and the problem looks to be coming from the JetPack plug-in.
After finding a few keywords on that support and testing on my own site, it turns out the problem is being caused by the “Show Likes.” feature on the post:
Untick the “Show Likes.” option and save the post again and the problem goes away.
Now we just need to wait for a fix from JetPack (which seems a bit slow coming).
Note for developers: This type of error should never be logged in the UI via a JavaScript dialogue box. Why? It’s truly bad user experience for non-technical end users (who in the case of WordPress websites are most likely to see it). Log it to the console instead.
These are my views and approaches on leading software development teams and managing people in general. They come from the culmination of a few years of on-and-off leadership, and a lifetime of observation (plus a share of suffering under poor regimes along the way).
In no particular order:
Finally:
From years of experience and use (and a few recommendations from other people), I recommend the following tools:
Command-line has its place but for the complicities of Git-based source control (and being a visual person), I prefer a good GUI for Git management.