org-mode export drawers while parsing plain-lists (html) - org-mode

So I have a file where I am currently keeping a bunch of data in drawers (in this specific case, a pen and paper RPG character). I overwrote how drawers work so I could implement a toggle button to hide/show. This works fine, except it seems the content isn't being parsed how I think it should.
The main issue is it seems to not parse plain-lists. As such, how would I change the function so it parses plain-lists, without damaging the other output?
export drawer function:
(require 'org-publish)
(setq org-publish-project-alist
'(
("org-notes"
:base-directory "~/shared/"
:base-extension "org"
:publishing-directory "~/public_html/org/"
:recursive t
:drawers t
:creator-info nil
:publishing-function org-publish-org-to-html
:headline-levels 5 ; Just the default for this project.
:auto-preamble t
)
))
(defun my-org-export-format-drawer (name content)
(format
(concat "#<h6>"
(capitalize name)
"#<button class=\"dbut\" type=\"button\">toggle#</button>#</h6>"
"#<div class=\"drawer "
(downcase name)
"\">"
"%s #</div>")
content))
(setq org-export-format-drawer-function 'my-org-export-format-drawer)
Sample File with drawers:
#+DRAWERS: ABILITYSCORES FEATS
* Test
:ABILITYSCORES:
#+ATTR_HTML: :border 2 :rules all :frame border
| Stat | Value | Mod |
|------+-------+-----|
| Str | 18 | 4 |
| Dex | 10 | 0 |
| Con | 16 | 3 |
| Int | 12 | 1 |
| Wis | 14 | 2 |
| Cha | 10 | 0 |
*KOM:* Str; *KDM:* Con; *BAB:* 2
:END:
:FEATS:
- Cataphract :: Bonus, +2 to attack rolls, +2 to damage rolls with Power attack
ignore AC charge penalty (all while mounted)
- Mighty Smash :: 1, +2 damage, after being hit by three Mighty Smashes opponent
takes -1 to attack rolls for [Encounter], max -4.
:END:
js-fiddle of result

Related

altair bar chart for grouped data sorting NOT working

`Reservation_branch_code | ON_ACCOUNT | Rcount
:-------------------------------------------------:
0 1101 | 170 | 5484
1 1103 | 101 | 5111
2 1118 | 1 | 232
3 1121 | 0 | 27
4 1126 | 90 | 191`
would like to chart sorted by "Rcount" and x axis is "Reservation_branch_code"
this below code gives me chart without Sorting by Rcount
base =alt.Chart(df1).transform_fold(
['Rcount', 'ON_ACCOUNT'],
as_=['column', 'value']
)
bars = base.mark_bar().encode(
# x='Reservation_branch_code:N',
x='Reservation_branch_code:O',
y=alt.Y('value:Q', stack=None), # stack =None enables layered bar
color=alt.Color('column:N', scale=alt.Scale(range=["#f50520", "#bab6b7"])),
tooltip=alt.Tooltip(['ON_ACCOUNT','Rcount']),
#order=alt.Order('value:Q')
)
text = base.mark_text(
align='center',
color='black',
baseline='middle',
dx=0,dy=-8, # Nudges text to right so it doesn't appear on top of the bar
).encode(
x='Reservation_branch_code:N',
y='value:Q',
text=alt.Text('value:Q', format='.0f')
)
rule = alt.Chart(df1).mark_rule(color='blue').encode(
y='mean(Rcount):Q'
)
(bars+text+rule).properties(width=790,height=330)
i sorted data in dataframe...used in that df in altair chart
but not found X axis is not sorted by Rcount column........Thanks
You can pass a list with the sort order:
import altair as alt
from vega_datasets import data
source = data.barley()
alt.Chart(source).mark_bar().encode(
x='sum(yield):Q',
y=alt.Y('site:N', sort=source['site'].unique().tolist())
)

jedi:goto-definition overjumping the import section

I am using jedi:goto-definition to jump to function definitions.
If the function has a definiton under import it first jumps into that and I have to do second jump to the module again. Can it directly jump to the module by over passing the import jump?
Here: cursor is on top of my_function. When I do jedi:goto-definition it first jumps to my_function, under import at the top of the file. Than when I do jedi:goto-definition it jump to its definition.
from utils import ( |
my_function, <-----| --------------> | def my_function(arg):
_log | | ....
) | |
| |
my_function("hello") --| # cursor is here
wanted behavior:
my_function("hello") --| # cursor is here ----> | def my_function(arg):
setup:
(defun my/python-mode-hook ()
(add-to-list 'company-backends 'company-jedi))
(add-hook 'python-mode-hook 'my/python-mode-hook)
(company-jedi 1)
(setq elpy-rpc-backend "jedi")
(add-hook 'python-mode-hook 'jedi:setup)
(global-set-key "\C-x\C-j" 'jedi:goto-definition)
(global-set-key "\C-x\C-k" 'jedi:goto-definition-pop-marker)

How can I put fit 4 items into a RDF triple?

I have this table, representing the refugee population for each country in each year.
| Country | 2000 | 2001 | 2002 | 2003 |
|---------|-------|-------|-------|-------|
| USA | 56213 | 67216 | 67233 | 12367 |
| Chile | 26137 | 12345 | 23345 | 21312 |
How can I make it clear in the RDF triple that it's the population for the year? I can not find any existing vocabulary to reuse. My idea is to coin my own URI and then the local name to be year2000population and then the statement will be:
dbo:USA :year2000population 56213 ;
:year2001population 67216 .
But I'm not happy with this solution, it seems like it is wrong to me.
You can use a pattern for n-ary relationships, which basically means you introduce an anonymous individual for each row in your table, and add each property to the individual rather than force that in a single triple format.
See https://www.w3.org/TR/swbp-n-aryRelations/ for details of the pattern.
Here is a concrete example of reifying the property (ala n-ary relationships) using your data. The basic technique is to create an object represnting the data that belongs together, then refer to that with an object property, :popyear in the example:
:py2000USA :population 56213 ;
:year 2000 .
:py2001USA :population 67216 ;
:year 2001 .
:py2002USA :population 67233 ;
:year 2002 .
:py2003USA :population 12367 ;
:year 2003 .
dbo:USA :popyear :py2000USA ;
:popyear :py2001USA ;
:popyear :py2002USA ;
:popyear :py2003USA ;
:py2000Chile :population 26137 ;
:year 2000 .
:py2001Chile :population 12345 ;
:year 2001 .
:py2002Chile :population 23345 ;
:year 2002 .
:py2003Chile :population 21312 ;
:year 2003 .
dbo:Chile :popyear :py2000Chile ;
:popyear :py2001Chile ;
:popyear :py2002Chile ;
:popyear :py2003Chile ;

Junk output or random character in Data::Dumper output for Net::DNS::Resolver object

I am getting familiarized with the Net::DNS library in Perl and an object is created using
my $res = Net::DNS::Resolver->new();
However, simply trying to query a domain name shows a lot f junk values, though the output itself is correct. Here is the code snippet
#!/usr/bin/perl
use Net::DNS;
use Net::IP;
use Data::Dumper;
my $rr;
$domain = 'google.com';
my $res = Net::DNS::Resolver->new();
my $ns_req = $res->query($domain, "NS");
print "\n\n###\n".Dumper($ns_req)."\n###\n\n";
Here are 2 outputs for various domains tested against this object:
What are these junk values being displayed? Is there a way to clean up the output a bit in order to read the output properly?
You are dumping the internals of the object which include the buffer which holds the original response bytes.
You should use the API defined in the module documentation to access the information.
#!/usr/bin/env perl
use strict;
use warnings;
use Net::DNS;
my $resolver = Net::DNS::Resolver->new;
my $result = $resolver->query('google.com', "NS");
$result->print;
Output:
;; Answer received from x.x.x.x (100 bytes)
;; HEADER SECTION
;; id = 39595
;; qr = 1 aa = 0 tc = 0 rd = 1 opcode = QUERY
;; ra = 1 z = 0 ad = 0 cd = 0 rcode = NOERROR
;; qdcount = 1 ancount = 4 nscount = 0 arcount = 0
;; do = 0
;; QUESTION SECTION (1 record)
;; google.com. IN NS
;; ANSWER SECTION (4 records)
google.com. 21599 IN NS ns4.google.com.
google.com. 21599 IN NS ns2.google.com.
google.com. 21599 IN NS ns1.google.com.
google.com. 21599 IN NS ns3.google.com.
;; AUTHORITY SECTION (0 records)
;; ADDITIONAL SECTION (0 records)
The query method returns a Net::DNS::Packet which provides other methods to obtain specific parts of the response.
For example:
#!/usr/bin/env perl
use strict;
use warnings;
use Net::DNS;
my $resolver = Net::DNS::Resolver->new;
my $result = $resolver->query('google.com', "NS");
for my $answer ($result->answer) {
print $answer->nsdname, "\n";
}
Output:
ns2.google.com
ns1.google.com
ns3.google.com
ns4.google.com
If you are interested in the contents of the binary buffer, Net::DNS::Packet has a data method which returns the contents of that buffer. As RFC 1035 points out:
3.2. RR definitions
3.2.1. Format
All RRs have the same top level format shown below:
1 1 1 1 1 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| |
/ /
/ NAME /
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| TYPE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| CLASS |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| TTL |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| RDLENGTH |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
/ RDATA /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
NAME an owner name, i.e., the name of the node to which this
resource record pertains.
TYPE two octets containing one of the RR TYPE codes.
CLASS two octets containing one of the RR CLASS codes.
TTL a 32 bit signed integer that specifies the time interval
that the resource record may be cached before the source
of the information should again be consulted. Zero
values are interpreted to mean that the RR can only be
used for the transaction in progress, and should not be
cached. For example, SOA records are always distributed
with a zero TTL to prohibit caching. Zero values can
also be used for extremely volatile data.
RDLENGTH an unsigned 16 bit integer that specifies the length in
octets of the RDATA field.
RDATA a variable length string of octets that describes the
resource. The format of this information varies
according to the TYPE and CLASS of the resource record.
You can examine the contents of $result->data by doing a hexdump:
#!/usr/bin/env perl
use strict;
use warnings;
use Net::DNS;
my $resolver = Net::DNS::Resolver->new;
my $result = $resolver->query('google.com', "NS");
print $result->data;
C:\...\t> perl tt.pl | xxd
00000000: 3256 8180 0001 0004 0000 0000 0667 6f6f 2V...........goo
00000010: 676c 6503 636f 6d00 0002 0001 c00c 0002 gle.com.........
00000020: 0001 0000 545f 0006 036e 7333 c00c c00c ....T_...ns3....
00000030: 0002 0001 0000 545f 0006 036e 7334 c00c ......T_...ns4..
00000040: c00c 0002 0001 0000 545f 0006 036e 7332 ........T_...ns2
00000050: c00c c00c 0002 0001 0000 545f 0006 036e ..........T_...n
00000060: 7331 c00c s1..

What does the line ## -9,9 +9,10 ## mean in a diff file?

Can someone please explain the third line in the sample diff output below (i.e., the one that starts with ##)? I understand the changes represented by the remaining lines but am having trouble making sense of that third line...
--- a/code/c-skeleton/Makefile
+++ b/code/c-skeleton/Makefile
## -9,9 +9,10 ##
TEST_SRC=$(wildcard tests/*_tests.c)
TESTS=$(patsubst %.c,%,$(TEST_SRC))
## -9,9 +9,10 ##
...specifies where in the source and destination files changes take place, by line number and size of the chunk being edited, both before and after the changes.
Specifically:
## -9,9 +9,10 ##
^ ^^ ^ ^^ ^
| || | || \----- The "10" is the number of lines in the hunk after being
| || | || modified; this patch, then, must add a line, since the
| || | || new count (of 10) is longer than the old count (of 9).
| || | |\------- This "9" is the line number in the new file where the
| || | | modified hunk is placed.
| || | \-------- This "+" is a hint that the following numbers refer to
| || | the new file, after modification.
| || \---------- This "9" is the number of lines in the hunk before being
| || modified.
| |\------------ This "9" is the line number in the original file.
| \------------- This "-" is a hint that the following numbers refer to the
| original file.
\---------------- This "##" is a marker indicating that this is the start of a
new hunk.
That is to say: in the original file, the hunk being modified consists of 9 lines starting at line 9; in the destination file, it's 10 lines starting at line 9.
See the detailed description of unified diff format in the GNU diffutils documentation.