Skip to content

Instantly share code, notes, and snippets.

View tshort's full-sized avatar

Tom Short tshort

  • Electric Power Research Institute
View GitHub Profile
@tshort
tshort / mechanical-example.md
Last active November 25, 2021 12:57
MTK equation explorations: mechanical example

I'm trying to implement this Modelica example from Michael Tiller's Modelica by Design. I don't understand the rules for writing DAE equations in MTK.

Here's a version in semi-explicit form with the derivative terms alone on the left-hand side:

using ModelingToolkit, OrdinaryDiffEq
const D = Differential(t)
@variables t

@variables phi1(t) phi2(t)=1.0 omega1(t) omega2(t)
@tshort
tshort / vscodevim-vspacecode-julia.md
Last active November 3, 2021 22:31
VSCodeVim / VSpaceCode extensions for using Julia in VS Code

Here are additions to keybindings.json to support more VIM-like keys in the plot pane. This could be a PR to julia-vscode.

            {
                "command": "language-julia.plotpane-previous",
                "key": "k",
                "when": "jlplotpaneFocus && !inputFocus"
            },
            {
                "command": "language-julia.plotpane-next",
@tshort
tshort / explanation.md
Created April 25, 2021 22:57
Julia crash with v1.6.1

Here's the code to trigger the crash:

using Pkg
Pkg.add(url="https://github.com/tshort/Sims.jl", rev="mtk")
Pkg.add("ModelingToolkit")
using Sims, Sims.Examples.Lib
m = CauerLowPassOPV()
@tshort
tshort / summary.md
Created April 17, 2021 00:38
ModelingToolkit experiments with functional composition of models

Here's an attempt to functionally compose MTK models where each model is an ODESystem:

using ModelingToolkit, Symbolics


struct NodeSet end

isnode(x::Num) = isnode(Symbolics.value(x))
@tshort
tshort / keybindings.json
Created June 26, 2020 10:49
Implementing the mirror plugin for Kakoune in Dance
[
{
"key": "'",
"command": "dance.openMenu",
"args": {
"menu": "mirror"
},
"when": "editorTextFocus && dance.mode == 'normal'"
},
]
@tshort
tshort / mdpad-franklin-hyperscript.md
Created February 16, 2020 00:20
Using mdpad with Franklin.jl and Hyperscript.jl

mdpad example with Hyperscript.jl inputs and Mithril outputs

This is an example mdpad page. The inputs and outputs are generated using the mdpad-mithril helper functions. These helper functions rely on Mithril and Bootstrap.

#hideall
using Hyperscript
@tshort
tshort / mdpad-franklin.md
Created February 16, 2020 00:18
Using mdpad with Franklin.jl

mdpad example with Mithril inputs and outputs

This is an example mdpad page. The inputs and outputs are generated using the mdpad-mithril helper functions. These helper functions rely on Mithril and Bootstrap.

<div id="input"></div>

I'd like to turn the following

i32_from_name(id) = @extern("i32_from_name", Int32, (Any,), string(id))

into:

i32_from_name(id) = ccall("extern i32_from_name", llvmcall, Int32, (Any,), string(id))

I just want to simplify the ccall with a macro or generated function, so I don't have to include the "extern " and llvmcall every time. I haven't had luck with either macros or generated functions.

@tshort
tshort / compile-fib.jl
Created December 18, 2019 14:01
Example of compilation using StaticCompiler.jl (a very experimental package)
# Run the following from within `StandaloneCompiler/test`.
# Amin Yahyaabadi (@aminya) is working on a PR to make some of this easier.
include("jlrun.jl")
function fib(n)
a, b = 0, 1
while n > 0
a, b = b, a + b
n = n - 1
@tshort
tshort / Trait example from Rust.md
Last active November 9, 2019 00:08
Trait example from "Rust By Example"

Here is a Julia implementation from this trait example in Rust By Example.

## Define the object

mutable struct Sheep
    name::String
    naked::Bool
end
Sheep(name) = Sheep(name, false)