Dmitry Maslennikov · Dec 13, 2017 go to post

In HTTP/2 added some features which are impossible or maybe possible in Cache

  • Server Push - allows pushing some resource from server to client, at any time, in parallel 
  • Data compression for HTTP Headers. How it will be now when I will need to read headers in a request.

And other features which also important but mostly on TCP Stack, and maybe really not Cache part.

Dmitry Maslennikov · Dec 10, 2017 go to post

Looks like there is some error with autodetecting links in a post here, just fixed it with manually marking correctly as a link in his comment.

In the first implementation, I tried to actually build the tree. But missed something, and got some duplications in the lowest branches. Then using the same tree trying to solve second part, I found more than one unbalanced branches and a long time had not noticed how it could be until I noticed duplications. Then I removed this way, and first part becomes much simpler if just search node which does not have parents. In the second part, you actually already have a tree when you know when it started from the first part.

Looks like just some simple implementation for Long Pulling requests.

But how about getting not just a progress but how to get some data before task finished. 

And also, I see beg security Issue, when I can get information from any other process. You use TaskId directly from the request like you trust everybody. And also easy to get SUBSCRIPT error.

BTW: do you suppose to acept someone's answer? Looks like it is mostly just discissing topic.

Today's task was pretty difficult, it takes few hours to solve it. I made a mistake in first part even if I got the right answer, but after when I rewrote my first part, the second part was solved quite fast. But I lost so much time to figure it out.

For current process

USER>f fmt="enuw","rusw","current","" do ##class(%SYS.NLS.Format).%New(fmt) w !,fmt,?10,$zd($h,11),?15,$zd($h,12)
 
enuw      Wed  Wednesday
rusw      Сре  Среда
current   St   středa
          Wed  Wednesday

Or for all new processes, without restart

%SYS>write $zd($h,12)
Wednesday
%SYS>Set ^SYS("NLS","Config","LocaleFormat")=1
 
%SYS>write $zd($h,12)
Wednesday
%SYS>Do Locale^NLSLOAD("rusw")
 
%SYS>write $zd($h,12)
Среда

Looks like we in the same timezone, and you solve tasks faster than me. When your time today was 15:47 minutes for the first task. But on the main Leaderboard fastest time 2:58. I really don't understand how it would be possible, to solve it so fast.

anagram used all letters, so I just compared lengths of strings and used $tr() to remove all characters from string one in another.

So, your code I would change like 

ClassMethod IsAnagram(word,test) as %Boolean {

  if $L(word)'=$L(test) return 0

  return $tr(word,test)=""

}

Look at the documentation, there are some formats available to use in the $zdate function. Where 11 (abbreviated) and 12(full) looks like what you need.

write $zdate($h, 11)
Tue

Write $zdate($h, 12)
Tuesday

It would be better if you can add your SQL query, and if it is not a secret also Classes definition. So, we could see if something may be wrong with it. And you also should look at the book in the documentation about SQL Optimizations.

 set input="1212"
 set len=$l(input)/2
 set sum=0
i=1:1:len {
   if $e(input,i)=$e(input,len+i),$i(sum, i*2)
 }
 zw sum

I also started from $zstrip,  but in task 1111 should produce 1, when $zstrip returns only one 1.

for the second task, you should simply compare values from the first half of string with the same position from the second half. 

ClassMethod HelloWorld(Name As %String)
{
  set result = {
    "name": (Name)
  }
  quit result.%ToJSON()
}

Why do you use such a strange url? You created the application with your class as Dispatch class. So, in this case, you should call this.

http://localhost:57772/USER/REST/Arun

where /USER/REST is web application, and everything else is already what should be in a REST.

PS. I would not recommend do not use uppercase for web applications

You can use colon to achieve it

<Route Url="/checkUID/:uid/:supplierid/" Method="GET" Call="Some.Other.Class:checkUID"/>

With Map tag in UrlMap, you can simply split your big UrlMap by multiple classes

Dmitry Maslennikov · Nov 28, 2017 go to post

After all details, it means, that no reasons to use $lb, or any other ways, it should be as is as a string, but with this length's header.

In Cache, we don't have binary strings as do other languages, but what is a byte, it is a symbol for text, so text will be arrays of bytes.

write $c(166, 70, 114, 105, 110, 103, 101)
¦Fringe

The only thing you should care as already mentioned above is different codepages. 

Let's try for some example:

And try to get the same.

USER>set data="TestТест"
 
USER>zzdump data
 
0000: 0054 0065 0073 0074 0422 0435 0441 0442                 TestТест

USER>set msg=$zcvt(data,"O","UTF8") ; convert from Unicode
 
USER>set msg=$c(160+$l(msg))_msg    ; of course should be changed for bigger text
 
USER>zzdump msg
 
0000: AC 54 65 73 74 D0 A2 D0 B5 D1 81 D1 82                  ¬TestТеÑ.Ñ.

and as you can see we got the same result

Dmitry Maslennikov · Nov 27, 2017 go to post

What do you mean by overhead from $lb? 

What is $c(166), some magic number? And why you encode the string as a list of codes, why not keep it as a string?

$lb it is also a string, but compressed for some types of values.

Dmitry Maslennikov · Nov 23, 2017 go to post

I love Docker way. In Dev environment, when you need only some test data. You can use Docker, with all test data inside the image, just recreate container will clean all previous changes and return the database to state when this image was built. If you later will decide to keep some changes as default for next uses, you can commit this changes to the image.

Dmitry Maslennikov · Nov 12, 2017 go to post

Not sure, but maybe property method GetStored can help. It is ClassMethod which accept object Id as the first argument. Full name for the method <Property>GetStored(id)

Dmitry Maslennikov · Nov 12, 2017 go to post

I also solved this task, and I decided to choose a bit different way. As we have some kind of programming language, we can execute it, but how. We can transpile this code to Caché code, and execute it. 

  kill
  set fs = ##Class(%Stream.FileCharacter).%New()
  set sc=fs.LinkToFile("c:\advent\input\day12.txt")
  set src($i(src(0))) = "start(c) new (c)"
  while 'fs.AtEnd {
    set line = fs.ReadLine()
    set pos = $i(src(0))
    set code = $$transpile(line, pos, "start")
    set src(pos) = code
  }
  set src($i(src(0))) = " zwrite a"
  set src($i(src(0))) = " quit"
  set sc = $compile(src, 0, errs, , , , "AdventDay12New")
  do start^AdventDay12New()
  do start^AdventDay12New(1)
  quit
transpile(line, pos = 0, label) {
  set result = ""  
  set $lb(cmd, arg1, arg2) = $lfs(line," ")
  if cmd = "jnz" {
    if +arg1=arg1 set result = " goto:("_arg1_") "_label_"+"_(pos+arg2-1)
    else  set result = " goto:(+$get("_arg1_")) "_label_"+"_(pos+arg2-1)
  elseif $lf($lb("cpy", "inc", "dec"), cmd) {
    set args = $case(cmd, "cpy": $lb(arg2, arg1), "inc": $lb(arg1, arg1_" + 1"), : $lb(arg1, arg1_" - 1"))
    set result = " set "_$lts(args, " = ")
  }
  quit result
}

Spoiler. Task 25 have the same language with one more instruction. and with some little modifications in this code, becomes quite easy to solve that task, too.