The Codest
  • O nás
  • Služby
    • Vývoj softwaru
      • Vývoj frontendů
      • Vývoj backendu
    • Staff Augmentation
      • Vývojáři frontendů
      • Vývojáři backendu
      • Datoví inženýři
      • Cloudoví inženýři
      • Inženýři QA
      • Další
    • To Advisory
      • Audit a poradenství
  • Odvětví
    • Fintech a bankovnictví
    • E-commerce
    • Adtech
    • Healthtech
    • Výroba
    • Logistika
    • Automobilový průmysl
    • IOT
  • Hodnota za
    • CEO
    • CTO
    • Manažer dodávek
  • Náš tým
  • Case Studies
  • Vědět jak
    • Blog
    • Setkání
    • Webové semináře
    • Zdroje
Kariéra Spojte se s námi
  • O nás
  • Služby
    • Vývoj softwaru
      • Vývoj frontendů
      • Vývoj backendu
    • Staff Augmentation
      • Vývojáři frontendů
      • Vývojáři backendu
      • Datoví inženýři
      • Cloudoví inženýři
      • Inženýři QA
      • Další
    • To Advisory
      • Audit a poradenství
  • Hodnota za
    • CEO
    • CTO
    • Manažer dodávek
  • Náš tým
  • Case Studies
  • Vědět jak
    • Blog
    • Setkání
    • Webové semináře
    • Zdroje
Kariéra Spojte se s námi
Šipka zpět ZPĚT
2019-04-15
Vývoj softwaru

Special game for Ruby programmers

The Codest

Tomasz Szkaradek

Vývojový architekt

One day 3 years ago in the The Codest team we prepared a great Cody game for Ruby programmers. In today’s article, I would like to describe what the work on this project looked like and above all show you the code of the project, which from now on is publicly available on our github.

Game design

When designing the game, our main goal was to prepare a fun entertainment for programmers, as well as to do something interesting as a part of the work in our company. So far, we had not had any competences in creating games, which is why it stroke nás a significant challenge. In the first place, we focused on what this game really was. After coming up with the initial plan, we stepped up to the plate.

As a part of the work on the game, we decided to take a hackathon and split into groups performing specific tasks. With such an 8-hour work division, we were able to realize the appearance of opponents in the game, the entire layout, and the foundation of both tasks and APIs of the entire system. During the next stage, we gathered for 4-hour meetings once a month due to which we managed to finish the game in 3 meetings.

Implementation

As we specialize in RubyOnRails, we chose the technology as the leading one. However, the game was not meant to be textual and therefore the approach to it was reflected in the SPA type application. As part of the task, we worked on a well-known pipeline of assets from kolejnice (in 2016 there was nothing better in principle) and the entire javascript based on our proprietary kód with the help of TypeScript. In the application, there was a standard division of responsibilities: Rails as an asset and API source, javascript and related as interaction with the user. Here, however, it functioned as a hybrid and some views were simply rendered from rails while some of the others – from JS.

Typescript

It was our first experiment in this field. These were times when people believed in CoffeScript success. Using of  TypeScript required introduction of a typescript-rails gem. Unfortunately, this was not the final, as typescript, being statically typed language, also required this from the libraries attached by default to rails.

https://github.com/codesthq/cody_the_game/blob/master/app/assets/javascripts/jquery.d.ts (especially when using the embedded asset management system with rails).

Cody as a game required a lot of dynamics on the browser side, as well as the modification of DOM’s tree. Using TypeScript instead of vanilla javascript was a huge leap in the quality of code, the very presence of classes and encapsulation was very tempting for us.

API and SPA

In 2019, SPA applications are managed by using the magnificent React nebo Vue libraries. However, in 2015, we did it in a different way. The previously mentioned typescript was helpful in the implementation of the game, while jQuery revoked all the work related to the xml http request. Now we can use fetch, whilst back in those days `$ .ajax` was all that was needed for the job. Take a look at our client api!

https://github.com/codesthq/cody_the_game/blob/master/app/assets/javascripts/services/api_client.js.ts

