Browsed by
Category: Programming

Posts

Configure Angular CLI to use tabs instead of spaces

Configure Angular CLI to use tabs instead of spaces

As a tab indentation enthusiast, I wanted to use an Angular project with tabs instead of 2 spaces. Unfortunately, there are several settings to change, and the schematics used by ng CLI command supports only spaces. Despite numerous requests (e.g. here and here), Google did not decide to introduce an option to set indentation for generated files. I went through the process of making Angular project tabbed and I’ll describe it here.

Read More Read More

Automatically enhance headers with hierarchy, links and smooth scrolling with offset

Automatically enhance headers with hierarchy, links and smooth scrolling with offset

There are several things useful in a longer document:

  • showing position of given heading in the structure
  • ability to create links to a heading
  • smooth scrolling to internal links
  • offset for scrolling if the top header covers some of the contents

Read More Read More

Help! I created too many changes and want to make separate commits – git add interactive, patching and branching

Help! I created too many changes and want to make separate commits – git add interactive, patching and branching

There are cases when you try to add a feature, but before it’s done, a new problem arises and you try to resolve it. At the end of the day you end up with several things solved, but no commits yet. Some people prefer big and messy commits that include all the work for the past week, but I tend to have one issue solved in one commit. What are your options to keep a clean repository in this situation?

Read More Read More

How I refactored maze generating Python code and used advanced class features

How I refactored maze generating Python code and used advanced class features

Previously, I have created a maze generating code while learning Python. Later I enhanced it with animation and marking special cells. All of it was done in rush, to solve the problem. Now I spent some time improving the quality of the code by encapsulating code into classes, using “private” methods and fields and separating concerns. The exact steps I took can be viewed in the GitHub repository or read here.

Read More Read More

Recursive Backtracker maze – more features and animation with Matplotlib and Python

Recursive Backtracker maze – more features and animation with Matplotlib and Python

In the previous post, I generated a simple maze. I wasn’t sure the algorithm worked as intended unless I debugged or animated it. I chose the second option. I also added marking the beginning and end of the maze quest.

Read More Read More

Maze generation algorithm in Python – drawing and arrays

Maze generation algorithm in Python – drawing and arrays

There are plenty of maze generation algorithms, some are described here and here. I decided to use one to learn some Python. I chose Recursive Backtracker. You can find longer descriptions in both links, but briefly:

  • choose a random cell in the maze
  • walk in a random direction
  • when there is no possibility to walk farther, go back (backtrack) to find the first cell from which it is possible to proceed
  • the algorithm ends when there is no possibility to move from any cell

Read More Read More

Programming paradigms in JavaScript – callbacks, Promise, async/await, promisify, functional Ramda and reactive RxJS

Programming paradigms in JavaScript – callbacks, Promise, async/await, promisify, functional Ramda and reactive RxJS

As a quick exercise, I wanted to read all URLs from my page’s sitemap instead of crawling the site. Just after I added a nested callback I decided to apply the Single Responsibility Principle and convert calls to Promises. Later I experimented with async/await and automatic conversion with Node’s promisify. Finally, I rewrote the solution in functional style using Ramda and reactive using RxJS. Read on to follow the evolution of callbacks in JavaScript.

Read More Read More

CSS – two headers – big and smaller sticky

CSS – two headers – big and smaller sticky

In modern web, you often see pages that have a big fancy header with a menu. It would be impractical to keep that menu visible all the time when scrolling because it would occupy too much of screen space. Therefore those pages often introduce a smaller header just with the navigation and logo that will be displayed as user scrolls down. I will show how to easily create such a header and add some animation to it.

Read More Read More

JavaScript – hoisting, var, let, const

JavaScript – hoisting, var, let, const

This post is a quick summary of the differences in JavaScript variable declaration.

Before ES2015 (previously named ES6), there was only one keyword to declare variables: var. The newer standard introduced two extra useful keywords: let and const.

Briefly:

  • var declares “almost global” variables
  • let declares block variables
  • const declares block read-only variables

Explanation follows.

Read More Read More