Dustjs OR helper - dust.js

How to write below statement using dust helper?
{#eq key="device" value="windows || Linux"}
Your system is Windows or Linux based.
{:else}
Your system is MAC based.
{/eq}

You can use the #any helper with the Select Helper to achieve this:
{#select key=device}
{#eq value="windows"/}
{#eq value="Linux"/}
{#any}Your system is Windows or Linux based.{/any}
{#none}Your system is MAC based.{/none}
{/select}

Related

How do I check the OS in the F# preprocessor?

We're multiple persons working on the same F# project. Some use MacOS and Visual Studio Code together with Ionide while others use Windows with Visual Studio. In the F#-code, we need to access some files, but MacOS uses / to specify paths while Windows uses \. In F#, how can we make something like:
#if OS_WINDOWS
let path = "path\to\file.txt"
#elif OS_MAC
let path = "path/to/file.txt"
#endif
There is no built-in pre-defined symbol to indicate what operating system you are compiling for. When you use .NET, you generally use the same compiled assembly on all operating systems, so this is not something that you can reasonably do in a pre-processor anyway.
You can check what OS are you running on at runtime using System.Environment:
open System
let path =
if Environment.OSVersion.Platform = PlatformID.Win32NT then #"path\to\file.txt"
else #"path/to/file.txt"
That said, if your only concern is slashes and backslashes in a path, you can just use:
let path = System.IO.Path.Combine("path", "to", "file.txt")

Running Python commands in xterm js?

Is is possible to execute python commands through xterm js? I want to easily print a "Hello World" statement below but not sure how to properly implement that.
<div id="terminal"></div>
<script>
var term = new Terminal();
term.open(document.getElementById('terminal'));
term.write(print("Hello World"))
</script>
No, not directly like that. xterm.js is only a visual renderer. You'd have to write a backend that actually takes the user input, runs the command (in your case in a python shell) and then tells xterm.js what to render.

Dymola mos script environment variables

Is there a way to use the Windows environment variables in Dymolas .mos scripts?
Something like this:
// Load libraries, last one determines the working directory
openModel(%USERPROFILE% + "Documents/Dymola/MyTestLib/package.mo");
Alternatively, does Dymola know some other predefined pathes?
I would like to make .mos script a bit more portable to a different PC.
You can use the getEnvironmentVariable function from the MSL.
So this should do what you want:
user_profile = Modelica.Utilities.System.getEnvironmentVariable("USERPROFILE", convertToSlash=true);
openModel(user_profile + "/Documents/Dymola/MyTestLib/package.mo");
On startup Dymola also defines two useful environment variables:
DYMOLA: the dymola installation directory, e.g. C:/Program Files/Dymola 2019 FD01
DYMOLAWORK: the startup directory, with C:/Users/<user>/Documents/Dymola as default. See user Manual 1 for details.

How to format/beautify rails erb code

How to format/beautify rails erb code. The view code is a mix of erb and JS.
I tried using the following tool as well, but it didn't help
https://github.com/katgironpe/rails-erb-lint
A good IDE to format/beautify rails is RubyMine.
RubyMine is able to reformat many types of files, like Ruby, HTML, JavaScript, CSS, etc.
example for reformat erb file:
Before:
After:
You can set the code style in the Preferences / Editor / Code Style
The tool which you already used, i.e., rails-erb-lint, checks only for the validity of you ERB and doesn't help with beautifying the ERB code. I don't know which editor you are using, but you can try either Sublime Text 3 or Github's Atom. Both of these have 3rd party packages to beautify Ruby and ERB code. Moreover, the indentation and trailing whitespace removing ability of these editors are enough to beautify/format the ERB files, though they have menu items/ shortcuts to do this on-demand/selectively too.
If you are using Sublime Text, check out this "Sublime Text 2 & 3 Plugin to BeautifyRuby":
https://github.com/CraigWilliams/BeautifyRuby
Once installed via Sublime's Package Control System you can use the shortcut ctrl + alt + k (on Windows + Linux) or ctrl + cmd + k (on OS X) to beautify your Ruby and erb-files manually - or configure the plugin to do that automatically before saving any Ruby- and erb-file. Configuration is easy - you find the config-file here (via the Sublime- menu):
Preferences > Package Settings > BeautifyRuby > Settings - Default:
{
// Specify your ruby interpreter (below). (Note, if you are using a linux distro with Rbenv instead of RVM, then try the following path: "ruby": "~/.rbenv/shims/ruby")
"ruby": "~/.rvm/bin/rvm-auto-ruby",
// Use 2 Spaces instead of tabs:
"translate_tabs_to_spaces": true,
"tab_size": 2,
// You can change the file patterns handled by this plugin:
"file_patterns": ["\\.html\\.erb", "\\.rb", "\\.rake", "Rakefile", "Gemfile", "Vagrantfile"],
"html_erb_patterns": ["\\.html\\.erb"],
// This package offers a pre-save hook; when activated, your ruby and erb files will
// be reformatted automatically before saving (deactivated by default)
"run_on_save": false,
// The sublime command "beautify_ruby" performs a save after formatting.
// (activated by default)
"save_on_beautify": false
}
BeautifyRuby depends on the Ruby gem htmlbeautifier, which needs to be installed on your system first. Otherwise the plugin throws an error each time you try to beautify your code. Make sure, the ruby-interpreter-setting in the config file shown above points to the correct ruby which holds the htmlbeautifier-gem...

Lua return directory path from path

I have string variable which represents the full path of some file, like:
x = "/home/user/.local/share/app/some_file" on Linux
or
x = "C:\\Program Files\\app\\some_file" on Windows
I'm wondering if there is some programmatic way, better then splitting string manually to get to directory path
How do I return directory path (path without filename) in Lua, without loading additional library like LFS, as I'm using Lua extension from other application?
In plain Lua, there is no better way. Lua has nothing working on paths. You'll have to use pattern matching. This is all in the line of the mentality of offering tools to do much, but refusing to include functions that can be replaced with one-liners:
-- onelined version ;)
-- getPath=function(str,sep)sep=sep or'/'return str:match("(.*"..sep..")")end
getPath=function(str,sep)
sep=sep or'/'
return str:match("(.*"..sep..")")
end
x = "/home/user/.local/share/app/some_file"
y = "C:\\Program Files\\app\\some_file"
print(getPath(x))
print(getPath(y,"\\"))
Here is a platform independent and simpler solution based on jpjacobs solution:
function getPath(str)
return str:match("(.*[/\\])")
end
x = "/home/user/.local/share/app/some_file"
y = "C:\\Program Files\\app\\some_file"
print(getPath(x)) -- prints: /home/user/.local/share/app/
print(getPath(y)) -- prints: C:\Program Files\app\
For something like this, you can just write your own code. But there are also libraries in pure Lua that do this, like lua-path or Penlight.

Resources