The Codest
  • Sobre nós
  • Serviços
    • Desenvolvimento de software
      • Desenvolvimento de front-end
      • Desenvolvimento backend
    • Staff Augmentation
      • Programadores Frontend
      • Programadores de back-end
      • Engenheiros de dados
      • Engenheiros de nuvem
      • Engenheiros de GQ
      • Outros
    • Aconselhamento
      • Auditoria e consultoria
  • Indústrias
    • Fintech e Banca
    • E-commerce
    • Adtech
    • Tecnologia da saúde
    • Fabrico
    • Logística
    • Automóvel
    • IOT
  • Valor para
    • CEO
    • CTO
    • Gestor de entregas
  • A nossa equipa
  • Case Studies
  • Saber como
    • Blogue
    • Encontros
    • Webinars
    • Recursos
Carreiras Entrar em contacto
  • Sobre nós
  • Serviços
    • Desenvolvimento de software
      • Desenvolvimento de front-end
      • Desenvolvimento backend
    • Staff Augmentation
      • Programadores Frontend
      • Programadores de back-end
      • Engenheiros de dados
      • Engenheiros de nuvem
      • Engenheiros de GQ
      • Outros
    • Aconselhamento
      • Auditoria e consultoria
  • Valor para
    • CEO
    • CTO
    • Gestor de entregas
  • A nossa equipa
  • Case Studies
  • Saber como
    • Blogue
    • Encontros
    • Webinars
    • Recursos
Carreiras Entrar em contacto
Seta para trás VOLTAR
2019-04-15
Desenvolvimento de software

Special game for Ruby programmers

The Codest

Tomasz Szkaradek

Arquiteto de desenvolvimento

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 carris (in 2016 there was nothing better in principle) and the entire javascript based on our proprietary código 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.

Tipografia

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 ou 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 doca 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 Rubi 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.

Leia também:

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?

Artigos relacionados

Ilustração de uma aplicação de cuidados de saúde para smartphone com um ícone de coração e um gráfico de saúde em ascensão, com o logótipo The Codest, representando soluções digitais de saúde e HealthTech.
Desenvolvimento de software

Softwares para o setor de saúde: Tipos, casos de uso

As ferramentas em que as organizações de cuidados de saúde confiam atualmente não se assemelham em nada às fichas de papel de há décadas atrás. O software de cuidados de saúde apoia agora os sistemas de saúde, os cuidados aos doentes e a prestação de cuidados de saúde modernos em...

OCODEST
Ilustração abstrata de um gráfico de barras em declínio com uma seta ascendente e uma moeda de ouro que simboliza a eficiência ou a poupança de custos. O logótipo The Codest aparece no canto superior esquerdo com o slogan "In Code We Trust" sobre um fundo cinzento claro
Desenvolvimento de software

Como dimensionar a sua equipa de desenvolvimento sem perder a qualidade do produto

Aumentar a sua equipa de desenvolvimento? Saiba como crescer sem sacrificar a qualidade do produto. Este guia cobre sinais de que é hora de escalar, estrutura da equipe, contratação, liderança e ferramentas - além de como o The Codest pode...

OCODEST
Desenvolvimento de software

Construir aplicações Web preparadas para o futuro: ideias da equipa de especialistas do The Codest

Descubra como o The Codest se destaca na criação de aplicações web escaláveis e interactivas com tecnologias de ponta, proporcionando experiências de utilizador perfeitas em todas as plataformas. Saiba como a nossa experiência impulsiona a transformação digital e o negócio...

OCODEST
Desenvolvimento de software

As 10 principais empresas de desenvolvimento de software sediadas na Letónia

Saiba mais sobre as principais empresas de desenvolvimento de software da Letónia e as suas soluções inovadoras no nosso último artigo. Descubra como estes líderes tecnológicos podem ajudar a elevar o seu negócio.

thecodest
Soluções para empresas e escalas

Fundamentos do desenvolvimento de software Java: Um Guia para Terceirizar com Sucesso

Explore este guia essencial sobre o desenvolvimento de software Java outsourcing com sucesso para aumentar a eficiência, aceder a conhecimentos especializados e impulsionar o sucesso do projeto com The Codest.

thecodest

Subscreva a nossa base de conhecimentos e mantenha-se atualizado sobre os conhecimentos do sector das TI.

    Sobre nós

    The Codest - Empresa internacional de desenvolvimento de software com centros tecnológicos na Polónia.

    Reino Unido - Sede

    • Office 303B, 182-184 High Street North E6 2JA
      Londres, Inglaterra

    Polónia - Pólos tecnológicos locais

    • Parque de escritórios Fabryczna, Aleja
      Pokoju 18, 31-564 Cracóvia
    • Embaixada do Cérebro, Konstruktorska
      11, 02-673 Varsóvia, Polónia

      The Codest

    • Início
    • Sobre nós
    • Serviços
    • Case Studies
    • Saber como
    • Carreiras
    • Dicionário

      Serviços

    • Aconselhamento
    • Desenvolvimento de software
    • Desenvolvimento backend
    • Desenvolvimento de front-end
    • Staff Augmentation
    • Programadores de back-end
    • Engenheiros de nuvem
    • Engenheiros de dados
    • Outros
    • Engenheiros de GQ

      Recursos

    • Factos e mitos sobre a cooperação com um parceiro externo de desenvolvimento de software
    • Dos EUA para a Europa: Porque é que as empresas americanas decidem mudar-se para a Europa?
    • Comparação dos centros de desenvolvimento da Tech Offshore: Tech Offshore Europa (Polónia), ASEAN (Filipinas), Eurásia (Turquia)
    • Quais são os principais desafios dos CTOs e dos CIOs?
    • The Codest
    • The Codest
    • The Codest
    • Privacy policy
    • Website terms of use

    Direitos de autor © 2026 por The Codest. Todos os direitos reservados.

    pt_PTPortuguese
    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 cs_CZCzech pt_PTPortuguese