Get rid of System.out

Get rid of System.out

Some features of Java are annoying for me, especially after several years of Scala experience. First of all: why should I use System.out.println instead of println!

Continue Reading

Scala.js and Algebraic Data Types

Last time I started the discourse about the place of Scala in front-end development. My point, roughly , is that it should take business logic and leave view rendering to JavaScript. But some difficulties can appear while someone tries to bind both languages together. In my previous post I talked about Scala – JavaScript classes two-way conversion. Today I’m going to make one step further and take an example with Algebraic Data Types. Say, we have to develop an application that helps to deal with stock trading. We will buy and sell assets and our program will keep all records

Continue Reading

Scala – JavaScript class conversion example

Scala – JavaScript class conversion example

Scala is a great language. We are lucky to use it not only for back-end development but also in front-end. That’s cool, but it’s an illusion that one can create the whole front-end by solely using Scala.js. Of course, it’s possible. And one could develop the great application. I won’t argue about that. But my point is: we should use the strong parts of Scala in conjunction with strong parts of JavaScript. We all love Scala for many things. If we need to realize business logic, we will choose Scala.js . But what about view rendering, appearance, visual effects, styles,

Continue Reading

Scala Futures, Traverse and Side Effects

Scala Futures, Traverse and Side Effects

A month ago I was developing some virtual file system. My code had should read a config file, take a path and create all folders from that path. I had an asynchronous API for that purpose. My code was like this: val list = ( “/a”, “/a/b”, “/a/b/c”, “/a/b/c/d”, “/a/b/c/d/e” ) def isDirExists(str: String): Future[Boolean] = ??? def createDir(str: String): Future[Unit] = ??? Future.traverse(list){dir => isDirExists(dir).flatMap{ isExists => if (isExists) Future.successful(()) else createDir(dir) } } The list consists of paths of folders to be sequentially created. The folder creation starts from the most upper folder. If it doesn’t exist it

Continue Reading

Scala.js With Monix Example

Scala.js With Monix Example

One of the annoying thing in front-end development is managing long calculations in a browser. JavaScript does things synchronously, and when you want to do something, that needs time for execution, JavaScript resists. Here is an example of such long calculation. At first, I shall demonstrate synchronous code, then asynchronous. Scala has the great library Monix, that works well with Scala.js. I have already told about Monix in some of my previous posts. Of cause, I’m going to use this library in my asynchronous example. My son goes to school. One time he was doing his math homework and he

Continue Reading

How to make a gallery for Flickr photos

How to make a gallery for Flickr photos

This post is for those who want to showcase photos stored by Flickr. There is a commercial product for this purpose (see Flickr Pack). But you can easily do the same (say, almost) absolutely for free. I have already covered the theme of usage of Moon Gallery plugin in two little posts (see here and here). Now it’s time to go further and to tell about its usage with Flickr API. You can  read all about Flickr API here. The general  scheme of using this API is as follows: The script sends an appropriate query to the server, using one

Continue Reading

The gallery with photo-filters

The gallery with photo-filters

Today I want to continue talking about Moon Gallery jQuery library. It’s time to consider photo-filters. There are two ways to transform images in JavaScript: 1. You can draw a canvas element and replace your image with it. 2. Or you can use SVG-filters. First way consumes significantly more resources, but it’s supported by almost all modern browsers. Second way is preferable, but it’s not supported by old Android devices. Moon Gallery supports both technics. You can even set your gallery so that SVG-filters will be used if a browser supports them, otherwise canvas will be used. Canvas filters The

Continue Reading

JQuery: making a masonry gallery for free

JQuery: making a masonry gallery for free

When you want to make a photo gallery you will  likely find the Moon Mega Grid Plugin among others. It’s a great tool for building galleries with a bulk of templates and settings. But it’s not free. Fortunately, there is a free version of this plugin: the Moon Gallery. It has the same functionality. But there are only two simple templates in the Free Pack. If you need something special you ought to create a template by yourself. Features integrated support for canvas and svg filters perfect for mobile devices simple templating tools built-in lightbox with retina support 2 retina

Continue Reading

TypeScript: defining a top-level function

I use Lift as a web framework. Lift allows to generate JavaScript code and than to execute it on the page. I needed to execute a JavaScript function from that generated code. Since I use TypeScript for frontend development, I faced a problem here: How to create a global scoped function? Something like: window.myFunction = function(){ // … }   Fortunately, I found a trick. Behold: ;( <any> window).myFunction = function():void { // … }   For TSX: ;( window as any).myFunction = function():void { // … }   Now you can call this function from JavaScript inside <script> tags

Continue Reading

Let’s create a Slider. Again…

Let’s create a Slider. Again…

There have been three posts about creating a Slider with Scala.js already. The first post was about how to do it in principal. The second post was about the ScalaCSS library in general and how one could use it with our Slider in particular. The third post was about how to use a JSON object with our Slider. Now it’s time to compare Scala.js with its closest alternative: I mean TypeScript (a typed superset of JavaScript that compiles to plain JavaScript). It’s fun: the first version of this Slider was written in CoffeeScript. It took me about 3 hours. I

Continue Reading