Skip to content

Instantly share code, notes, and snippets.

Avatar

Tom Short tshort

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

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 Nov 3, 2021
VSCodeVim / VSpaceCode extensions for using Julia in VS Code
View vscodevim-vspacecode-julia.md

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 Apr 25, 2021
Julia crash with v1.6.1
View explanation.md

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 Apr 17, 2021
ModelingToolkit experiments with functional composition of models
View summary.md

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 Jun 26, 2020
Implementing the mirror plugin for Kakoune in Dance
View keybindings.json
[
{
"key": "'",
"command": "dance.openMenu",
"args": {
"menu": "mirror"
},
"when": "editorTextFocus && dance.mode == 'normal'"
},
]
@tshort
tshort / mdpad-franklin-hyperscript.md
Created Feb 16, 2020
Using mdpad with Franklin.jl and Hyperscript.jl
View mdpad-franklin-hyperscript.md

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 Feb 16, 2020
Using mdpad with Franklin.jl
View mdpad-franklin.md

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>
View ccall-shortcut.md

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 Dec 18, 2019
Example of compilation using StaticCompiler.jl (a very experimental package)
View compile-fib.jl
# 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 Nov 9, 2019
Trait example from "Rust By Example"
View Trait example from Rust.md

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)