JSON and bencode
1 pointsby gwu781 comments
A 4
B 5
B 8
C 9
A 6
How to solve with only a dict? 3| 1742563279
using q)\ts d:(!/)(" II";"\t")0:`:1gram
q)\ts 1#desc sum each group d
1897 134218176
371 238872864
or k)\ts d:(!/)(" II";"\t")0:`:1gram
k)\ts desc:{$[99h=@x;(!x)[i]!r i:>r:. x;0h>@x;'`rank;x@>x]}
k)\ts 1#desc (sum'=:d)
1897 134218176
0 3152
372 238872864
No doubt I must be doing some things wrong. k)`t insert+:`k`v!("CI";"\t")0:`:tsvfile
k)f:{select (*:k),(sum v) from t where k=x}
k)a:f["A"]
k)b:f["B"]
k)c:f["C"]
k)select k from a,b,c where v=(max v) curl -o 1.htm https://www.google.com/search?q=xyz
yyg < 1.htm > 2.htm
your-ad-supported-web-browser 2.htm
To compile this I use something like flex -Crfa -8 -i g.l;
cc -Wall -pipe lex.yy.c -static -o yyg;
Save text below as file g.l
Then compile as above. %%
[^\12\40-\176]
\/url[?]q=
"http://www.google.com/gwt\/x?hl=en&u="
"&"[^\"]*
%%
main(){yylex();}
yywrap(){}
As for amp, I read that it needs to use iframes (and Javascript). Yikes. We can easily write a program to strip out iframe targets as well as links to Javascript. fetch -4o yc.htm https://news.ycombinator.com
yc < yc.htm
To compile this I use something like flex -Crfa -8 -i yc.l;
cc -Wall -pipe lex.yy.c -static -o yc;
Save the text below as yc.l then compile as above. #define jmp BEGIN
#define p printf
#define x yytext
%s aa bb cc dd ee ff gg hh
%s ii jj kk ll mm nn oo
aa "span class=\"rank\""
bb "a href=\""
cc score_........
dd \>
/* #include <time.h> */
/* #include <util.h> */
%%
[^\12\40-\176]
, p("%2c");
/* rank (dont care) */
{aa} jmp aa;
/* <aa>[1-9][^<\.]* p("\n%s,",x);jmp bb; */
<aa>[1-9][^<\.]* p("\n");jmp bb;
/* url */
<bb>{bb} jmp cc;
<cc>http[^"]* p("%s,",x);jmp dd;
/* title */
<dd>{dd} jmp ee;
/* <ee>[^><]* p("%s,",x);jmp ff; */
<ee>[^><]* p("%s",x);jmp ff;
/* host (omit) */
/* points (dont care) */
<ff>{cc} jmp gg;
<gg>{dd} jmp hh;
/* <hh>[1-9][^<> p]* p("%s,",x);jmp ii; */
<hh>[1-9][^<> p]* p(",");jmp ii;
/* user */
<ii>{bb} jmp jj;
<jj>http[^"]* p("%s,",x);jmp kk;
/* time (dont care) */
<kk>{bb} jmp ll;
/* <ll>http[^"]* ; */
<ll>http[^"]* jmp mm;
/* unix time (dont care) */
/* <ll>[1-9][^<]* {
time_t t0; time_t t1; time_t t2;
t1=time(&t0);
t2=parsedate(x,&t1,0);
p("%d,",t2);
jmp mm;
} */
/* item */
<mm>{bb} jmp nn;
/* <nn>http[^"]* p("%s,",x);jmp oo; */
<nn>http[^"]* p("%s",x);jmp oo;
/* comments (dont care) */
<oo>{dd} jmp oo;
/* <oo>[1-9d][^ <]* p("%s",x);jmp 0; */
<oo>[1-9d][^ <]* jmp 0;
.
\n
%%
main(){ yylex();}
yywrap(){ p("\n");} test $# = 1 ||exec echo usage: $0 section
curl -o 1.json https://static01.nyt.com/services/json/sectionfronts/$1/index.jsonp
exec sed '/\"guid\" :/!d;s/\",//;s/.*\"//' 1.json
I guess SpiderBytes could be used for older articles? * routine stolen from gimpel
* algorithm from peck and schrack
define('p(s)t,n,c,k','p_init') :(p_end)
p_init n = size(s)
r = array('2:' n, 0)
&alphabet len(n) . y
x = array('2:' n, y)
k = n + 1
p_0 k = k - 1
x[k] len(1) . s1 tab(k) . s2 = s2 s1 :s(p_0)
define('p(s)i,k')
p = s :(return)
p k = size(s)
p_1 s = replace(x[k],y,s) :f(p_2)
r[k] = r[k] + 1
k = eq(remdr(r[k], k),0) k - 1 :s(p_1)
p = s :(return)
p_2 define('p(s)t,n,s1,s2','p_init') :(freturn)
p_end
* example: all permutations of string abcdefgh
s = 'abcdefgh'
abc output = p(s) :s(abc)f(end)
end
Here is another solution that only returns the unique permutations. The items of the set must first be sorted or grouped, e.g, a string like "cabcd" could be given as "ccabd", "adbcc", "abccd", etc. Duplicate items must be adjacent. define('r(s,ors)c,f,s1,a,d,os')
:(r_end)
r ors rtab(1) len(1) . c :f(freturn)
s (span(c) | null) . f =
s arb . s1 len(1) . d c = :f(r_1)
r = s1 f c d s :(return)
r_1 ors break(c) . os
r = r(s,os) f :s(return)f(freturn)
r_end
s = 'abcdefgh'
output = s
x01 output = r(output,s) :s(x01)
end grep pattern1 | grep -v pattern2
can be replaced by sed -n '/pattern1/d;/pattern2/p'
or at least sed '/pattern1/!d' | sed '/pattern2/d'
or sed -n 's/pattern1pattern2//g;/pattern2/p'
But I must be missing something obvious. sed '/^op:livefloat80:/d'
Moreover, in the last line, why not use sed 's/\$/#/g'
instead of tr '$' '#'
Apologies if I am missing the obvious. old_pids=$(ps -A -opid,args | grep haproxy | egrep -v -e 'grep|reload-haproxy' | awk '{print $1}' | tr '\n' ' ')
Can we do this without grep, egrep and awk?
Would this work? old_pids=$(exec ps -A -opid,args |sed -n '/sed/d;/reload-haproxy/d;/haproxy/{s/ .*//;p};'|tr '\n' ' ') var a = 0;
start
+a = a + 1;
break
+lt(a,101) :f(end);
x01
+x = (remdr(a,3) + remdr(a,5)); eq(x,0) :s(x06);
x02
+y = remdr(a,3); eq(y,0) :s(x04);
x03
+z = remdr(a,5); eq(z,0) :s(x05)f(x07);
x04
+output = 'fizz' :(start);
x05
+output = 'buzz' :(start);
x06
+output = 'fizzbuzz' :(start);
x07
+output = a :(start);
end
More: http://www.hakank.org/setl/fizzbuzz.setl