If it was api then you had to solve the authentication problem somehow, didn’t you? Well, that’s right. But in that case, we went after (is it possible to write here – we used the band?!) the band and in the rails session we created cookie_key and afterwards saved it in the database. Hence we knew that everything was more than fine.

https://github.com/codesthq/cody_the_game/search?q=cookie_key&unscoped_q=cookie_key

The game status was stored in the database and information about how many users had points were coming from the database (is it the very same database? Can we just change it by a pronoun?). ACID always comes in handy when there is no caching on the system side;)

In case of the spa, it is the best without reloading the page. We have solved it classically and the html anchor was the best solution without expanding unnecessary dependencies. Because who would use turbolinks?

SnapSVG

If we design a game, it must be released only with great graphics and animations. Back then we spent many hours wondering how to meet those demands in our application. On one hand, the canvas can do miracles, on the other, in a clean html is much easier to catch up with and everyone knows it. After a painstaking search for the best solution, we figured out that the combination of these two solutions is svg. It allows you to easily present graphics in a vector, it is written in the markup language and, what is the most important, it can be modified on the fly. Importantly, there is a library for svg files that works similarly to jQuery and allows operations on the image in a unified manner. This is: http://snapsvg.io, we have very nice memories of that particular solution usage.

An example of how we used snap.svg you can find below:

https://github.com/codesthq/cody_the_game/blob/master/app/assets/javascripts/intro.js.ts

The haml file itself with the graphic skeleton:

https://github.com/codesthq/cody_the_game/blob/master/app/views/game/show.html.haml

As you can see, it’s almost like a normal DOM tree and a regular rails app!

TrustedSandbox

Well, finally we had API, Graphics, SPA. But what about the implementation of solutions sent by the users?

The first thing that comes to mind is the eval method, but we are not crazy;) Back in 2016, the docker was on the rise, so it felt like a natural choice. The containers themselves did not guarantee complete isolation and protection, which is why we used a ready solution in the Ruby called https://github.com/vaharoni/trusted-sandbox. It allowed to better protect the code before leaving the sandbox and in a standardized manner configure the operating system requirements. It was very important to properly limit the code execution time, the memory needed to operate and the CPU cycles. Our configuration is available below

https://github.com/codesthq/cody_the_game/blob/master/config/trusted_sandbox.yml.example

Of course, the same trusted sandbox did not guarantee anything, which is why we came up with a special website to run the code.

https://github.com/codesthq/cody_the_game/blob/master/app/services/task_runner/base_task.rb

Each of the tasks had its own test case, which allowed us to verify the correctness of the implemented solution. This was done by injecting the user code into the test case so that everything was run in isolation.

https://github.com/codesthq/cody_the_game/blob/master/app/challenges/challenge/case.rb

Of course, this action cost quite a lot of time and, while collecting the responses, we could not afford to run the sandbox, so we only saved the code in the database, creating a submission and then, using long pooling, we asked the endpoint to obtain the code status. This allowed us to relieve the application server and verify the data appropriately. Of course, we also had to protect ourselves against “crashing the script” and therefore we limited the number of server queries using the ttl variable, which can be seen below.

https://github.com/codesthq/cody_the_game/blob/master/app/assets/javascripts/level_controller.js.ts#L92

Summary of competition

Until September 2011, the game statistics were as follows:

– numbers of sessions: 1945 – sent tasks: 4476 – sent correct answers: 1624 – finished the game: 31

As you can see, the biggest stairs started in task # 2 because it was no longer an ordinary hello world example.

Přečtěte si také:

A quick dive into Ruby 2.6. What is new?

Writing documentation has become easy thanks to VuePress

 Vue.js basics tutorial. How to start with this framework?

Související články

Ilustrace zdravotnické aplikace pro chytré telefony s ikonou srdce a rostoucím zdravotním grafem, označená logem The Codest, která představuje digitální zdraví a řešení HealthTech.
Vývoj softwaru

Softwarové vybavení pro zdravotnictví: a případy použití

