Invoke native element method with Angular 6

The useful method invokeElementMethod() has been removed from the new Renderer v3 in the upcoming version 6 of Angular. What does it mean? For example it is now harder to invoke focus() on input field or create custom native event, which bubbles up. The motivation of the Angular team is that this method has not been used internally, therefore they have removed it. I don’t think this was the best solution, because this method has been used by many. So now when you need to focus some input field, you need to write up your own renderer service. It makes the …

Continue Reading

Frozen global object

If your app uses global object as a config, you should make sure, that this object is truly readonly. So that an attacker can not modify it in dev console. This is how to do it. // example of frozen global object // freeze the config object properties const config = Object.freeze({ httpApi: ‘http://127.0.0.1:20003/v1’, wsApi: ‘ws://127.0.0.1:3000’, enableReduxDevTools: true, minLegalAge: 18 // in years }); // make sure that the config object can not be replaced Object.defineProperty(window, “config”, { value: config, configurable: false, writable: false }); PS: I assume that “window” is sufficient as a global object. If your app runs …

Continue Reading

Custom command line shortcuts with Doskey

I’ve learned this nice trick from Petr Horáček aka Besir while working on Nakamotox. So the credit goes to him. You can define custom commands via doskey (only on Windows) and then invoke them via command line. It is quite powerfull, because you can define alias for command with predefined attributes, so it save you lot of repetitive typing. Steps: Open any text editor and define your shortcut commands @echo off REM example shortcut for docker-compose doskey dcdu=docker-compose -f docker-compose-dev.yml up doskey dcdd=docker-compose -f docker-compose-dev.yml down Add path to file with commands to registry: open regedit go to \HKEY_CURRENT_USER\Software\Microsoft\Command Processor define AutoRun enter path to …

Continue Reading

Email validator for Angular

Angular has built in email validator, but it is very benevolent one. It allows for single letter domains, therefore email a@b is considered valid. Their motivation is that when used in intranet it can be perfectly valid email, because you can have custom domain names. But it does not make much sense in the broader internet. I would prefer if the built in validator would be stricter, or that there would be two validators, something like emailValidator and intranetEmailValidator. Here is my solution, hope it will help someone import {FormControl} from ‘@angular/forms’; // copied from http://emailregex.com/ export const emailRegexp = /^(([^<>()\[\]\\.,;:\s@”]+(\.[^<>()\[\]\\.,;:\s@”]+)*)|(“.+”))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; …

Continue Reading

Print document from cross-origin iframe

When you need to show content from some other site, such as Google Docs, you can easily embed it inside an iframe. Google Docs even generates it for you. But what if you need to print that document via some button click? You can not do that, because the cross-origin policy does not allow it. You have basically two options. A) Create some proxy function on your server. But that is only available when you actually have a server and not just some hosted WordPress. B) Create proxy iframe, which you are actually allowed to print, because there is no cross-origin involved. Then …

Continue Reading

Node_modules versus Docker

I’ve encountered strange error lately. Whenever I tried  to run npm install in my project’s folder, it failed. The error says something about not being able to unlink folder. The interesting think was that it only happened under certain circumstances. The reason for this was the when I started docker compose up to run my project in Docker, it created some lock on the node_modules folder. And shutting down the container or even the whole Docker did not help. The lock stayed there. The only way to workaround this (at least which I am aware of) is to restart the …

Continue Reading

Sticky header menu with animation using Javascript

The problem I needed to create animated menu, which will stay always sticked to the top and will collapse or expand as user scroll How it should look Click the image for a live version – Wisephora.com What do you need to implement it? You will need a little bit Javascript and CSS. There are several ways how to implement it, at first I wanted to do it purely by using CSS transitions, but I got whole bunch of weird bugs, so finally I implemented it using mostly Javascript. The main idea is that menu switches between two states, “expanded” and “collapsed”. I …

Continue Reading

Jak sehnat super práci

Tento článek je možná trochu předčasný, protože reálně ještě novou práci nemám. A tu starou už nemám 🙂 Čekám, jestli se rozeběhne jeden zahraniční projekt pod hlavičkou X-Team. Pokud ne, tak budu pracovat v jiné super firmě 🙂 Ale jak takovou super firmu sehnat? Jak najít práci, která bude zároveň kreativní, bude obsahovat nové výzvy, bude dobře placená a kde bude člověk mít možnost dělat na zajímavých projektech? Je jasné, že obyčejný LinkedIn profil na to nestačí. Ten je dobrý tak možná na to, aby vám chodily copy-paste nabídky a neosobní pozvánky od head-hunterů s defaultním textem. Je potřeba vystoupit …

Continue Reading

Recover deleted files by VisualStudio

Image this: You are working on a new functionality. You open up your IDE and start hacking away. You create several new files, invest your time and effort and then you accidentally delete the wrong file. No problem, that’s what we have Git for, right? But you forgot to add that now deleted file to version control. Aaarrrrggh. There is no way to retrieve that lost file. Bad, bad stupid little programmer. There is one little hack to save you (if you are in Windows): Locate the folder of deleted file and press Ctrl-Z. That will undo your deletion. It …

Continue Reading