Wednesday, 28 March 2018

Javascript Diceware Selector

Click the button to simulate die roll. View the source to ensure everything here is above board:

Length:
Modulo result:

Javascript Die Roller - Easier Than Soldering ICs

Save this text in a .js file and load the .js file locally in your browser:

<!DOCTYPE html>
<html>
<body>

<p>Click the button to display the milliseconds of the time right now.</p>

<button onclick="myFunction()">Roll Die</button>
<button onclick="addNewLine()">Br</button>

<p id="demo"></p>

<script>
function myFunction() {
    var d = new Date();
    var n = 1 + d.getMilliseconds() % 6;
    document.getElementById("demo").innerHTML += n;
}
function addNewLine() {
    document.getElementById("demo").innerHTML += '<br>';
}

</script>

</body>
</html>

20180329: R + Shiny - Service Operation Visualiser #2


This version has a rescalable plot from <<https://github.com/rstudio/shiny/issues/650>> that uses the session parameter in the server function setup:

library(ggraph)
library(igraph)(data.table)
t01 <- fread("C:/kewoo/git/eai-bw.master/BW_Projects/Tools/findOperationUsage.csv")
setnames(t01, "BW Calling Project", "BW_Calling_Project")
setnames(t01, "BW Project", "BW_Project")
setnames(t01, "BW Exposed Service", "BW_Exposed_Service")
setnames(t01, "BW Process", "BW_Process")
t01[,reqSUB1 := sub("Request", "", BW_Process)]
t01[,reqSUB2 := sub(".process", "", reqSUB1)]
t01[,reqSUB3 := sub("(\\w)", "\\L\\1", reqSUB2, perl=TRUE)]
t01[,operSUB1 := sub("(\\w)", "\\L\\1", Operation, perl=TRUE)]

# t01a is a caller-centred graph, giving you a callee-list (via subcomponent mode = out) for any given service operation
t01a <- t01[,.(caller = paste(BW_Calling_Project, reqSUB3, sep = "-"),
               callee = paste(BW_Project, operSUB1, sep = "-"))]
ig01a <- graph_from_data_frame(t01a, directed = TRUE)

library(shiny)

# Define UI for app that draws a histogram ----
ui <- fluidPage(
  titlePanel(h1("Service Operation Call Dependency Visualiser")),
  
  sidebarLayout(
    sidebarPanel(
      h1("Service Operations"),
      selectInput("ServiceOperation", h3("Choose"), 
                  choices = sort(V(ig01a)$name))
    ),
    mainPanel(
      plotOutput("ServiceOpDependencies_ig")
    )
  )
)


# Define server logic required to draw a histogram ----
server <- function(input, output, session) {
  output$ServiceOpDependencies_ig <- renderPlot({
    plot.igraph(induced_subgraph(ig01a,
                                 subcomponent(ig01a, input$ServiceOperation, mode = c("out"))),
                frame = 1,
                vertex.shape = "none",
                vertex.label.dist = 1,
                edge.curved = 0.1,
                layout=layout_with_kk)},
    height = function() {
      0.75 * session$clientData$output_ServiceOpDependencies_ig_width
    })
}

shinyApp(ui = ui, server = server)