I have a python dictionary:
cupcakedictionary = {'flour' : '12',
'butter' : '4',
'sugar' : '14',
'egg' : '0.1'}
How would I write this in pseudo code?
any help appreciated.
Try and write it in simple, English terms.
01 (newDataBase) = Cupcake;
02 {
03 item1 (integer) "butter" = 4
04 item2 (integer) "sugar" = 14
05 item3 (float) "egg" = 0.1
06 }
Pseudo code is not a set language, it's what is used to state code in layman's terms, following a high-level language programming structure.
Related
Good day,
Hoping for the kind help of anyone here, thanks in advance.
I have T.csh which looks like this:
#! /bin/csh
set a="01 02 03 04 05 06 07 08 09 10 11 12 13"
set b="14 15 16 17 18 19 20 21 22 23 24 25"
set c="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25"
set X = `grep $1 EOL.txt | head -n1 | cut -d- -f1`
printf "$X\n$2\n$3\nYYYY\n1\nN\n"
The variables a,b and c are optionally used as the 3rd argument in the printf line. The problem is, whenever I try to run the script, it showed undefined variable. These set command lines are working whenever I assigned them interactively, but inside the script, it seems to not work. Perhaps I need to initialize it but could not figure out how. Just new to this programming thing, I hope someone here can help me. Thanks a lot in advance.
Here are the sample execution and error for your reference:
CAT-46{bc2}40>set a="01 02 03 04 05 06 07 08 09 10 11 12 13"
CAT-46{bc2}41>./T.csh 4773 XXXX.XX "$a"
62
XXXX.XX
01 02 03 04 05 06 07 08 09 10 11 12 13
82869
1
N
CAT-46{bc2}42>unset a
CAT-46{bc2}43>./T.csh 4773 XXXX.XX "$a"
a: Undefined variable
CAT-46{bc2}44>
If i set the variables manually,it's OK, but when I called for it from the script, its flagging undefined variable error.
Mike
I post another answer because a comment is too short. Look at the following.
I have a script named /tmp/T.csh:
#!/bin/csh
set a="blah"
echo $a
My shell is bash; I type /tmp/T.csh: result is blah (csh executed the script).
Still in bash; I type unset a; /tmp/T.csh $a: result is the same.
Still in bash; I type . /tmp/T.csh: no result (bash executed the script).
I type csh; now I am in csh.
I type /tmp/T.csh: result is blah (of course).
I type /tmp/T.csh $a: "a: Undefined variable"
set a = something
/tmp/T.csh $a: blah
echo $a: something
unset a
echo $a: "a: Undefined variable"
I replicated all you did; hope this helps.
You get an error for what you wrote on the command line, not for the content of your script. Even a simple echo, as you can see here above, gives an error if you on the command line refer to a variable which does not exist.
prompt> unset a
prompt> ./T.csh 4773 XXXX.XX "$a"
The first command, "unset a", deletes the variable. In the second command you try to read the variable (on the command line!). That is why csh complains.
I'm trying to create custom SNMP-trap.
send(IP(dst="10.152.1.81", src="10.152.1.100")/UDP(sport=55555,
dport=3338)/SNMP(version=1 , community= 'test' ,
PDU=SNMPtrapv2(id=14452,
varbindlist=[SNMPvarbind(oid='1.3.6.1.2.1.1.3.0',value=6100)])))
In Wireshark:
...
Value (Integer32): 6100
...
In hex it looks:
02 02 17 d4
Where '02 02' is value type (Integer32).
But i need to change value type to
Value (Timeticks): 6100
Hex:
43 04 17 d4
Yes, i can change it using hex:
e=IP(dst="10.152.1.81", src="10.152.1.100")/UDP(sport=55555, dport=3338)/SNMP(version=1 , community= 'test' , PDU=SNMPtrapv2(id=14452, varbindlist=[SNMPvarbind(oid='1.3.6.1.2.1.1.3.0',value=6100)]))
>>> str(e)
"E\x00\x00E\x00\x01\x00\x00#\x11b\xc3\n\x98\x01d\n\x98\x01Q\xd9\x03\r\n\x001T\xf10'\x02\x01\x01\x04\x04test\xa7\x1c\x02\x028t\x02\x01\x00\x02\x01\x000\x100\x0e\x06\x08+\x06\x01\x02\x01\x01\x03\x00\x02\x02\x17\xd4"
>>> c = "E\x00\x00E\x00\x01\x00\x00#\x11b\xc3\n\x98\x01d\n\x98\x01Q\xd9\x03\r\n\x001T\xf10'\x02\x01\x01\x04\x04test\xa7\x1c\x02\x028t\x02\x01\x00\x02\x01\x000\x100\x0e\x06\x08+\x06\x01\x02\x01\x01\x03\x00\x43\x04\x17\xd4"
>>> send IP(c)
But this method is too difficult when i use 'large' traps.
Whether there is a another method to change this type, or where i can find all possible fields(maybe value_timeticks, value_oid, etc) for SNMPvarbind in Scapy?
Sorry for my google-english.
Thanks.
I think you could use the class ASN1_TIME_TICKS
it should look like this:
varbindlist=[SNMPvarbind(oid=ASN1_OID("1.3.6.1.2.1.1.3.0"),value=ASN1_TIME_TICKS(6100))]
http://fossies.org/dox/scapy-2.2.0/classscapy_1_1asn1_1_1asn1_1_1ASN1__TIME__TICKS.html
I have a problem (Octave):
lets say I have a = 1 2 3 4 5
and I want to add 'b' character to every element in a.. So that I get something like that: a = 1b 2b 3b 4b 5b
How do I do that?
Thanx
To be able to do that, a must be defined as a string of characters rather than an array of doubles. There may be a more elegant solution, but the following works:
a = num2str(1:5); % '1' is a(1), '2' is a(5), etc...
% a(2) to a(4) are white spaces
for k=2:4:18
a(k) = 'b';
end
I want to extract the numbers following client_id and id and pair up client_id and id in each line.
For example, for the following lines of log,
User(client_id:03)) results:[RelatedUser(id:204, weight:10),_RelatedUser(id:491,_weight:10),_RelatedUser(id:29, weight: 20)
User(client_id:04)) results:[RelatedUser(id:209, weight:10),_RelatedUser(id:301,_weight:10)
User(client_id:05)) results:[RelatedUser(id:20, weight: 10)
I want to output
03 204
03 491
03 29
04 209
04 301
05 20
I know I need to use sed or awk. But I do not know exactly how.
Thanks
This may work for you:
awk -F "[):,]" '{ for (i=2; i<=NF; i++) if ($i ~ /id/) print $2, $(i+1) }' file
Results:
03 204
03 491
03 29
04 209
04 301
05 20
Here's a awk script that works (I put it on multiple lines and made it a bit more verbose so you can see what's going on):
#!/bin/bash
awk 'BEGIN{FS="[\(\):,]"}
/client_id/ {
cid="no_client_id"
for (i=1; i<NF; i++) {
if ($i == "client_id") {
cid = $(i+1)
} else if ($i == "id") {
id = $(i+1);
print cid OFS id;
}
}
}' input_file_name
Output:
03 204
03 491
03 29
04 209
04 301
05 20
Explanation:
awk 'BEGIN{FS="[\(\):,]"}: invoke awk, use ( ) : and , as delimiters to separate your fields
/client_id/ {: Only do the following for the lines that contain client_id:
for (i=1; i<NF; i++) {: iterate through the fields on each line one field at a time
if ($i == "client_id") { cid = $(i+1) }: if the field we are currently on is client_id, then its value is the next field in order.
else if ($i == "id") { id = $(i+1); print cid OFS id;}: otherwise if the field we are currently on is id, then print the client_id : id pair onto stdout
input_file_name: supply the name of your input file as first argument to the awk script.
This might work for you (GNU sed):
sed -r '/.*(\(client_id:([0-9]+))[^(]*\(id:([0-9]+)/!d;s//\2 \3\n\1/;P;D' file
/.*(\(client_id:([0-9]+))[^(]*\(id:([0-9]+)/!d if the line doesn't have the intended strings delete it.
s//\2 \3\n\1/ re-arrange the line by copying the client_id and moving the first id ahead thus reducing the line for successive iterations.
P print upto the introduced newline.
D delete upto the introduced newline.
I would prefer awk for this, but if you were wondering how to do this with sed, here's one way that works with GNU sed.
parse.sed
/client_id/ {
:a
s/(client_id:([0-9]+))[^(]+\(id:([0-9]+)([^\n]+)(.*)/\1 \4\5\n\2 \3/
ta
s/^[^\n]+\n//
}
Run it like this:
sed -rf parse.sed infile
Or as a one-liner:
<infile sed '/client_id/ { :a; s/(client_id:([0-9]+))[^(]+\(id:([0-9]+)([^\n]+)(.*)/\1 \4\5\n\2 \3/; ta; s/^[^\n]+\n//; }'
Output:
03 204
03 491
03 29
04 209
04 301
05 20
Explanation:
The idea is to repeatedly match client_id:([0-9]+) and id:([0-9]+) pairs and put them at the end of pattern space. On each pass the id:([0-9]+) is removed.
The final replace removes left-overs from the loop.
I examined some MPEG-4 video headers and saw some byte arrays like below at the beginning:
00 00 01 B0 01 00 00 01 B5 89 13
I know 00 00 01 parts but what exactly B0 B1 and B5 89 13 parts mean? Actually, if I put this byte array infront of an MPEG-4 stream, it works fine.
But I don't know if those values works with different mpeg-4 stream sources ?
0x000001B0 -> Visual Object Sequence Start (VOSS) Code
0x000001B5 -> Visual Object Start (VOS) Code
You can find the complete MPEG-4 elementary video header details at "ISO/IEC 14496-2" documentation. Here are the details you asked for.
Visual Object Sequence Start (VOSS) Code
-> 4 bytes visual object sequence start code = long hex value of 0x000001B0
-> 8 bits profile/level indicator = 1 byte unsigned number
Visual Object Start (VOS) Code
-> 4 bytes visual object start code = long hex value of 0x000001B5
-> 1 bit has id marker flag = 1/4 nibble flag
_ID_Marker_Section_
-> 4 bits version id = 1 nibble unsigned value - only if marker is true
- version id types are ISO 14496-2 = 1
-> 3 bits visual object priority = 3/4 nibble unsigned value - only if marker is true
- priorities are 1 through to 7
-> 4 bits visual object type = 1 nibble unsigned value
- types are video = 1 ; still texture = 2 ; mesh = 3 ; face = 4
-> 1 bit video signal type = 1/4 nibble flag
- NOTE: if this is false Y has a sample range of 16 through to 235