Deeply Nested, Arbitrarily lenth Definition Lists, Zebra-striped in Jquery - jquery-selectors

I have a page where the markup includes nested definition lists of both random depth and random numbers of DDs associated with any DT. Thus:
DL
- DT
- DD
- DT
- DD
- DD
--DL
--DT
--DD
--DT
--DD
--DD
-DT
-DD
-DD
I need:
zebra stripe the groups of DT/DDs with one another and
to start the even/odd sequence over for each nested list that is encountered.
Using :even and :odd won't work because of the extra DDs.
I've tried using an each loop, shown here: http://jsfiddle.net/XJ9j4/, which fixes A but ignores B. i.e. compare the background color of the 1st child dt/dd combination to the 1st parent, and consider the return to the parent list which should be blue not green.
Thoughts?

With my new understanding of what you want, I think this will do. Let me know if I am still misunderstanding.
$("dl").each(function(){
$this = $(this);
$this.children("dt:even").addClass("even").nextUntil("dt").addClass("even");
$this.children("dt:odd").addClass("odd").nextUntil("dt").addClass("odd");
});
http://jsfiddle.net/XJ9j4/8/

Related

Cannot properly array googlefinance formula with dates

I am trying to convert money amounts in USD to EUR, but I want to do it in relation to date of transaction taking place due to dyncamic exchange rates.
Idea is to use googlefinance function with index function, along with date function, which will be made of right, mid, and left functions. All of that should be wrapped with arrayformula. Numbers should be rounded using round.
Non-working example:
Don't mind ;, this is instead of , in my google sheets language settings.
Formula: =ARRAYFORMULA(IF(B2:B="";"";ROUND(INDEX(B2:B*GOOGLEFINANCE("CURRENCY:USDEUR";"price";DATE(RIGHT(A2:A;4);MID(A2:A;4;2);LEFT(A2:A;2)));2;2);2)))
Formula (with , instead of ;):
=ARRAYFORMULA(IF(B2:B="","",ROUND(INDEX(B2:B*GOOGLEFINANCE("CURRENCY:USDEUR","price",DATE(RIGHT(A2:A,4),MID(A2:A,4,2),LEFT(A2:A,2))),2,2),2)))
Since I'm pretty sure this formula should work in "normal circumstances", I've replicated it leaving out arrayformula, and full ranges (such as B2:B, etc), and it works once I drag down the formula.
Working example:
Formula: =IF(F2="";"";ROUND(INDEX(F2*GOOGLEFINANCE("CURRENCY:USDEUR";"price";DATE(RIGHT(E2;4);MID(E2;4;2);LEFT(E2;2)));2;2);2))
Formula (with , instead of ;):
=IF(F2="","",ROUND(INDEX(F2*GOOGLEFINANCE("CURRENCY:USDEUR","price",DATE(RIGHT(E2,4),MID(E2,4,2),LEFT(E2,2))),2,2),2))
Does anyone have idea what's going on with the first case, i.e. why it doesn't work? I believe it has to be something with those full ranges (e.g. B2:B, A2:B, etc), but not sure why...
GOOGLEFINANCE is already an ARRAYFORMULA type formula so try like this:
=ARRAYFORMULA(IF(B2:B="";;ROUND(B2:B*IFNA(VLOOKUP(A2:A+0,9986111111;
GOOGLEFINANCE("CURRENCY:USDEUR"; "price"; MIN(A2:A); MAX(A2:A)+1); 2; 1)); 2)))

Two-sided references in a list

I'm just starting to learn Perl and I have to do an exercise containing references.
I have to create a program, that constructs a list with two sided references, that are are received as command line arguments. At the beginning of the program, there is only one element in the list - 0. To go through the list, reference is being used, that references to the only element of the list at the moment - 0. The arguments of the command line are being read one by one and added right behind the element, that is being referenced to. When one argument is added, the reference slides one element to the right(it references to the newly added element). There are also two special elements - + and -. + allows the reference to move one element to the right, and - one element to the left. Also, it is important that the reference would not go beyond the list limit.
The output is all the arguments in the correct order of the list.
Additional requirements are that the list must be created by using hashes, that contain links to neighbouring elements. Also, I cannot use arrays to store the whole list.
There are a few examples to make it easier to grasp the concept, this is the most useful one:
./3.pl A D - B C + E
0 A B C D E
All I've got now is just the start of the program, it is nowhere near done and doesn't compile, but I can't figure out where to go from there. I've tried looking for some information about two-sided references(I'm not sure if I'm translating it correctly), but I can't seem to find anything. Any information about two-sided references or any tips how to start writing this program properly would be very appreciated.
My code:
#!/usr/bin/perl
use strict;
use warnings;
my $A= {
value=>'0',
prev=>'undef',
next=>'$B'
};
my $B= {
value=>'0',
prev=>'$A',
next=>'$C'
};
my $C= {
value=>'0',
prev=>'$B',
next=>'undef'
};
for my $smbl(0..#$ARGV) {
$A-> {value} = $ARGV[$smbl];
$Α-> {next} = $ARGV[$smbl+1];
}
First of all, what you are building is called a doubly linked list.
Let me tell you the biggest trick for working with linked lists: Create a dummy "head" node and a dummy "tail" node. You won't print their values, but having them will greatly reduce the number of special cases in your code, making it so much simpler!
At the core, you will have three "pointers" (references).
$head points to the first node of the list.
$tail points to the last node of the list.
$cursor initially points to the node in $tail. New nodes will be inserted before this node.
When processing +, two different situations you need to handle:
$cursor == $tail: Error! Cursor moved beyond end of list.
$cursor != $tail: Point $cursor to the node following the one it references.
When processing -, there are two different situations you need to handle:
$cursor->{prev} == $head: Error! Cursor moved beyond start of list.
$cursor->{prev} != $head: Point $cursor to the node preceding the one it references.
When processing inserting nodes, no checks need to be performed because of the dummy nodes!

