Skip to content

Instantly share code, notes, and snippets.

View amitaibu's full-sized avatar

Amitai Burstein amitaibu

View GitHub Profile
@amitaibu
amitaibu / gist:4427e2319ebc3d8aa0bcd9264270e6f3
Last active March 19, 2024 15:26 — forked from djazayeri/gist:d3dc89988486fe6f988d
Example of using OpenMRS REST to create a patient and an encounter (in OpenMRS 2.1)
// go to https://demo.openmrs.org, log in as admin/Admin123, open the JavaScript console, and do the following:
var URL_BASE = "https://demo.openmrs.org/openmrs/ws/rest/v1/";
var resources = {};
function andLog(data) { console.log(data); }
function andSaveAs(variable) { return function(data) { resources[variable] = data; console.log(variable + " => " + JSON.stringify(data)); } }
function andSaveFirstResultAs(variable) { return function(data) { data = data.results[0]; resources[variable] = data; console.log(variable + " => " + JSON.stringify(data)); } }
function random() { return Math.floor(Math.random() * 10000); }
function post(resource, data, success) {
$.ajax({ type: "POST", url: URL_BASE + resource, contentType: "application/json", data: JSON.stringify(data), success: success });
instance ToJSON Html where
toJSON html = String (TL.toStrict $ Renderer.renderHtml html)
data-tree={encode someJsonValue}
<div class="flex flex-row justify-between">
<div>Name</div>
<div class="flex flex-row items-center gap-x-4 divide-x">
<div>Edit</div>
<div>Delete</div>
</div>
</div>
let
# Execute:
# nix-shell --run 'make build/ihp-lib's
ihp = builtins.fetchGit {
url = "https://github.com/digitallyinduced/ihp.git";
# ref = "refs/tags/v0.19.0";
rev = "05f1eafbe897dfdbf8a77e5bd0673b1857f4e8c2";
};
haskellEnv = import "${ihp}/NixSupport/default.nix" {
curl --silent https://raw.githubusercontent.com/digitallyinduced/ihp/master/Troubleshoot/ihp-troubleshoot | python3
Checking that the current directory is an IHP project:
+ Found Main.hs
+ Found start script
+ Nix installed
Checking direnv:
+ Found .envrc
+ direnv loads .envrc
+ direnv allows .envrc
DEBUG=1 ./start
direnv: loading ~/Sites/Haskell/ihp/ihp-simple-seat-reservation/.envrc
direnv: export ~PATH
IHP Version: 0.20.0
Opening in existing browser session.
GET /
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Status: 302 Found 0.002388625s
[("ihpVersion","0.20.0"),("os","linux"),("arch","x86_64"),("projectId","02f68fafb04ff896261af0ac082ec9f688c950e1d1b6612e3a5f304a5cfc91c6dc7e6cd27c08d0aea4c5dba559bc041e98ee90fdfce8c83d69208692adef74b7")]
[
    {
        "key": "1",
        "tree": [
            {
                "key": "1.1",
                "tree": {
                    "key": "1.1.1"
 }
module Radix exposing (..)
import List.Extra
import Tree
import Tree.Zipper as TreeZipper
empty : Tree.Tree (List a)
empty =
Tree.singleton []

I'd like to convert the List (List Int) to a Tree, where it will group similar items together.

So imagine the following:

[
  [ 1 , 2, 3, 4]
  [ 1 , 2, 5, 6]
  [ 1 , 2, 3, 7]
]
@amitaibu
amitaibu / example.hs
Last active September 30, 2021 12:40
action CreateBidAction = do
let bid = newRecord @Bid
bid
|> buildBid
>>= ifValid \case
Left bid -> render NewView { .. }
Right bid -> do
bid <- bid |> createRecord
_ <- forkIO $ do