Skip to content

Instantly share code, notes, and snippets.

// From Stephen:
// This is the code that was written live on-stage on October 25, 2023.
// I've recreated a few of the tests / examples that I overwrote / deleted
// as I was building up the layers of functionality.
// Recommended follow-up reading:
// https://devblogs.microsoft.com/dotnet/how-async-await-really-works/
using System.Collections.Concurrent;
using System.Runtime.CompilerServices;
@marcinjahn
marcinjahn / prefs.js
Last active May 5, 2023 17:45
prefs.js with failure "JS ERROR: Failed to open preferences: ImportError: No JS module 'ui' found in search path"
const GIRepository = imports.gi.GIRepository;
const GLib = imports.gi.GLib;
let libdir = GIRepository.Repository.get_search_path().find(path => {
return path.endsWith("/gjs/girepository-1.0");
}).replace("/gjs/girepository-1.0", "");
const gsdir = GLib.build_filenamev([libdir, "gnome-shell"]);
if (!GLib.file_test(gsdir, GLib.FileTest.IS_DIR)) {
const currentDir = `/${GLib.path_get_basename(libdir)}`;
libdir = libdir.replace(currentDir, "");
}
@marcinjahn
marcinjahn / oceny.cs
Last active February 10, 2023 15:05
Przykład programu na zaliczenie C#
using System;
using System.Collections.Generic;
using System.Linq;
// Typy danych
record Student(IEnumerable<SubjectWithMarks> Subjects);
record SubjectWithMarks(Subject Subject, Marks Marks);
record Marks(int Semester1Mark, int Semester2Mark);

Transport Control Protocol (TCP)

Allows 2 endpoints to exchange data reliably ovet the network. It is a Transport (4th) layer of OSI.

Connection

Connection between 2 computers is identified by:

  • source IP
  • source port

Arguments

Function has an arguments object containing all of the arguments passed by the called (even if function does not define any parameter, you can still pass arguments).

Arrow functions do not have this parameter.

Arrow Functions

this is inherited from the scope where arrow function was defined.

OOP

There are 3 ways of using objects:

  • Object Literals
  • Constructor Functions
  • Classes

Object Literals

IIFE

A way to make file's data non-global is to use IIFE:

(function () {
    statements
})();

Overview

HttpClient uses implementations of HttpMessageHandler to do its job. The default handler is HttpClientHandler.

There may be a chain of handlers (delegating handler pattern). Messages go down throug handlers and responses go up to the HttpClient. Any handler can decide not to pass message down and return a response earlier (i.e. caching).

HttpClient configuration

_httpClient.BaseAddress = "http://www..google.pl";

Random values

//Random number
let random = Int.random(1...10)

//Random array element
let array = [1, 2, 3, 4]
let randomFromArray = array.randomElement()