Creating custom widgets for ruby gem dashing.io - Or combining widgets elements

I'm working with the dashing ruby gem and I would really like to combine elements of the graph and number widgets. I would like all elements of the graph and include the up/down percentage arrow from the number widget.
I've never done much work with ruby and I understand there are a few files within the widget that might need to be changed.
I've setup a few nice widgets and I'm using a job to pull data from a redis db to populate. I've added the following to the graph.html page:
<p class="change-rate">
<i data-bind-class="arrow"></i><span data-bind="difference"></span>
</p>
This has no effect, and I'm sure that I'm missing something in one of the many files that makes this all work.
Your on the right track, and I've actually put together something very similar but in order to complete what you are trying to do you need to send data to your two new data binds, which would be done with your jobs file and the graph.coffee file.
I'm not sure how exactly you're getting your graph data from redis to your jobs erb file but you will want to setup a couple new variables, for the example I have used nowNumber and lastNumber. These will be the number that the valuation is performed on.
jobs/jobname.erb
send_event('graph', points: points, current: nowNumber, last: lastNumber )
If you print this out you will get something like this:
{:points=>[{:x=>6, :y=>64}, {:x=>5, :y=>62}, {:x=>4, :y=>56}], :current=>57, :last=>64}
Tweak your graph/graph.coffee file:
# The following 6 lines aren't needed for your solution, but if you wanted to take advantage of 'warning', 'danger', and 'ok' status classes (changes background color and flashes), just feed your send_event with 'status: [one of the three status names]
if data.status
# clear existing "status-*" classes
$(#get('node')).attr 'class', (i,c) ->
c.replace /\bstatus-\S+/g, ''
# add new class
$(#get('node')).addClass "status-#{data.status}"
#accessor 'difference', ->
if #get('last')
last = parseInt(#get('last'))
current = parseInt(#get('current'))
if last != 0
diff = Math.abs(Math.round((current - last) / last * 100))
"#{diff}%"
else
""
# Picks the direction of the arrow based on whether the current value is higher or lower than the last
#accessor 'arrow', ->
if #get('last')
if parseInt(#get('current')) > parseInt(#get('last')) then 'icon-arrow-up' else 'icon-arrow-down'

MIC-1 Simulation how to get started

Not sure how to start this..
For the given high-level code:
c = b - a;
a = a * 2;
complete the tasks:
create corresponding ijvm hexcode
store into appropriate cells
simulate the instructions
show changing contents of each data cell using "/", using the notation:
< old_value > / < new_value >
Start by writing the equivalent instructions in IJVM. If you are using Tannenbaum's book, there is a simple example for doing a calculation like one of these statements.
Since you have to update the contents of the registers in the data path, IJVM is not sufficient. If you only had to show the contents of the stack, the IJVM would suffice. Tannenbaum has an example of how the stack changes from IJVM instructions.
Once you have the IJVM, look up the opcodes in the instruction table and change operands into offsets from LV.
You will have to take the IJVM instructions and simulate them through MIC-1. Fill in the stack and registers with initial values. Show how the values change as you step through the code, using paper and pen.

Matlab: Understanding a piece of code

I have a matlab code which is for printing a cell array to excel. The size of matrix is 50x13.
The row 1 is the column names.
Column 1 is dates and rest columns are numbers.
The dateformat being defined in the code is:
dFormat = struct;
dFormat.Style = struct( 'NumberFormat', '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(#_)' );
dFormat.Font = struct( 'Size', 8 );
Can someone please explain me what the dFormat.Style code means ?
Thanks
The first line creates an empty struct (struct with no fields) called dFormat. A structure can contain pretty much anything in one of its fields, including another structure. The second line adds a field called 'Style' to the dFormat struct and sets it equal to another struct with a field called 'NumberFormat'. The 'NumberFormat' field is set equal to that long string of characters. You now have a structure of structures. The third line is similar to the second.
Note that the first line isn't really necessary unless dFormat already exists and it needs to be "zeroed out" as dFormat.Style with create it implicitly. However, using the struct function can make code more readable in some cases as objects use a similar notation for access methods and properties. In other words, all of your code could be replaced with:
dFormat.Style.NumberFormat = '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(#_)';
dFormat.Font.Size = 8;
See this video from the MathWorks for more details and this list of helpful structure functions and examples.
#horchler already elaborated on structs, but I imagine you may actually be more interested in the content of this structs Style field.
In case you are solely interested in _(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(#_), that does not really look like something MATLAB related to me.
My best guess is that this code is used to later feed some other program, for examle to build an excel file.