Skip to content

Instantly share code, notes, and snippets.

View mbjelac's full-sized avatar
🏠
Working from home

Marko Bjelac mbjelac

🏠
Working from home
View GitHub Profile
@mbjelac
mbjelac / ada-random-sort.adb
Created May 15, 2019 14:21
Ada random sort
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Numerics.Discrete_Random;
procedure jdoodle is
type Int_Array is array(Natural range <>) of Integer;
function isSorted(numbers: Int_Array) return boolean is
begin
// file: num-store.js
// plain JS "store" - one of many possible!
//-----------
export const numberStore = {
count: 0;
}
//-----------
// file: incrementor.js
@mbjelac
mbjelac / carrot-soup.test.js
Last active March 1, 2019 08:42
A test resolves the "User manual" comment problem
describe("more carrots means more carrot slices", () => {
test.each`
carrots | slices
${0} | ${0}
${1} | ${8}
${2} | ${16}
${3} | ${24}
${10} | ${80}
${20} | ${160}
@mbjelac
mbjelac / carrot-soup-user-manual.js
Last active March 1, 2019 08:41
Comment type: User manual
/*
Carrot Soup Factory
===================
This creates carrot soup. (Go figure!)
## API
Parameters:
@mbjelac
mbjelac / 2-algorithms-solved.js
Last active March 1, 2019 08:42
Resolving the "Two algorithms" comment problem
function createCarrotSoup() {
carrots = buyCarrots();
onions = buyOnions();
validateFreshness([carrots, onions]);
pot = [carrots, onions, SALT];
hotPlate = startCooking(pot);
@mbjelac
mbjelac / 2-algorithms.js
Last active March 1, 2019 08:40
Comment type: 2 algorithms
/*
a recipe for carrot soup:
1. buy carrots & onions at the market (make sure they are fresh!)
2. slice carrots
3. slice onions
4. put carrots, onions & some salt in a pot
5. fill pot with water
6. heat it up
@mbjelac
mbjelac / extraction-todo-done.js
Last active March 1, 2019 08:40
Resolved "extraction TODO"
function launch() {
trajectory = calculateTrajectory();
// use trajectory...
}
function calculateTrajectory() {
x = 6;
@mbjelac
mbjelac / extraction-todo.js
Created February 26, 2019 07:53
comment type: extraction TODO
function launch() {
// calculate trajectory
x = 6;
y = 7;
traj = x * y;
// use traj...
}
@mbjelac
mbjelac / jest-toequal.test.js
Created November 29, 2018 09:54
Jest toEqual failure report with undefined properties
const a = { foo: undefined, bar: 1 };
const b = { bar: 2 };
test('toEqual wrongly reports undefined properties', () => {
expect(a).toEqual(b);
});
test('toStrictEqual wrongly reports undefined properties', () => {
@mbjelac
mbjelac / MockServerTroubleshootingTest.java
Created November 21, 2017 08:08
MockServer reset lag: multiple tests including NettyClient
import org.apache.http.client.fluent.Request;
import org.junit.Before;
import org.junit.Test;
import org.mockserver.client.netty.NettyHttpClient;
import org.mockserver.client.server.MockServerClient;
import org.mockserver.model.HttpRequest;
import org.mockserver.model.OutboundHttpRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;