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

Recreating Facebook's Recoil library

posted in JavaScript on 2020-07-12   recoil facebook state management mycoil facebook s recoil counter atoms atom component library formattedcountervalue selector key function javascript subscribers hook const return

This weekend I decided to play with the new kid on the block - Facebook's Recoil library for managing state. I did the trivial counter example to see how it works. It's pretty simple idea so I wondered how much it takes to replicate its features. I found the exact answer - 70 lines of code. Obviously, my implementation didn't cover everything but it was fun so I decided to share my findings.

(A side note: I did not look at the code of Recoil. I didn't want to be bias on how to write my version.)

read more

Pairify - how to match balanced string pairs

posted in JavaScript on 2020-03-11   pairify balanced matches javascript pairs decided type stack line starter token code const position function category https

I'm now actively working on a VSCode extension. I started it as a theme but then decided to add some more features. Like for example a tin line on the left side of the editor marking the current function scope. In order to do that I had to analyze the current file's code and find the lines that are included in that scope. The obvious approach will be to translate the code to AST and then traverse the tree finding the information that I need. This however will require the usage of a language server which now I don't want to deal with. So I decided to explore a brute force approach. Looping over the string characters and finding balanced matches. I quickly wrapped it into a library. I called it Pairify. It consumes text and returns an array of pairs. This blog post will show you how it works.

read more

Part 1: We need channels! A gentle introduction to communicating sequential processes.

posted in Riew on 2020-01-06   riew csp routine go javascript channels put javascript fibonacci index function return pattern fibonacci number

CSP is a formal language for describing patterns of interaction in concurrent systems. It's used in Go, Crystal, Clojure's core.async and a couple of other places. The idea in its core is nothing so complicated but it offers some interesting capabilities. Surprisingly enough it is not really popular in JavaScript. Recently I'm exploring this pattern and here are my findings.

read more

Part 2: Riew - reactive view basics

posted in Riew on 2020-01-06   riew csp routine go javascript channels channels channel const javascript function ch view console log

Riew is a library based on communicating sequential processes (CSP). It is made to help with communication and synchronization between your view and business logic. It's distributed as a npm package, it has 0 dependencies and adds ~8KBs (gzip) to your application on production.

read more

Part 3: Riew - reactive view in patterns

posted in Riew on 2020-01-06   riew csp routine go javascript channels console log yield krasimir riew https github function state const

In this article we will see some use cases of Riew. Those are patterns which I found repeating while using the library. There are other blog posts part of the same series and I will suggest checking at least this one so you get a basic understanding before jumping into the code snippets below.

read more

Reactive view - the concept

posted in Riew on 2020-01-04   riew csp routine go javascript channels kitty ch const function view https react redux

Something bugs me last couple of years. I'm using React for some time now and there is always this doubt if I'm placing the business logic on the right place. I'm trying to be pragmatic, to follow best practices and listen what the community is saying. However, I still feel that something is not ok. This blog post presents the idea of the reactive view. That is nothing new per se but I came up with this term because it fits well in my idea.

read more

Rethinking the Redux API

posted in JavaScript on 2019-09-10   redux const state login username password authenticated action function reducer

I really like Redux. I Love its ideas. The reducers for example - small pure functions that apply changes without side effects are nice way to model the mutations in the state. Redux also teaches us to use the one-direction data flow which makes our apps more predictable and stable. These two things fits well for what we are doing on the front-end - building user interfaces.

Of course there is nothing perfect and Redux as every other library has its own problems. In this article I want to explore some ideas for new APIs that will help solving the problems that I encounter. I’ll be happy to see your comments below.

read more

Jolly Roger - a 2KB micro-framework based on React hooks API

posted in JavaScript on 2019-04-20   time roger const state return function usestate yohoho action

The hooks API is a wonderful idea. There are some slick patterns involved that push the React development to a more functional approach. I'm interested in trying that new API and decided to use it for my latest project. However, after a couple of days, it looked like I can't build my app only with hooks. I needed something else. And that's mainly because each hook works on a local component level. I can't really transfer state or exchange reducers between the components. That's why I created Jolly Roger. It has similar helpers but works on a global app level.

read more

Build your own interactive JavaScript playground

posted in JavaScript on 2018-11-13   code function const console exports editor require file error js

Recently I spent some time working on my own JavaScript playground called Demoit. Something like CodeSandbox, JSBin or Codepen. I already blogged about why I did it but decided to write down some implementation details. Everything happens at runtime in the browser so it is pretty interesting project.

read more

React hooks: changing the mindset

posted in JavaScript on 2018-10-31   react function hooks count counter return useeffect state const usestate

If you use React you probably know about the so called hooks. They were officially announced at this year's ReactConf by Sophie Alpert and Dan Abramov. Their presentation could be seen here. I, same as many others got intrigued by this new feature. A little bit confused by if I like them or not but kind of excited. This article pretty much sums up my thinkings around React hooks and aims to give a balanced opinion.

read more

React and separation of concerns

posted in JavaScript on 2018-05-27   loading users return error component react function data app css

Years ago when Facebook announced their JSX syntax we had a wave of comments how this was against some of the well established good practices. The main point of most people was that it violates the separation of concerns. They said that React and its JSX are mixing HTML, CSS and JavaScript which were suppose to be separated.

In this article we will see how React and its ecosystem has quite good separation of concerns. We will prove that markup, styles and logic may live in the same JavaScript land and still be separated.

read more

Implementing an async queue in 23 lines of code

posted in JavaScript on 2018-05-07   tasks taskindex getnexttask numofworkers function result promise task array process error run

Recently we had an interesting task at work. The user makes a selection of items and clicks a button. Then for every selected item we have to make a request to our API. The thing is that the user may click as many items as he/she wants. In order to speed up the process we decided to handle four requests in parallel and once some of them is finished we pull the next one. If you ask why exactly four requests in parallel read this paper.

read more

My take on Redux architecture

posted in JavaScript on 2018-04-06   state action redux const visible store function return counter type

Redux is a library that acts as a state container and helps managing your application data flow. It was introduced back in 2015 at ReactEurope conference (video) by Dan Abramov. It is similar to Flux architecture and has a lot in common with it. In this section we will create a small counter app using Redux alongside React.

read more

Markup as function

posted in JavaScript on 2017-12-01   ischristmas user state function children component props greeting redux userdataprovider jsx

If you are writing React applications you probably know about higher order components or render props (which by the way I think is kind of a form of higher order component pattern). In both cases we have a component that encapsulates logic and passes props down to children. Recently at work we came to the idea that we may push this further and represent some functionalities which are out of React in the same fashion - with a single tag in our components tree.

read more

Meet the JavaScript pattern of the year or how to handle async like a boss

posted in JavaScript on 2017-11-24   generator player function result return position error const console log yield call player

Sometimes when you learn something new you get really excited. Excited to that level so you want to teach it to someone. That is the case with the concept which I found a couple of months ago. It is an implementation of the command pattern using generators. Or the well known saga used in the redux-saga library. In this article we will see how the idea makes our asynchronous code simpler and easy to read. We will also implement it ourself using generators.

read more

Post-transpilation or what is the real face of your code

posted in JavaScript on 2017-10-10   function user return firstname lastname var person object constructor greeting

If you write JavaScript today you probably use some sort of a transpilation tool. A tool that reads your hipster code and convert it to code that works in the browser. In this article we are going to see what is actually send to the browser and how exactly libraries like Babel polyfill some of the ES6 features.

read more

The powerful higher-order component pattern

posted in JavaScript on 2017-06-10   component function props react const job dependencies h1 return state

There are lots of things which I like in React. Mostly the fact that it teaches interesting patterns. One of my favorites ones is higher-order component. In this article we’ll do a couple of experiments and will see how powerful this approach could be.

read more

Children in JSX

posted in JavaScript on 2017-01-06   todo header component return props children function todos classname todolist title

(This article is part of React in patterns series.)

React is highly composable. And the API that enables that is props.children. It gives us the power to create a placeholder that is later filled with content from the outside.

read more

The bare minimum to work with React

posted in JavaScript on 2016-06-13   react app function file babelrc return babelify browserify render superclass

The setup here is available at GitHub here.

Half an year ago I published A modern React starter pack based on webpack. The starter provides the basic tooling around React. However, I noticed that very often I need even less stuff than that. That’s usually when I want to hack something quickly. In this blog post we’ll see what’s the bare minimum to work with React.

read more

Lazy-load your images with Coloor

posted in JavaScript on 2016-04-03   image src coloor img var images base64 canvas size function

Last week I landed on an article by Manuel Wieser called Dominant Colors for Lazy-Loading Images and I found the topic really interesting. It’s about lazy-loading of images. Something that Medium is using.

read more

Debugging with Node

posted in Nodejs on 2016-03-22   debugger step node text function program line run counter command

Node has a wonderful debugger. As a front-end developer I’m mainly using Chrome’s tools but sometimes I run things in Node environment and this native feature comes handy. In this article we’ll see how to debug in the terminal using Node’s debugger.

read more

Constructive destructuring

posted in JavaScript on 2016-02-24   var destructuring function object data enabled files options attachments

Destructuring is one of my favorite ES6(ES2015) features. It just shortens my code and helps me be more explicit with my statements. Let’s see it in action.

read more

The return statement is not the end (but it should be)

posted in JavaScript on 2016-01-05   function format return result var defined function dosomething code var format function result var format return result var

Well, I kind of lied in the title of this article. Of course that it is the end of the function. Once we call return everything else after that is simply not executed. Ops … I did it again, I kind of lied again.

read more

Start your own JavaScript library using webpack and ES6

posted in JavaScript on 2015-12-30   library js webpack babel true var file module exports eslint function build

Two months ago I published a starter pack for React based on webpack. Today I found out that I need almost the same thing but without the React bit. This simplifies the setup but there are still some tricky parts. So, I made a brand new repository webpack-library-starter and placed all the stuff that we need for creating a JavaScript library.

read more

Dissection of Flux architecture or how to write your own

posted in JavaScript on 2015-12-18   store function action var return consumer change dispatcher view

The Flux implementation discussed in this article is available here github.com/krasimir/fluxiny. Feel free to use it in a browser directly or as a npm dependency.

I’m obsessed by making my code simpler. I didn’t say smaller because having less code doesn’t mean that is simple and easy to work with. I believe that big part of the problems in the software industry come from the unnecessary complexity. Complexity which is a result of our own abstractions. You know, we (the programmers) like to abstract. We like placing things in black boxes and hope that these boxes work together.

read more

A story about currying

posted in JavaScript on 2015-12-15   var function read dict key return currying button bind big dictionaryb blue

I hope you know about currying. If not then please read this book. It’s basically a process of calling a function with less parameters than it expects. Ok, not exactly calling the function but prepare another function that will run the original one. Some people call the returned function higher-order factory function. Really powerful concept.

read more

How require/import may decrease your testability

posted in JavaScript on 2015-08-23   login http js function var module password username login js user promise

When CommonJS was announced we all thought “Finally something that will organize our code”. However, there are some cons that we should be aware of. It’s not only unicorns and rainbows. In this article we will see how a simple require line makes our code difficult to test.

read more

Rethinking JavaScript readability

posted in JavaScript on 2015-08-10   function moveforward var code return callwith skipped event bind

You probably know the famous quote that the code should be written for humans to understand and accidentally for computers to execute. Writing code that compiles is easy. Writing readable code is completely different thing. Working in a team is like sharing the kitchen with your roommates. You all should care for the dishes and keep clean. And it is not only because of the others but because of you. You don’t want your dinner in a mixed place and dirty dishes right.

read more

Hacking Browserify

posted in JavaScript on 2015-07-04   function require user var return

You’ve probably heard of Browserify. It’s a nice npm module for bundling your JavaScript for a client-side usage. It lets you use similar to Node.js modular system but for the code running in the browser. I had few issues testing modules in an app that uses Browserify. So I had to learn how it works and probably hack it in order to solve my problem.

read more

Using Local Storage as a communication channel

posted in JavaScript on 2015-05-05   namespace data localstorage function var storage loop browser buffer namespace

So it's been a few months since I published something here. It’s not because I’m lazy (that’s true though) but because I was working on my second book. Now the book is almost finished and I’ll start actively blogging again. In this article we’ll see how to use the local storage of the browser as a communication channel.

read more

Unit test your client-side JavaScript

posted in JavaScript on 2014-11-20   var register test function message password username js directive jsdom angularjs

I don’t think that we have to discuss the importance of having tests. That’s not something that we add to the project in addition. That’s something that the project is based on. And because testing is so important we have bunch of tools in our disposal. We all know (I hope) how to test our back-end code. However, once we move to the front-end is a bit different. At the moment we are working on a big single page application and testing is one of our main focuses. In this article you will see how to unit test our client-side JavaScript.

read more

ToDoMVC with AbsurdJS

posted in JavaScript on 2014-07-26   model function js todos app main css component absurdjs event

You've probably heard about ToDoMVC project. It's same ToDo application made with different frameworks. It's interesting how the same problem is solved by different programmers following different concepts. This article is about making the ToDoMVC application with AbsurdJS.

read more

Feeding the beast at 60fps

posted in JavaScript on 2014-07-23   li data browser function var processed code list time

The browsers nowadays are smart. They optimize everything and help us to produce better applications. They process our code as fast as possible and even on mobile devices deliver a pleasant experience. However, at the same time, it is possible to write buggy code and make the browser freezing. We are not talking about slowing down the rendering. We are talking about no rendering at all. There are cases where we want so much from the browser that it just can’t handle it.

read more

Usersnap - the holy grail of bug reporting

posted in Must-see on 2014-07-15   usersnap data xmlhttp json function script project client s page

The bug reporting is something very important for us. As developers, we produce code that should work everywhere. Not only on our machines. No matter how many times we test our application it often happens that it does not work properly for the client. We all know how helpful is an email with text “It does not work. Fix it ASAP!”. Usersnap is amazing tool that removes the gap between you (the developer) and the non-techy guy from the other side.

read more

Node.js application made with Express and AbsurdJS

posted in Nodejs on 2014-06-07   html js function css express content styles absurdjs app

Node.js is one of those new technologies, which are attracting more and more developers every day. Mainly, because it's JavaScript driven, a lot of people are interested working with it. In this tutorial, I'll show you how to use AbsurdJS together with Express. Express is one of the popular Node.js frameworks. However, the other instrument is really fresh one and I hope that you will find it useful.

read more

Node.js: managing child processes

posted in Nodejs on 2014-05-21   error stdout js exec console log stderr visits function var module

These days I spent some time working on Yez!. Chrome extension whose main role is to replace the annoying switching between the terminal and the browser. It uses Node.js module to run shell commands. So, I had to deal with child processes, and I decided to document my experience.

read more

Look ma, JavaScript only Off-Canvas menu

posted in JavaScript on 2014-03-25   menu content css links function html position absurdjs isopen

The off-canvas menu is pretty popular nowadays. You know, the little button in the right upper corner which opens the navigation with a slide-in effect. That's what we are going to build in this article. The interesting things is that we are not going to use CSS neither HTML, only JavaScript.

read more

JavaScript: bind function

posted in JavaScript on 2014-03-09   function bind prototype comments fullname var scope user call arguments

The this keyword is always important in JavaScript. I'll admit that it took me some time to actually understand how it works. You know, sometimes JavaScript is all about the scope. Where you are and what you have an access to. This article is about the bind function. Something which I use very often.

read more

Using media queries in JavaScript (AbsurdJS edition)

posted in JavaScript on 2014-03-04   media css function var width window matchmedia dom html mq absurdjs

If you believe in responsive design you probably use a lot of media queries. That's a CSS feature which gives us the power to add something like if statements. We are able to apply rules only if the current page meets certain conditions. In this article I'll show you how I use media queries in JavaScript.

read more

Mastering the DOM access

posted in JavaScript on 2014-02-28   el parent var dom api return selector function val element

If you build web applications you probably communicate with the DOM a lot. Accessing and manipulating DOM elements is the thing which we do almost every day. Very often we collect information from different controls, we need to set values, change the content of div or span tags. Of course there are million libraries which handle these actions. The most popular jQuery, is de factor a standard. However, sometimes you need something smaller. In this article we will build our own class for managing DOM elements.

read more

Cross-browser handling of Ajax requests

posted in JavaScript on 2014-02-23   ops xhr function data request var headers return callback ops method

This blog post is part of series about AbsurdJS. I'll continue filling the library with small and self organized black boxes. In the last article we talked about creating a JavaScript router. This time we will go through the process of making Ajax requests.

read more

Dependency injection in JavaScript

posted in JavaScript on 2014-01-06   function var dependencies router service scope arguments deps dosomething

I like the quote that the programming is all about managing complexity. Maybe you've heard that the computer world is a giant construction of abstractions. We simply wrap things and produce new tools over and over again. Just think for a minute. The languages which you use have build-in functionalities and they are probably abstracted functions of other low level operations. It's the same with JavaScript.

read more

7 lines JavaScript library for calling asynchronous functions

posted in JavaScript on 2013-12-12   function var funcs callback scope queue function funcs var queue function array

I was surprised by the good feedback for JavaScript template engine in just 20 lines and decided to blog for another small utility function which I'm using often. While we are talking about JavaScript in the browser, most of the operations are asynchronous. We are dealing with callbacks all the time and sometimes we end up with awesome callback hell.

read more

JavaScript template engine in just 20 lines

posted in JavaScript on 2013-12-01   var r push match skills code function template index line tpl

I'm still working on my JavaScript based preprocessor - AbsurdJS. It started as a CSS preprocessor, but later it was expanded to CSS/HTML preprocessor. Shortly, it allows JavaScript to CSS/HTML conversion. Of course, because it generates HTML it was normal to act as a template engine. I.e. somehow to fill the markup with data.

read more

AbsurdJS fundamentals

posted in JavaScript on 2013-11-11   css api color styles var function absurd absurdjs javascript

AbsurdJS became one of my favorite projects. I spent a good amount of time developing it and it's getting more and more interesting. I also received some positive feedback, so I think it is time to write a bit more about the module and explain how it actually works and what exactly is made for.

read more

JavaScript: dependency free extend method

posted in JavaScript on 2013-10-28   extend var function o prop destination tobedefined expect o address bla bla

While I worked on AbsurdJS I needed a function which accepts numerous objects and combines their properties. I.e. something like the _.extend method of UnderscoreJS. What I did is actually to use one more dependency just because of such method. John-David Dalton nicely pointed out my mistake and added a simple function which solved the problem. I change it a bit and now it acts as UnderscoreJS's version.

read more

JavaScript challenge: queue implementation

posted in JavaScript on 2013-09-24   function queue item var api queueelements flags delay return api queue function

I'm currently working on an animation-heavy web application. There are long chains of CSS transitions/animations, which I have to do. I wrote this little library, because I needed something lightweight with minimalistic API. I think that it deserves its own repository and I created one.

read more

Auxilio Chrome extension or how I boost my productivity

posted in Must-see on 2013-09-04   auxilio function command callback browser current extension page github

I'll be honest and I'll say that I'm a bit lazy sometimes. I'm one of those developers which don't like to repeat same actions again and again. There are dozen of things which I have to do while working on a project. Very often I'm covering the development of several applications and have to switch between them. It's really annoying process. I hate to have many opened tabs in my browser, many consoles or several code editors. I always try to improve my productivity by automating tasks. I think that even switching between opened applications takes too much time.

read more

JavaScript: creating class based on object

posted in JavaScript on 2013-08-31   object function var return ob2 ob1 create obj return function function obj return

I'm very happy visiting Stackoverflow more often then Facebook these days. Today I landed on this question. I'm not sure that I understand the real context of the situation, but I found something helpful, which may be useful for you. What if we have an object and want to use it as a base for JavaScript class (i.e. function). The idea is to create instances and basically extend the original object.

read more

Managing events in JavaScript

posted in JavaScript on 2013-08-23   model function var view controller eventbus callback function var scope event

I just noticed that the most popular repository in my GitHub account is EventBus. There is already an article about it, but it's a little bit outdated. I needed to clarify few things, so here is a new one.

read more

Managing events in JavaScript

posted in Must-see on 2013-08-23   model function var view controller eventbus callback function var scope event

I just noticed that the most popular repository in my GitHub account is EventBus. There is already an article about it, but it's a little bit outdated. I needed to clarify few things, so here is a new one.

read more

Send message from web page to chrome extension\'s background script

posted in JavaScript on 2013-08-22   script event web page document function message content script background script send

I just answer on that question in StackOverflow. I think that this is a common quetion so it worths writing about it.

read more

A bad side effect of the aspect oriented programming

posted in JavaScript on 2013-08-15   thing result function thing prototype dosomething start prototype dosomething function aspect oriented programming problem original class

I just read this very interesting article published on know.cujojs.com. It's about aspect oriented programming. At the beginning I thought "Oh, that's kinda cool", but when I start thinking about how I'll use it in practice I notice something bad. The blog post itself is well written and informative, but doesn't include any cons of the used technique.

read more

Introduction to animations in HTML

posted in HTML5 on 2013-07-30   animation var animations css function element class add

Last few years designers use a lot of animations directly in the HTML. That's of course kinda cool, because you don't need a plugin in order to see their work. There are several ways to make animations in HTML. It's an interesting subject and I decided to make a short research and summarize the information.

read more

JavaScript is cool

posted in JavaScript on 2013-07-23   var function class return instance pubmethod module event function return

I'm writing a lot of JavaScript these days. Sometimes it's really crazy what you can do with that language. I have bunch of tools in my arsenal and I wanted to document them somehow. Writing an article is a good option. By tools I mean patterns, piece of logic or just syntax shortcuts. However, this article is not exactly about design patterns, but it uses some of them. It's just about few ideas, which I came into during my daily scripting.

read more

JavaScript: sequencing function calls #2

posted in JavaScript on 2013-07-10   chain error console log arguments function res chain errors run object chainends

I created a simple JavaScript library for running functions in a sequence. The story behind this is published here. Today I made few interesting changes which deserve a new blog post.

read more

JavaScript: sequencing function calls

posted in JavaScript on 2013-07-09   function var callback run element chain function res type console log

While I'm working on Auxilio I end up in a sitatuation where I have to call few javascript functions in a sequence. It's an interesting how this could be solved and I'll be happy if you share your opinion for such problem.

read more

Extending Jasmine (BDD framework for testing)

posted in JavaScript on 2013-07-05   function jasmine htmlreporter spec reporter jasmineenv test prototype

Don't get me wrong, Jasmine is a wonderful framework. I'm using it for testing JavaScript in both places - front-end (in browser) and back-end (Nodejs). However, the client side has some disadvantages, which I just fixed. I hope that someday these changes will be moved to the official version (or at least I'll make a pull request very soon).

read more

Insert css or javascript dynamically

posted in JavaScript on 2013-06-18   var function css files

That's a super simple function for adding new css or javascript files in the current document. I didn't test it in all the browsers, because I'm using it in the chrome extension and I need only Chrome supported.

read more

Chrome extension: debugging dev tools tab or how to make console.log

posted in JavaScript on 2013-06-18   chrome dev tools obj message alert chrome runtime console log bglog function work

It's really interesting to work on an extension for Chrome. However, sometimes it's a little bit difficult to debug. Especially when you work on a dev tools add-on (i.e. a new tab).

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

Simple command line parser in JavaScript

posted in JavaScript on 2013-06-11   long parameter param3 var parse command param1 commandparser parse command param3 commandparser parse param1 param2 param3 command param1 param2 param3 command param1 string function

There should be some super cool RegEx, which I can use. However after short research I wasn't able to find it. So, I created a simple function which does the job.

read more

Git under windows (console mode)

posted in Architecture on 2013-05-29   git windows powershell file aliases function command status alias set

I'm a Windows user. I also have a virtual machine with Ubuntu installed and coding there from time to time. I use Git a lot and in general I prefer console mode over the GUI. Under Unix everything works just great, but Windows's command prompt requires more efforts from our side. However I found some helpful tips, which could make your life easier.

read more

Real time game with NodeJS and Socket.io

posted in Nodejs on 2013-05-13   user var function users socket io game data end clicks currentwidth

NodeJS gives me the ability to write back-end code in one of my favorite languages - JavaScript. It's the perfect technology for real time applications. In this tutorial I'll show you how to build a web chat with Socket.io.

read more

Douglas Crockford’s Function Challenges

posted in JavaScript on 2013-02-25   function s function challenges crockford s function douglas crockford s called multiple times function challenges test compose functions function scope learn knowledge

Douglas Crockford’s Function Challenges. Test your knowledge of function scope and and learn to compose functions that can be called multiple times through function returns.

read more

Testing with headless browser (Zombie.js + Jasmine)

posted in Nodejs on 2012-10-14   browser function login site expect browser test testing input zombie css selectors

I was planning to post this article a few weeks ago, but today I finally finished the examples and I can't wait to share it. We all know that the testing is a big part of our daily tasks and we should use every existing tool to make our lives easier. I really like test driven development and once I found the concept of the headless browsing I started to think that we can automate every single aspect of the testing. In this post I'll show you how to use Nodejs to test a simple php site.

read more

MySQL vs JSON file data storing

posted in PHP on 2012-02-12   records requests data json ms time request mysql res count array function

I'm not exactly a performance perfectionist, but currently I'm working on a tool which will be used in a large system. It will deliver texts to a multi-language environment and there will be several sites/apps which will performe big amount of request to it. It is the right moment for me to choose how to speed up my code and the work of the tool overall.

read more

The Open-Closed Principle

posted in Architecture on 2011-12-18   principle classes modules functions entities classes modules software entities classes called open closed robert c martin great article modification extension

That's a great article by Robert C. Martin. It's one of those articles that really may change something in your programming. The principle is called Open-Closed and it says:_SOFTWARE ENTITIES (CLASSES, MODULES, FUNCTIONS, ETC.) SHOULD BE OPEN FOR EXTENSION, BUT CLOSED FOR MODIFICATION._More about that here.

read more

Testing Facebook application

posted in JavaScript on 2011-11-29   facebook function php testing var fb config id sdk check

I had a lot of work these days and didn't have time to blog here, but I think that the tips in this article are very useful. The number of Facebook applications is increasing every day. We all know that the testing (debugging) of our code is really important. That's why I decided to share my experience in this area.

read more

Filtering data with jQuery

posted in JavaScript on 2011-10-11   var rows function var vowels consonants filtering filterinput data input filter user

We are working with data every day and there is a part of our applications, which is responsible for presenting the information to the user. Sometimes we need to show a lot of records and then we are using pagination or additional server requests to filter the data. A little JavaScript code could change the things a lot - fast data filtering and better user experience.

read more

AS3: Tracing in Flash/Flex

posted in ActionScript on 2011-08-16   import flash public str function debug movieclip void trace swf class

Inspired by the article of Dru Kepple I decided to share my experience in Debugging processes in flash/flex enviroment.

read more

AS3: DataGrid with custom ItemRenderers

posted in ActionScript on 2011-08-11   date data rating datafield var row import mx column private function void datagridcolumn

One of the big advantages of Flex framework is that you can use a lot of ready components. The DataGrid is really helpful. Especially when you want to list big amount of data and provide ability to edit the information directly in the grid. These days I finished a test task which uses DataGrid and decided to share my experience.

read more

AS3: Creating Facebook Application

posted in ActionScript on 2011-07-08   facebook function response http application log friends id api

Facebook became one of the most popular social platforms these days. I just finished a flash based game that uses their API and decided to share my experience.

read more

GoogleMaps JS API: address to coordinates transformation

posted in JavaScript on 2011-06-01   map google maps function address locations var results location google maps latlng step

When we are talking about maps, Google is an absolute leader. Their GoogleMaps tool is free, well documented and works really good. What I didn't find directly in the documentation is how to get the exact location based on plain text. I.e. to convert an address to google.maps.LatLng object. That's why I wrote a simple function that did this job.

read more

5 useful ActionScript 3 tips

posted in ActionScript on 2011-05-24   movie color function date movie getchildat month number return tips

Sometimes, when you work on some project, you find something that is small, but very interesting and useful. Usually I'm adding such kind of things in classes that I like to call helpers. The following tips are part of my helpers.

read more

OOP in JavaScript (part 2)

posted in JavaScript on 2011-02-22   child function parent prototype getname superclass parentclass childclass prototype extend child parent getname function return

I already wrote an article on this topic (Object Oriented Programming in JavaScript (Extending / Inherit classes)), but last few days I realized that there are some things that I didn't explain.

read more

Creating simple WYSIWYG editor with AS3 (Flex)

posted in ActionScript on 2011-02-11   text str function font html string editor mx var code

There are dozen of JavaScript WYSIWYG editors available, but most of them are too complicated and a little bit buggy. From time to time I'm using my own tool to provide such kind of functionality. It accepts and exports valid html. I decided to share it with you and explain how I built it.

read more

Creating mp3 player with RobotLegs (basics tutorial)

posted in ActionScript on 2011-02-09   import public function event data preloaderevent robotlegs events class

Have you ever wondered how to optimize your ActionScript applications? Have you searched for a nice framework that will save you a lot of time and will organize your structure? If yes then RobotLegs is for you. In this article I'll show you how to use it to create a simple mp3 player which loads a configuration xml file, parse it and play mp3 files.

read more

JavaScript: managing events (dispatch, listen)

posted in JavaScript on 2011-01-06   function event events dispatch classname type eventbus addeventlistener testclass2 testclass1 var

As a huge fen of the flash platform, I always like to work with events. The events system in ActionScript3 is really helpful when we are building a big application with many modules and we want to keep them independent. JavaScript hasn't native support of events, but we can still use them.

read more

AS3: Using custom Metadata in Flex (part 1)

posted in ActionScript on 2010-12-28   metadata public flex mycustomclass information metadata tags tag as3 flash utils describetype public function mycustomclass

I'm sure that you've already used metadata tags in your flex applications. There are several reserved keywords like [Bindable], [Embed], [Event] and so on (the full list is available here). The function of the metadata tags is to provide additional information to the flex compiler. For example information about embeding assets, dispatching events. This article doesn't explain how to use the default flex tags (you can learn that from here). It shows you how to create your own metadata tags and how to use them.

read more

Delegation in JavaScript

posted in JavaScript on 2010-12-27   var numofargs arguments length var numofargs arguments args var numofargs var args var delegate scope method function delegate scope delegation

I think that the delegation is an important part of every programming language. It is also possible in JavaScript.

read more

Object Oriented Programming in JavaScript (Extending / Inherit classes)

posted in JavaScript on 2010-12-23   function baseclass class childclass var getname subclass2 subclass1 extend

As you probably know JavaScript is not exactly OOP based language. Of course there are some ways to handle with this and you can still create classes and inherit them. It is much much better to use classes. Your application will be well structured and split to modules.

read more

Scaling rounded corners in Flash

posted in ActionScript on 2010-12-11   clip grid clip slicing height width void function rectangle resizing

I'm absolutely sure that you've already met this problem. You know, these nice rounded buttons that are provided by the designer. They are really cool, but sometimes the label of the button is so long that you have to resize/scale the image. ActionScript3 provides simple way to solve this issue.

read more

Javascript: autocomplete country script

posted in JavaScript on 2010-12-06   field function helper ac countries var loop div script javascript

We are all filling registration forms. It's really nice when the page helps us to do that faster. The script, that I'm going to show you, is designed to be used for a country field.

read more

PHP: export data to XLS file

posted in PHP on 2010-12-01   xlswritelabel echo pack 0x0 function content type application header content type download header content row col 0x0 echo pack ssssss

Sometimes it is necessary to present your data in format which is popular and easy to work with. In most cases the CSV format will fit perfectly you and your clients, but sometimes you have to export the information in XLS file. These several functions will help you to do that.

read more

Deep linking in flash with AS3

posted in ActionScript on 2010-11-14   flash page function hash address deeplinkingclass dl html swf home

Many people will say that Flash is not SEO friendly. Actually that's not 100% true. Flash is just a tool that shows your data. Exactly the same as the HTML. In this article I'll show you how to use ActionScript3 and JavaScript together to make your flash sites SEO friendly and provide a different URL for each of your pages.

read more

How to protect your SWF file

posted in ActionScript on 2010-10-15   function swf protect void check file import flash public ondatafiledtoload onfailed files string

Is there any way to protect your flash work? To be honest the answer is NO. As you probably know everything that is uploaded on a web server and is accessible from a web browser is downloaded to the users' computers and could be found in the temporary directories. Once someone gets your swf file he could use one of the dozen decompilers to reproduce the .fla and .as files. Anyway, there are still some ways to make stealing difficult.

read more

Cloning JSON object in JavaScript

posted in JavaScript on 2010-10-04   obj obj1 outpurarr var document write obj2 object getname function return obj var outpurarr clone obj var function clone obj

Simple and easy solution.

read more

Distort MovieClip in Flash with AS3

posted in ActionScript on 2010-09-05   getrandomnum clip setting mtd tweentype out_expo end getrandomnum distort private function number movieclip distortimagewrapper

As you probably know there is no simple way to distort a MovieClip in Flash. The solution that I've found uses AS3. Special thanks to Thomas Pfeiffer and Ruben Swieringa. They share their experience with this problem.

read more

Duplicate loaded images in AS3

posted in ActionScript on 2010-08-30   duplicate target var rect movieclip function bitmap loader import flash display target parent

During the creation of the latest changes in my portfolio site, I needed to duplicate a loaded image that has to be placed as a material in papervison3d's cube. We don't have duplicateMovieClip in AS3, so we have to use another technique.

read more

How to use Google Maps API in flash

posted in ActionScript on 2010-08-19   import map flash google maps icon private function adding setting mapevent api

Google offers a lot of free tools for us. One of them is really useful and easy to work with - GoogleMaps API. In this article I will show you how to import a map in Flash and place an icon in a specific place.

read more

Create your own tween manager class in AS3

posted in ActionScript on 2010-08-07   arr ease startpos calcendpos steps var calcendpos steps break object steps break case properties start public function

There are some features in Flash that we can't work without. Tween classes are among the most used ones. They give you ability to animate objects without using the timeline, to change the animation fast and easy. The idea of these classes is very simple. That's why I think that it is a good idea to have your own tween manager that you can modify to fit into your needs.

read more

Delegation in AS3

posted in ActionScript on 2010-08-02   function param2 func param1 delegation

I just can't code without delegation. I'm using it every day and wanted to share this method with you.

read more

Customize ComboBox in Flash (AS3)

posted in ActionScript on 2010-06-17   combo tf data import flash dp additem label customcellrenderer function combo textfield setstyle oncombochange cellrenderer movieclip

In my work as a flash developer very often I receive from the client just one photoshop file with the design of the application/site that has to be coded. In the last project the designer made the ComboBox in the style of the site. So I couldn't use the default look of the Flash's drop down component.

read more

Tween Manager Class in AS3

posted in ActionScript on 2010-03-16   customproperty object tween tweenmanager xtween property function change tweenmanager tween loop end

TweenManager is ActionScript3 class that helps you to animate your objects in flash. You don't need to create timeline type animations, because you can control every property of the object. Also it helps you to create a sequence by different animations/events. In the examples below I'll show you how to use the manager to solve different problems during your daily flash work.

read more