Skip to content

Instantly share code, notes, and snippets.

View Martinsos's full-sized avatar

Martin Šošić Martinsos

View GitHub Profile
@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.
#!/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)
/**
* 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
@Martinsos
Martinsos / gist:73c61312eabf5b5aea9ccbd7be2e3700
Created September 12, 2021 15:21
CSS that highlights start/end of working day on google calendar.
.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 / ChristmasTree.hs
Last active December 23, 2022 16:57
Short Haskell function that prints a christmas tree
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 / plan-prompt.txt
Last active August 11, 2023 10:17
[Wasp] [GPT Web App Generator] Example of plan generation GPT prompt
Wasp is a full-stack web app framework that uses React (for client), NodeJS and Prisma (for server).
High-level of the app is described in main.wasp file (which is written in special Wasp DSL), details in JS/JSX files.
Wasp DSL (used in main.wasp) reminds a bit of JSON, and doesn't use single quotes for strings, only double quotes. Examples will follow.
Important Wasp features:
- Routes and Pages: client side, Pages are written in React.
- Queries and Actions: RPC, called from client, execute on server (nodejs).
Queries are for fetching and should not do any mutations, Actions are for mutations.
- Entities: central data models, defined via PSL (Prisma schema language), manipulated via Prisma.
Typical flow: Routes point to Pages, Pages call Queries and Actions, Queries and Actions work with Entities.
@Martinsos
Martinsos / link-rewrite.hs
Last active January 12, 2024 17:03
Haskell script for rewriting absolute docs/ links in Docusaurus docs to relative ones.
@Martinsos
Martinsos / wasp-imports-migration-011-to-012.js
Last active February 2, 2024 15:59
JS script that encodes import migrations from Wasp 0.11 to 0.12
const util = require('util');
// `same` means that new export is same as old one. Same name, also type, also user defined.
// The only thing that we impliclty assume will change even for `same` is that new exports are always
// considered to be named exports, even if original one was default.
const same = Symbol("SAME")
const importMappings = [
[["@wasp/config.js", dflt("config")],
["wasp/server", same]