31.01.2013

Instacode

Instacode is for developers what Instagram is for hipsters. Just paste your code into the textfield and choose the level of "hipness" to get a nice image of your code. The range of supported languages is amazing and our beloved Delphi is supported as well.

The service is currently not working, due to the heavy load of users, that are trying to "beautify" their code.
Here's an example from the website:


PS: If you are visiting the site with IE, you are in for a treat ;-)

28.01.2013

Delphi and Sleepsort

A while ago, someone on 4chan posted a fun sorting algorithm. It is called Sleepsort and is not recommended to be usedin production. However, I thought it would be fun to implement it in Delphi. Here it is (for your amusement):
program Sleepsort;

var
  items: TArray<integer>;
  i: integer;

begin
  randomize;
  writeln('Random: ');
  setlength(items, 25);
  for i := 0 to High(items) do
  begin
    items[i] := random(length(items) * 4);
    write(IntToStr(items[i]) + ' ');
  end;
  writeln;
  writeln('Sorted: ');
  for i := 0 to high(items) do
  begin
     TSortThread.Create(items[i]);
  end;
  readln;
end.
unit uSortThread;

interface

uses
  Classes;

type
  TSortThread = class (TThread)
  private
    fValue : integer;
  protected
    procedure Execute; override;
  public
    constructor Create(n : integer);
  end;

implementation

uses SysUtils;

constructor TSortThread.Create(n: integer);
begin
  inherited Create;
  fValue := n;
end;

procedure TSortThread.Execute;
begin
  sleep(fValue * 333); // artificial slowdown, to make the process visible for the human eye
  write(IntToStr(fValue)+' ');
end;

end.