Skip to content

Instantly share code, notes, and snippets.

View dusekdan's full-sized avatar
🟠
MIA

Daniel Dusek dusekdan

🟠
MIA
View GitHub Profile
@dusekdan
dusekdan / 99 Haskell Problems with explanation.hs
Last active June 2, 2017 18:54
99 Haskell Problems (https://wiki.haskell.org/99_questions) as solved and explained by Daniel Dušek
-- #1
-- Find the last element of a list
-- Explanation:
-- Last element of one-element list is the element
-- General list last element is discovered by recursively calling myLast over
-- the tail of the list (xs). Once case myLast [x] is hit, we got our last
-- element.
myLast :: [a] -> a
myLast [x] = x
myLast (x:xs) = myLast(xs)
% #1
% Get last element from the list
% Explanation:
% Last element of list containing one element is the element
% Recursively call my_last on TAIL of the list, in rule head notice the underscore
% sign. We put it there because our rule body does not need to contain named
% reference to the list head - in other words, we don't care about it.
my_last(X, [X]).
my_last(X, [_|T]) :- my_last(X, T).
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
// Identificator of span which display mode should be altered
var SPAN_IDENTIFICATION = 'elementident';
function changeDisplayModeToBlock(elementId)
{
@dusekdan
dusekdan / FIT-VUT-WAP-DOMTreeJS.htm
Last active May 11, 2017 14:33
Update wrong function call (refactoring left over)
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
// DOM Node Type ELEMENT (=> we are only interested in elements, we dont want (attributes/CDATA/etc.))
var DOM_TYPE_ELEMENT = 1;
// TAG NAME of root element we want to use for DOM tree traversing
var ROOT_NODE_TAG_NAME = 'html';
/**
* Displays program's help screen
*/
void showHelp ()
{
printf ("Ticket algorithm synchronization demo.\n\n");
printf ("Usage: ./XXX N M\n\n");
printf ("Creates N threads and simulates M number of total passes through critical section protected by ticket algorithm.\n\n");
printf ("No other available options. Wrong parameters to the program shows this help.\n");
}