Skip to content

Instantly share code, notes, and snippets.

Avatar

Martin Šošić Martinsos

View GitHub Profile
@Martinsos
Martinsos / ChristmasTree.hs
Last active December 23, 2022 16:57
Short Haskell function that prints a christmas tree
View ChristmasTree.hs
printTree :: Int -> IO ()
printTree h = (putStrLn . unlines . center) $ "()" : (showTreeLvl <$> [0 .. h]) ++ ["[]"]
where showTreeLvl l = "/" ++ (take (l * 2) . drop (l `mod` 3) . concat . repeat) "~~o~~*~o~~*~~o~*" ++ "\\"
center ss = let w = maximum (length <$> ss) in (\s -> concat (replicate ((w - length s) `div` 2) " ") ++ s) <$> ss
-- > printTree 5
--
-- ()
-- /\
-- /~o\
@Martinsos
Martinsos / gist:73c61312eabf5b5aea9ccbd7be2e3700
Created September 12, 2021 15:21
CSS that highlights start/end of working day on google calendar.
View gist:73c61312eabf5b5aea9ccbd7be2e3700
.mmsF1c:nth-child(10)::after, .mmsF1c:nth-child(19)::after {
border-bottom-color: black;
border-bottom-width: 2px;
}
// Good way to apply this CSS consistently is to use Stylebot Chrome extension.
@Martinsos
Martinsos / wifi-dongle.sh
Last active October 16, 2019 14:25
Script that uses NetworkManager to disconnect wifi card when wifi dongle connects and to reconnect it when wifi dongle disconnects.
View wifi-dongle.sh
#!/usr/bin/env bash
# This script should be positioned in /etc/NetworkManager/dispatcher.d/
# This script disconnects wifi card when wifi dongle connects and reconnects wifi card when
# wifi dongle disconnects. That way, when dongle is connected, we are sure it is being used instead of
# wifi card being used, and it all happens automatically.
event_interface=$1
event_type=$2
@Martinsos
Martinsos / parseAzureBlobUri.js
Last active June 17, 2020 14:20
Regex for parsing Azure Blob URI (javascript)
View parseAzureBlobUri.js
/**
* Validates and parses given blob uri and returns storage account, container and blob names.
* @param {string} blobUri - Valid Azure storage blob uri.
* Check link for more details: https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#resource-uri-syntax .
* Few examples of valid uris:
* - https://myaccount.blob.core.windows.net/mycontainer/myblob
* - http://myaccount.blob.core.windows.net/myblob
* - https://myaccount.blob.core.windows.net/$root/myblob
* @returns {Object} With following properties:
* - {string} storageAccountName