Jekyll - sort pages by integer - sorting

I have some problem of pages with a custom attribute 'n', taking integer values. I would like to iterate through them in order. However,
{% assign pp = site.pages | sort:"n" %}
{% for p in pp %}
...
{% endfor %}
only sorts the attribute values as strings, so I obtain
1, 10, 2, 3, ...
How do I sort by numerical value? I need a plugin-free solution since I am using github.

If your page.n are sorted like strings, maybe you assign them like string (n: "1").
Be sure to assign them like integers (n: 1).

Related

PRAAT create string array and search in that array

It seems like an easy task (and is easy in other languages), but Im having trouble finding a solution.
Is it possible to create an array of strings? I'm looking for a PRAAT equivalent of the following python code
options=["a","b","cd"]
The ultimate goal is to do something like
Input=["ab","cd","ef"]
for InputEle in Input
if InputEle is in options
do blah
endif
endfor
You could use a string vector:
options$# = {"a", "b", "cd"}
for i from 1 to 3
appendInfoLine: options$# [i]
endfor
Check out section 8 at https://www.fon.hum.uva.nl/praat/manual/Scripting_5_7__Vectors_and_matrices.html

Is there a way to use the list output from a jinja2 `range` function directly in a template?

I'm using jinja2 to template a supercollider startup file.
I have a variable {{ sc_option_numOutputBusChannels }} from which I need to generate a list.
Specifically, if sc_option_numOutputBusChannels = 8, then I need to create the following list:
[0, 2, 4, 6]
for use in the line:
~dirt.start(57120, [0, 2, 4, 6]);
The function range(0, sc_option_numOutputBusChannels, 2 ) outputs that list exactly as I need it, but I've been unable to find a way to use the output of range directly as a string in my template - eg these don't work:
~dirt.start(57120, {% range(0, sc_option_numOutputBusChannels, 2 ) %} );
~dirt.start(57120, {{ range(0, sc_option_numOutputBusChannels, 2 ) }} );
Is there a way to do this?
I would guess it is because range by itself is a generator, and thus needs a consumer to indicate to ansible that you're done with the generator pipeline; the most common one I know of is | list
- debug:
msg: ~dirt.start(57120, {{ range(0, sc_option_numOutputBusChannels, 2 ) | list }} );

How to correctly sort merged arrays in Drupal 8 Twig template

I'm new here for one question.
I have a node type in Drupal 8 with some fields referencing to taxonomy terms. I like to display these terms all together in one sorted array, so I merge the fields and sort them. But the result is always incompletely sorted, some terms are moved, but the others stay in the order they are saved.
I tried different ways for sorting:
sort function:
{% for t in node.field_x|merge(node.field_y)|merge...|sort((a, b) => a.entity.name.value < b.entity.name.value ? -1 : (a.entity.name.value > b.entity.name.value ? 1 : 0)) %}...{% endfor %}
strcmp
|sort((a, b) => strcmp(a.entity.name.value, b.entity.name.value))
and I tried it with a twig extension function in a new module.
But it's always the same wrong result. So obviously I am wrong at some important point.
Can you help me?

How to assign more than one value to UInt32

I am trying to set the bird group as two numbers so that when I assign a variable I can use multiple "else if" statements with that one group later on
Code:
Xcode doesn't let me do this I'm in Swift
Let birdgroup: UInt32 = 2, 3
You can use Array, Set, or a tuple to store multiple values in a single variable. If order matters, go with Array or tuple, but if the order doesn't matter, you can use Set. Array and Set both allow you to vary the number of values stored in your variable, while a tuple variable must always be the same length. Also, you can loop over the items in an array or set, but not over a tuple.
Array is the most often used of the three, so if you aren't sure which to use, it's a good first choice.
In summary, this table shows the possibilities and their properties:
Loopable Unloopable
Ordered Array Tuple
Unordered Set (none)
Finally, all the items in an array or set must be of the same type (or derived from the same type, if the array or set is defined with the base class). This is called homogeneous. A tuple can contain different types, also known as heterogeneous.
Homogeneous Heterogeneous
Ordered Array Tuple
Unordered Set (none)
Collection Types in the Swift documentation describes how to use Array and Set.
Array
Create an array with
var birdgroup: [UInt32] = [2, 3]
birdgroup[0] is equal to 2, and birdgroup[1] is equal to 3. You can also access the items by looping:
for bird in birdgroup {
println("\(bird)")
}
Set
You can declare a set with
var birdgroup: Set<UInt32> = [2, 3]
Because sets have no order (imagine every item is tossed together in a bag), you can't request the "first" or "second" item. Instead, loop over each item of the set:
for bird in birdgroup {
println("\(bird)")
}
Tuple
let birdgroup: (UInt32, UInt32) = (2, 3)
Tuples also retain the order of their items. birdgroup.0 is equal to 2, and birdgroup.1 to 3. You can also give each item of the tuple a name if you prefer that to a number:
let birdgroup: (UInt32, UInt32) = (foo: 2, bar: 3)
birdgroup.foo is 2, and birdgroup.bar is 3.
Additionally, the values in a tuple do not all need to be the same type. You can combine different types, such as
let heterogeneousTuple: (UInt32, String) = (2, "three")

How do I display a list of long integers? (Mercury language)

In io.write_list(List(integer), ",", OutputPred, !IO), what is OutputPred? I'm trying to display a list of type integer. The list is initially never empty.
io.write_list(MyList, ",", io.write, !IO), where MyList is a list of type integer, will cause MyList members to be printed/displayed. Each member has the following display format i(1, [integer_value]), so it's an awkward appearing output, but is correct. An empty list prints nothing and doesn't result in error.
An alternative is io.write(MyList, !IO) and produces the same result.
The answer to the question of what OutputPred is is io.write. io.print also works.
This information was obtained from Mercury.org
The following Mercury code will display/print the list of type Integer in a more common form: [10, 9, 8,..., 2, 1].
io.write_string(string.join_list(" ,", map(integer.to_string, My_List)), !IO).
The square brackets have to be added separately and can be obtained with preceding and trailing io.write_string commands.
It works. My_List is a list of elements of type integer.
This information was obtained from Mercury.org

Resources