Nástroje, na které se dnes zdravotnické organizace spoléhají, se v ničem nepodobají papírovým kartám z doby před desítkami let. zdravotnický software dnes podporuje zdravotnické systémy, péči o pacienty a moderní poskytování zdravotní péče v klinických a...

NEJKRÁSNĚJŠÍ
Abstraktní ilustrace klesajícího sloupcového grafu se stoupající šipkou a zlatou mincí symbolizující efektivitu nákladů nebo úspory. V levém horním rohu se zobrazuje logo The Codest se sloganem "In Code We Trust" na světle šedém pozadí.
Vývoj softwaru

Jak rozšířit tým vývojářů bez ztráty kvality produktu

Zvětšujete svůj vývojový tým? Zjistěte, jak růst, aniž byste museli obětovat kvalitu produktu. Tento průvodce se zabývá příznaky, že je čas na škálování, strukturou týmu, najímáním zaměstnanců, vedením a nástroji - a také tím, jak může The Codest...

NEJKRÁSNĚJŠÍ
Vývoj softwaru

Vytváření webových aplikací odolných vůči budoucnosti: postřehy týmu odborníků The Codest

Zjistěte, jak společnost The Codest vyniká při vytváření škálovatelných, interaktivních webových aplikací pomocí nejmodernějších technologií, které poskytují bezproblémové uživatelské prostředí na všech platformách. Zjistěte, jak naše odborné znalosti podporují digitální transformaci a obchodní...

NEJKRÁSNĚJŠÍ
Vývoj softwaru

10 nejlepších lotyšských společností zabývajících se vývojem softwaru

V našem nejnovějším článku se dozvíte o nejlepších lotyšských společnostech zabývajících se vývojem softwaru a jejich inovativních řešeních. Zjistěte, jak mohou tito technologičtí lídři pomoci pozvednout vaše podnikání.

thecodest
Podniková a škálovací řešení

Základy vývoje softwaru v jazyce Java: A Guide to Outsourcing Successfully

Prozkoumejte tuto základní příručku o úspěšném vývoji softwaru outsourcing Java, abyste zvýšili efektivitu, získali přístup k odborným znalostem a dosáhli úspěchu projektu s The Codest.

thecodest

Přihlaste se k odběru naší znalostní databáze a získejte aktuální informace o odborných znalostech z oblasti IT.

    O nás

    The Codest - Mezinárodní společnost zabývající se vývojem softwaru s technologickými centry v Polsku.

    Spojené království - ústředí

    • Kancelář 303B, 182-184 High Street North E6 2JA
      Londýn, Anglie

    Polsko - Místní technologická centra

    • Kancelářský park Fabryczna, Aleja
      Pokoju 18, 31-564 Krakov
    • Brain Embassy, Konstruktorska
      11, 02-673 Varšava, Polsko

      The Codest

    • Home
    • O nás
    • Služby
    • Case Studies
    • Vědět jak
    • Kariéra
    • Slovník

      Služby

    • To Advisory
    • Vývoj softwaru
    • Vývoj backendu
    • Vývoj frontendů
    • Staff Augmentation
    • Vývojáři backendu
    • Cloudoví inženýři
    • Datoví inženýři
    • Další
    • Inženýři QA

      Zdroje

    • Fakta a mýty o spolupráci s externím partnerem pro vývoj softwaru
    • Z USA do Evropy: Proč se americké startupy rozhodly přesídlit do Evropy?
    • Srovnání technických vývojových center v zahraničí: Tech Offshore Evropa (Polsko), ASEAN (Filipíny), Eurasie (Turecko)
    • Jaké jsou hlavní výzvy CTO a CIO?
    • The Codest
    • The Codest
    • The Codest
    • Privacy policy
    • Website terms of use

    Copyright © 2026 by The Codest. Všechna práva vyhrazena.

    cs_CZCzech
    en_USEnglish de_DEGerman sv_SESwedish da_DKDanish nb_NONorwegian fiFinnish fr_FRFrench pl_PLPolish arArabic it_ITItalian jaJapanese es_ESSpanish nl_NLDutch etEstonian elGreek pt_PTPortuguese cs_CZCzech