software engineering

Using number inputs, and hiding the arrows

By Adam K Dean on

For a long time we've lived with a few basic input types; text, password, select, and submit. But with HTML5 there are a few more input types that we get to play with. Some of these are yet to be fully supported, but if you're developing for a single browser like I am at the moment, and that single browser happens to be Chrome, you're in luck.

After finding Angular's ng-pattern to be cumbersome, I decided to checkout the number input type. The client-side validation was just what I wanted, but the pesky up/down buttons made it look ugly and took up precious space on my already cramped user interface.

Having used the power of Google, I found a way to disable these ugly buttons.

input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;        

The next issue I had was that it wanted to accept integers only. Not good for currency operations.

Luckily, there are a few attributes available to us. One of these is step, which "specifies the value granularity of the element’s value". Setting step to any allows you to go to any granularity you like.

Another two useful attributes are min and max, which allow you to set a defined range.

<input type="number" step="any" min="0" max="100">

This is a truly useful element and hopefully we'll see much more built-in functionality come to HTML5.

Find column from all tables

By Adam K Dean on

A very useful SQL snippet today, courtesy of Danny Dawes and SQLAuthority.

The following query will list all tables that reference a specific column name:

SELECT AS table_name,
SCHEMA_NAME(schema_id) AS schema_name, AS column_name
FROM sys.tables AS t
WHERE LIKE '%EmployeeID%'
ORDER BY schema_name, table_name;

Just change %EmployeeID% to the column name you're looking for.

Counting commits with Git

By Adam K Dean on

To count commits on a branch, you can use git rev-list.

For the branch you're on, use:

git rev-list --count HEAD

Or for another <branch>, use:

git rev-list --count <branch>

Also, to count commits by author, you can use git shortlog:

git shortlog -s -n
4 Some User
1 Joe Bloggs

Creating empty files with specific sizes

By Adam K Dean on

If you're doing speed tests, you may find yourself needing large files with which to test your connection speeds and stability.

On Linux, you can do this with dd like so, creating a 100 MB file (or thereabouts):

dd if=/dev/zero of=output.png bs=1M count=100

On Windows servers, you can do this using fsutil, like so:

fsutil file createnew output.png 104857600

Remember, 1024 bytes in a kilobyte, 1024*1024 bytes in a megabyte, and so forth.

Count files in a directory in Linux

By Adam K Dean on

Count files in current directory with:

ls | wc -l

Or count files in a specific directory with:

ls /some/path | wc -l