Automation Techs For Productivity And Fun

Listing Up Files Under Folder Easily On Windows


There's always a work to make list of file names and saving them to Excel files.

If you are a Windows user and  if you know how to use "dir" command and "tree" command, this work would finish in a minute.

You can run these commands using command prompt.

https://www.lifewire.com/how-to-open-command-prompt-2618089

"dir" command - output files directly under folder

"dir" command is a command to output list of files directory under specified folder.

For example, if you want to write out files in "C:\Users\test" folder to a csv file like "C:\Users\test\Desktop\myfiles.csv", run the "dir" command like below.

dir /B C:\Users\test > C:\Users\test\Desktop\myfiles.csv

After running this command, open myfiles.csv and you'll see a list of files in it.

The command format means list this.

dir /B TARGET_FOLDER_PATH > FILE_PATH_TO_OUTPUT

"/B" is a command option to output only file names.

"tree" command - output files and folders recursively

"tree" command to output every file and folder under specified folder recursively.

If you want to write output the file tree under "C:\Users\test\docs" folder to a csv file "C:\Users\test\Desktop\myfiletree.csv", run the "tree" command like below.


tree /F C:\Users\test\docs > C:\Users\test\Desktop\myfiletree.csv

The command format means list this.

tree /F TARGET_ROOT_FOLDER_PATH > FILE_PATH_TO_OUTPUT

"/F" is a command option to write out both folder names and file names. Tree command outputs only folder names when ran without this option.

for more commands...

These two command are very basic commands you can use on command prompt.

If you want to learn more, check out the command list by Microsoft.

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands

Share:

Connecting To Microsoft SQL Server From Node.js Using Windows Authentication



I usually use Knex.js to connect to databases from Node.js programs.

https://knexjs.org/

According to the official document above, Knex.js is available for connecting to MSSQL, but it failed when I tried to connect using Windows Authentication.

It seems the package "node-mssql" which Knex.js is using, has two drivers: "Tedious" and "msnodesqlv8", and the default driver Tedious does not work with Windows Authentication.

https://www.npmjs.com/package/mssql

I couldn't find out how to change the driver to use from Knex.js, so I gave up using Knex.js and decided to use "msnodesqlv8" directly from my program.

https://www.npmjs.com/package/msnodesqlv8

Example

Here I found a document for msnodesqlv8.

https://github.com/TimelordUK/node-sqlserver-v8/wiki

This is a simple example program to connect with MSSQL and fetch data from a table using Promise.






Share:

4 Websites For Checking Out What's Trending In Japan


These are the websites I found when searching for information about Japan written in English.

"Tsunagu Japan" and "Live Japan" both mainly introduces best spots to visit this season. You can find unique hotels, sightseeing spots, and restaurants to visit when going on a trip to Japan.

https://www.tsunagujapan.com/

https://livejapan.com/

"Moshi Moshi Japan" is good when you want to check out music trends, trending food, and festivals.

https://www.moshimoshi-nippon.jp/

"SoraNews24" brings you casual news from Japan.

https://soranews24.com/

Share:

How To Repeat Node.js Tasks On Windows Without Using Task Scheduler


Using the Task Scheduler is the standard way to execute programs repeatedly on Windows.

But there is a problem that you have to save your Windows account if you want to execute the task when you're not logged in, and you have to remember to update your account when changing your password. If you forget to update, the task will try to login with your old account, and you may get locked out from Windows.

I've experienced this last day, searched for a better way to repeat my tasks.
I mainly write automation programs with Javascript for Node.js, and the best way I found, is to use "node-cron" an "PM2".

https://www.npmjs.com/package/node-cron

http://pm2.keymetrics.io/

"node-cron" is a Node.js library that keeps your program process running, and executes the specified function according to schedule settings.
You can set the schedule with crontab syntax.

"PM2" is a popular process manager for Node.js.
We need it to start our program at Windows startup.

Usage Example

First you need to install node-cron and PM2.

npm install --save node-cron

npm install -g pm2

Also you need an additional PM2 plugin to execute programs on Windows startup.

npm install -g pm2-windows-startup

You can find the PM2 document for startup here.

https://pm2.io/doc/en/runtime/guide/startup-hook/

Next, create a script for node-cron.

Let's say you created a Node.js program named "exampletask.js" with a exported function "main()", and you want to execute it on 9:00 AM every day.

A script for node-cron would be like this:



If you want to run it without using PM2, you can just run it as a Node.js program.

node exampletask_cron.js

You would see the program process keeps running, and executes your "main()" function at 9:00 AM.

The next step is to save the program as a PM2 process.
The next command adds "exampletask_cron.js" to the PM2 process list, and starts it as a PM2 process.

pm2 start exampletask_cron.js

Run the command below to check your PM2 process list.

pm2 ls

Next, save your PM2 process list.

pm2 save

Then set your process list to start on Windows startup.

pm2-startup install

For more information to custom settings, check out the PM2 document.

https://pm2.io/doc/en/runtime/overview/

This is all you need to do to schedule your Node.js program.
You don't have to worry about updating your login account when changing Windows password anymore.

Share:

Dashi-Maki, The Best Egg Dish For Bento


"Bento" is a traditional and popular style to take lunch at school and at work in Japan. It's a kind of lunch box with rice, fish or meat, vegetables and other side dishes.

Watch this movie for an example:


How to Make Bento (お弁当の作り方)

A standard bento contains:

  • Rice with Furikake (a kind of seasoning) sprinkled on it
  • Dashi-Maki (Japanese style omelette roll)
  • Fried chicken or Fried fish
  • Pickles


Dashi-Maki is my favorite.
Here is a link for recipe to make Dashi-Maki, if you want to try.

https://norecipes.com/dashimaki-tamago/
Share:

What I Like

If you want to write articles with originality, writing about things or habits you love and are interested about is a good idea to start from.

Writing out why you love that target would help you think and find out what kind of things you really want.

For your readers, it would work as a table of contents of your new blog.

So, here's a list of what I'm interested about.

Programming 

I work as a web application programmer, mainly using Javascript, Java, Python.
I also make games and educational applications for my kids as my personal work.

I'm interested about saving time by automating and bulk processing tasks,
and I'm thinking programming is the easiest way for it.

Pixel Art | Voxel Art

This is my new favorite I found about a year ago.
I love both watching arts other designers created, and creating arts myself.

I like pencil drawing also, but the great point of pixel (voxel) art is that
it is easier to create and transform with programs.

Books And Games

I use to read books with Kindle App in my smartphone.
I read Mangas, Novels and Technical books.

I also play lot of games, mainly smartphone games.I like single player RPGs and Adventure games rather than online multiplayer games. I think it's because I can't wait long to end the story.

...

These are what I like now, and this blog would mainly about these themes.

Hope you enjoy!

Share:

Search This Blog

Labels

Generate Data For Testing With PostgreSQL

When developing a software using PostgreSQL database as storage, the function "generated_series" is very useful to create data ...

Powered by Blogger.

Labels

Recent Posts