Skip to content

Instantly share code, notes, and snippets.

View Kotauror's full-sized avatar
🌞

Justyna Jurkowska (Zygmunt) Kotauror

🌞
  • London (UK) / Kraków (PL)
  • 10:02 (UTC +02:00)
View GitHub Profile
@Kotauror
Kotauror / user_input_test.md
Created March 24, 2018 12:38
Testing user input in RSpec

Testing user command line input in RSpec.

This note aims at explaining how to test user input in RSpec.

Background

I'm building a Tic-Tac-Toe game in Ruby. Before the game starts, I need to ask the user for name, in what mode (player vs player, player vs computer) he/she wants to play, and for the sign (eg. X or O). In order to test it, I've stubbed the gets method. It means that each time there was a gets.chomp in the code, I've stubbed it in the test in order to pass an user input. This allowed me to fluently run the tests, without the need of passing user input manually.

Examples of code

@Kotauror
Kotauror / sort_by.md
Created April 23, 2018 09:06
Sort_by ruby method - sorting using multiple attributes.

Sort_by ruby method - sorting using multiple attributes.

I guess everyone knows that feeling when you struggle with a codewars kata, create (or even not!) a looong solution, then you check the solutions of of others and go whaaaaaaaat -- they did it in one line?

This is how I felt today and this is how I refreshed my memory of Ruby's sort_by method.

Task:

@Kotauror
Kotauror / jsharder.md
Last active May 18, 2020 10:40
JavaScript the harder parts.
@Kotauror
Kotauror / closure.md
Last active April 15, 2020 10:09
Closure in Javascript

Closure in JavaScript

With every fancy framework and even fancier plugin to it, JavaScript is getting easier to use - more things happening behing the scenes, less difficult algorithms and procedures to write by hand. However, every now and then in the troublefree world of frameworks and libraries one might encounter an unexpected problem and then the JavaScript rules will creep out of the shadows and there will be no other other option but to finally face them.

In this entry, I'll go back to JavaScript basics to explain one of the fundamental concepts - a closure. I'll start with explaining the documention on very simple examples and then I'll move on to two more practical use cases.

Cracking the documentation code

Let's start talking about the closure from looking at the definition from documentation:

@Kotauror
Kotauror / models.py
Created October 29, 2018 15:24
models.py
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Contact(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), unique=True)
def __init__(self, name):
@Kotauror
Kotauror / docker-connect.md
Created May 29, 2019 08:54
connecting to docker in EC2
  1. Connect to the ec2 instance: eb ssh name-of-instance --profile name-of-profile (as in the .ssh file)
  2. docker ps - to list the dockers
  3. take a name of docker container
  4. docker exec -it name-of-container /bin/bash
  5. cd craft/storage/logs.
@Kotauror
Kotauror / typescript-interfaces.md
Last active May 20, 2019 15:48
Typescript interfaces

When and how to use interfaces in typescript. TL;DR - to prepare tymplates for objects.

Simple function, not many parameters - interface not needed:

let drawPoint = (x, y) => {
  console.log("kotek")
}
@Kotauror
Kotauror / srand.md
Last active May 14, 2019 09:09
srand in RSPEC stubbing.

srand in RSPEC stubbing.

Without further ado - some thoughts on how to use srand in RSPEC testing. Example at the end.

How does the srand work line by line.

Line Input Output
1 srand(4) 281462327676453734791076087004180619592
@Kotauror
Kotauror / fixErlangBuilds.md
Last active May 8, 2019 12:27
Fix Erlang builds

This note explains how I've solved a problem with building Erlang 21.0.

I used to use evm for managing versions of Erlang. After I've installed Erlang 21.0, I've tried to run mix and this gave me the following error: ** (MatchError) no match of right hand side value: {:error, {:crypto, {'no such file or directory', 'crypto.app'}}}.

I've then decided to use kerl instead of evm because of bigger online support. However, kerl gave me errors when I was trying to build Erlang 21.0 (kerl build 21.0 21.0).

The core of the problem with building Erlang 21.0 was hardcoding the version 20.0 of Erlang into my $PATH. I used to have this: