Code in Stranger Things 2

If you want to break a software’s security pass in early 1980’s, you need to code in BASIC like in the series Deutchland 83

Stranger Things 2 is in 1984 as well so once again we are dealing with some BASIC code.

hawkinsLabSystemsHack.png

As you can clearly see there are nested 4 loops to find 4 digit numbers of the password but interesting part is that there is a misterious function called checkPasswordMatch which gets an integer as a parameter and returns a boolean result. Actually the important part is in that function, the rest that we see on the screen just tries some brute-force attack.


Guru99

Guru99 is a website worth to mention. Their comprehensive tutorials contain beautifully annotated screenshots. Their goal is to provide fun and free education for everyone.

Sometimes I prefer video tutorials but they can be time consuming so a source like this is more accesible with its content.

I could only check out their amazing JUnit tutorials for one of my posts called Attributes and Annotations of Testing Frameworks. As a blog writer I can see their effort in it.

The JUnit course covers;

  • JUnit Basics like Introduction, Test framework, Download and Install Guide
  • Introduces Junit Annotation, API, Assert and JUnit Test Suite
  • Advanced topics like Ignore Test, Exception Test, ErrorCollector and Parameterized Test


PostgreSQL Introduction

This post is continuation of the series. If you do not have Postgres on your machine or sample data, you can read Installing PostgreSQL and Loading Sample Data post first.

First of all, we have to create a schema to manage easily our domain. It is in best practices, do not let dbo schema to seize your database. I use Navicat for my DDL operations but there are free softwares like pgAdmin.

create schema membership;

Functions use dollar signs to show scopes and language keyword for the language in the scope. We have a different datetime type here; TIMESTAMPTZ, timestamp with time zone. You must specify a time zone when inserting into a column with this type. Again, it is a best practice if you have inputs from different timezones. There are several ways to change it; Set timezone = ‘UTC’ in postgresq.conf or on connection, or in your queries.

create or replace function membership.random_string(len int) returns text as
$$
	select substring(md5(random()::text), 0, len) as result;
$$ language sql;

create or replace function membership.the_time() returns TIMESTAMPTZ as
$$
	select now() as result;
$$ language sql;


PostgreSQL as NoSQL

This post is continuation of the series. If you do not have Postgres on your machine or sample data, you can read Installing PostgreSQL and Loading Sample Data post first.

There are two JSON (JavaScript Object Notation) types for storing JSON data.

The json data type stores an exact copy of the input text, which processing functions must reparse on each execution; while jsonb data is stored in a decomposed binary format that makes it slightly slower to input due to added conversion overhead, but significantly faster to process, since no reparsing is needed.

Create a table with a column with jsonb data type.

create table film_docs(data jsonb);

Insert all the data in the row to that column. The original table comes from the sample data.

insert into film_docs(data)
select row_to_json(film)::jsonb
from film;

select (data ->> 'title') as Title,
(data -> 'length') as Length
from film_docs
where data -> 'title' ? 'Chamber Italian';

There are lots of JSON functions and operators. I think Entity Framework does not have these functions.


PostgreSQL Advanced

This post is continuation of the series. If you do not have Postgres on your machine or sample data, you can read Installing PostgreSQL and Loading Sample Data post first.

There are functions like date_gt to compare date types.

select * from payment
where date_gt(payment_date::date, '2007-04-01'::date);

You can use date_part to get a part of datetime.

select amount, payment_date, date_part('quarter', payment_date) as quarter, 
date_part('year', payment_date) as year, concat('Q', date_part('quarter', payment_date), '-',
date_part('year', payment_date)) as display_quarter
from payment;

generate_series(start, stop, step) generates a series of values, from start to stop with a step size of step. We need a function like f(x) to get the value. If we use a negative number as step, it will be decreasing.

select x, md5(random()::text) from generate_series(100, 0, -5) as f(x);

select x from generate_series('2001-10-01'::TIMESTAMP, '2002-10-01'::TIMESTAMP, '10 days') as f(x);

postgres_generate_series.png


Installing PostgreSQL and Loading Sample Data

As an experienced and certified .NET Developer, Postgres made my attention. I will tell about its reasons in another post.

I will write my notes about Postgres in this series. We will start with installing and loading sample data to our database in this post and we will have a result like below at the end.

postgres_dvdrental.png

First, download PostgreSQL database from PostgreSQL Downloads page to install. I use Windows so I chose Windows installer but you can use another operating system and also to develop because we can code ASP.NET Core Web Application in different operating systems.


Connect to Postgres with EF Core

We can use an ASP.NET Core Web Application template to create our Web API. We will use Npgsql, a PostgreSQL database provider for Entity Framework Core. Install its package from NuGet with the command below.

PM>  Install-Package Npgsql.EntityFrameworkCore.PostgreSQL

If you already have a Postgres database, add its connection string to appsettings.json as PostgreConnection or you can read Installing PostgreSQL and Loading Sample Data post in this series to install a database on your machine.

appsettings.json

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "Data": {
    "PostgreConnection": {
      "ConnectionString": "User ID=dvdclerk;Password=dvdsafe;Host=localhost;Port=5432;Database=dvdrental"
    }
  }
}

Write a model for film table of the sample data. Important part is Postgres is case sensitive here, so we need to define column and table names explicitly. Also EF wants to know the identity column of the table.


Deutschland 83 Encoded Floppy Disc

Deutschland 83 is a series about the political conflicts between West and East germany. In the third episode which is called “Atlantic Lion” of the first season, the underdeveloped technology of East Germany doesn’t let the officers to read the floppy disc of a NATO official.

deutschland_83_ibm_typing.png

They finally acquire an IBM Model 5155 computer from the West but they find the disc is encoded. When they insert the disc, it starts to print out number with 5 digits as 6 columns and unknown rows of matris. After that, they start to decode it.

On the next scene, we see a code block which generates random numbers on the screen with 3 for loops. As we can see from that, the number of rows is 64 and the matris is all random. Also there are some mistyped letters with Syntax error below.


C# 7.0 New Features in One File

C# now has some new features with the release of Visual Studio 2017. Those features focused on code simplification, performance and data consumption. I prepared a simple console application to show them in one file.

Out variables

out variables lets us to declare variables inline. I you don’t want to declare a variable for any of out variable you can use _ sign.

Patterns “is”

Constant, Type or Var patterns can be used in if statements and you can declare new inline variables as in out variables.

Switch statements

Switch has biggest improvements. You can switch, not just primitive types, any type you want. Patterns can be used in case clauses which can have additional conditions with when keyword.