Check out "Do you speak JavaScript?" - my latest video course on advanced JavaScript.
Language APIs, Popular Concepts, Design Patterns, Advanced Techniques In the Browser

Replacing code for production with Babel transformation

posted in JavaScript on 2020-11-29   babel transform plugin production replacement

If you are building some sort of an app, Babel is probably part of your build system. It is that thing which converts our fancy code to valid, working in a browser, JavaScript. Just recently at work I had to design a solution that swaps a class based on the environment. Or in another words, we have logic that should not reach our users. The file should be available locally and on our staging environment but not in production. A tiny Babel plugin was the cheapest solution for me so I decided to share the result.

read more

Smart placeholders in your markdown

posted in JavaScript on 2020-05-06   markdown placeholders template annotation marked contentful https button part content stuff p p seemore const

I ❤️ markdown. I like its simplicity and minimalistic API which is good enough to cover most of needed HTML markup. At least for textual content. At work we have a small node based microservice that delivers data from Contentful in exactly markdown format. It's all working well but we started having cases where part of the text is in Contentful and the other part is in that microservice. For example when we have a button with a catchy design. We want to content manage the label of the button but the actual markup to be on our side.

read more

Surviving the Web

posted in Must-see on 2017-03-03   smashfind links time cool places popular stuff twitter web read

I'm a proud father of two and programmer for more then 15 years. My kids are small so I'm really into parenting right now. A bit of a problem for me is to stay up-to-date with the latest technologies in the Web. I really love my job but I just don't have enough time to look after all these frameworks, libraries or tools. I used to read Twitter, monitor RSS feeds and spend hours reading Reddit or Medium. However, no time for that anymore.

read more

Distributing React components

posted in JavaScript on 2015-11-23   js react component file build react place src jsx browserify babel js map

While I was open sourcing react-place I noticed that there is some complexity around preparing the component for releasing. I decided to document the process here so I have a solid resource next time. You may be surprised but writing the working jsx file doesn’t mean that the component is ready for publishing and is usable for other developers.

read more

SASS: differences between mixins, extends and placeholders

posted in CSS3 on 2013-08-05   awesome width height mixin body placeholders radius css sass extend awesome

I used LESS a lot. These days I decided to try SASS and to be honest it's a better choice for CSS preprocessor. It just gives me more functionalities and better control on my code. There are few instruments for architecting your CSS logic - @mixin, @extend and placeholders. However there are differences between them and specific use cases.

read more

Javascript string replace and regular expression

posted in JavaScript on 2013-06-15   word git replace string innerhtml text replace element innerhtml text changetext function word creator linus torvalds linux creator linus source project started

The replace method in JavaScript is pretty much the same as in the other languages. Replace part/s of a string with something else. However, there are some tricky moments and I wanted to write this article, because I met this problem several times in the past. Actually, very often I use my blog as a documentation for myself and this is one of those cases. Probably I'll be in the same situation after week or so and I'll just check here for the proper solution.

read more

Cleaning up <pre> tag content

posted in PHP on 2013-02-02   code newstr pre parts2 code str_replace br parts str code code str_replace br code code

I'm blogging for different technologies, but very often I need to add some code in my articles. This little PHP function helps me to keep the text in my

 tags clean for prettify. It simply removes the 
's and keeps the html tags.

read more

PHP: Simple javascript obfuscator (merging files)

posted in PHP on 2010-12-30   jsstr jsstr jsstr str_replace jsstr str_replace jsstr str_replace jsstr jsstr js files fh file comment js core plugins

Currently I'm working on a big JavaScript project. It has a lot of files that have to be compressed. I wrote a simple php class that merges all the files into one. It has also a useful simple obfuscator method.

read more

PHP: find links in a string and replace them with actual html link tags

posted in PHP on 2010-11-24   urlstoreplace str numofurlstoreplace urls alreadyadded numofurlstoreplace count urlstoreplace html link tags

Currently I'm working on an application that gets data from Twitter. The tweet's string contains links that have to be transformed into html link tags. Here is a simple PHP function that helped me.

read more

Remove tags from a string in AS3

posted in ActionScript on 2010-06-30   text tags var string text replace removehtml text text replace gi text text str regexp gi text

A couple of months ago I integrated a nice WYSIWYG editor written in Flex in my CMS. It worked fine, till yesterday I needed to add more features like text formatting and font color changing. As you know the Flex RichTextEditor component adds some additional tags that I definitely don't want to send to the database. So I wrote a simple function to remove these tags.

read more