I'm scripting addons for After Effects, and I want to use the values stored in a user's preference file that determine the colours of UI elements. The values are stored in a plain txt file and look like this when I view it in Notepad++
["Label Preference Color Section 5"]
"Label Color ID 2 # 1" = FFFF"33"
"Label Color ID 2 # 2" = FFE4D8"L"
"Label Color ID 2 # 3" = FFA9CBC7
"Label Color ID 2 # 4" = FFE5BCC9
"Label Color ID 2 # 5" = FFA9A9CA
"Label Color ID 2 # 6" = FFA896"w"
"Label Color ID 2 # 7" = FFFFFFFF …
If I go through the UI and look at the decoded values for those colours I get this:
# pref decoded value
_____________________
#1 FFFF"33" → FF3333
#2 FFE4D8"L" → E4D84C
#3 FFA9CBC7 → A9CBC7
#4 FFE5BCC9 → E5BCC9
#5 FFA9A9CA → A9A9CA
#6 FFA896"w" → A89677
#7 FFFFFFFF → FFFFFF
So it's this close to ASCII encoded hex, but not quite.
EDIT
The quotes seem to contain values encoded as a hex string. I tried some other values to see how they were encoded, for example 345678 gets encoded as "4vx", which if you strip the quotes is the hex encoding of 345678, according to dencode
Could it be 7-bit ASCII? The program has been around for decades, and there's a lot of stuff that has been made backward compatible. If so, how do I decode it in JS?
Related
I'm trying to write a HTML parser in Lua. A major roadblock I hit almost immediately was I have no idea how to get a list of strings between 2 strings. This is important for parsing HTML, where a tag is defined by being within 2 characters (or strings of length 1), namely '<' and '>'. I am aware of this answer, but it only gets the first occurence, not all instances of a string between the 2 given strings.
What I mean by "list of strings between 2 strings" is something like this:
someFunc("<a b c> <c b a> a </c b a> </a b c>", "<", ">")
Returns:
{"a b c", "c b a", "/c b a", "/a b c"}
This does not have to parse newlines nor text in between tags, as both of those can be handled using extra logic. However, I would prefer it if it did parse newlines, so I can run the code once for the whole string returned by the first GET request.
Note: This is a experiment project to see if this is possible in the very limited Lua environment provided by the CC: Tweaked mod for Minecraft. Documentation here: https://tweaked.cc/
You can do simply:
local list = {}
local html = [[bla]]
for innerTag in html:gmatch("<(.-)>") do
list[#list] = innerTag
end
But be aware that it is weak as doesn't validade wrong things, as someone can put an < or > inside a string etc.
I am trying to create a plot in gnuplot with dots over the symbol theta in legend.
I am looking to do something similar to, \dot{\theta} and \ddot{\theta} from latex. However, most posts ask to use 'set term latex' or 'set term epslatex' which outputs a .tex file. I need to keep the output as a pdf with the dot and double dot over the theta in the legend. Is this possible? Appreciate any help. Thanks!
In place of 'Pitch rate', I need the symbol theta with a dot above it.
In place of 'Pitch acceleration', I need the symbol theta with two dots above it.
set term pdf
set termopt enhanced
set encoding utf8
set output "rampfuncs.pdf"
set style func linespoints
set xlabel 'time'
set format y "%.2f"
plot "output.dat" using 1:2 title '{/Symbol q} - Pitch angle', \
"output.dat" using 1:3 title 'Pitch rate', \
"output.dat" using 1:4 title 'Pitch acceleration'
set term x11
Update after answer from meuh: Image for reference
Second update after comments from meuh: Image 2
This is described in the section Enhanced text mode of the gnuplot guide. You can use the ~ tilde character to overprint two items, for example ~a/ will overprint a and /. In your case you need to raise the dot character by 1.1 times the font size (found empirically) in order for it to appear above the a so you prefix the character with this number, and enclose it in braces to make it one item: ~a{1.1.}
plot "data" using 1:2 title '{/Symbol q} angle', \
"data" using 1:3 title '~{/Symbol q}{1.1.} rate', \
"data" using 1:4 title '~{/Symbol q}{1.1..} accel'
which gives this result:
There seems to be a bug where the title will not be shown correctly if the ~{}{} construct is at the end of the title. The simple workaround is to add an extra space at the end of the title ~{}{} .
I'm tasked with creating a Caesar cipher for a project I am working on. A Caesar cipher takes each letter in a string of text and replaces it with a letter a fixed number of places away from it (dictated by the cipher key). For instance if my text is "cat" and my cipher key is 3, my new word would be "fdw" (I'm assuming positive numbers move the letters to the right). I've been able to get my code to solve correctly for most strings of text, but I am finding that if my string includes > ? or # it will not work. Their ASCii codes are 62,63 and 64 if that helps. Any input is appreciated!
def caesar_cipher(str, num)
strArray = str.split('')
cipherArray = strArray.collect do |letter|
letter = letter.ord
if (65...90).include?(letter + num) || (97...122).include?(letter + num)
letter = letter + num
elsif (91...96).include?(letter + num) || (123...148).include?(letter + num)
letter = (letter - 26) + num
else
letter
end
end
cipherArray = cipherArray.collect {|x| x.chr}
cipher = cipherArray.join('')
end
caesar_cipher("Am I ill-prepared for this challenge?", 3)
#ord 62-64 DON'T work >, ?, #
You should create an alphabet variable, just think in if you use both ends then you will have 2 problems: negative numbers and an ASCii number that doesn't exist. You can handle this with module operator % or with a single subtraction.
alphabet = "abcde"
text_to_cipher= "aaee" => 0044 #number based in his position at aphabet var
key = 3
result will be 3377 => dd¡? or any other symbol since 7 is out of the string length "abcde" same happens with ASCii at its ends.
With module operator, you can restrict that.
size_of_your_alphabet = 5 # For this case
7%size_of_your_alphabet = 2
The Ruby builtin tr is ideal to implement substitution ciphers.
Step 1: assemble the characters you wish to transform.
chars = ["A".."Z", "a".."z", ">".."#"].flat_map(&:to_a)
Step 2: create a 1:1 array of the transformed characters
transformed = chars.map{|c| (c.ord + 3).chr}
Step 3: apply tr to transform the string.
str.tr(chars.join, transformed.join)
Full working example:
def caesar_cipher(str, num)
chars = ["A".."Z", "a".."z", ">".."#"].flat_map(&:to_a)
transformed = chars.map{|c| (c.ord + num).chr}
str.tr(chars.join, transformed.join)
end
Output:
> caesar_cipher("Am I ill-prepared for this challenge?", 3)
#=> "Dq L mpp-tvitevih jsv xlmw gleppirkiC"
Notes:
Most substitution ciphers actually rely on letter rotation, not ASCII values. My inital assumption was that you wanted a rotation, e.g. ("a".."z").to_a.rotate(num). See prior edit for a working example of that.
You can use ranges in tr() to create a really simple Caesar cipher: str.tr('A-Za-z','B-ZAb-za')
Edit: Also, because of the range specification feature, the \ is an escape character so that you can use literals like -. See this SO answer for details. I think the above exhibits a bug due to this, because it contains a \ which should be escaped by another \.
I try to search for string in Pcap file captured by Wireshark tool. All string from/to sql server is formatted as Unicode String (UTF-16).
When the frame contains a Unicode string like "select", it is displayed as "s e l e c t", the space between characters is the null character \x00.
In case of using the following display filter:
frame contains "s e l e c t"
frames are not filtered.
so, I have to convert the string "select" to hex decimal manually, and run the display filter:
frame contains 73:00:65:00:6c:00:65:00:63:00:74:00
and it's working.
Also, I tried to use the find tool (in the tool bar) and picked Wide (UTF-16) and entered "s e l e c t", but it couldn't find the string.
I use WireShark v 2.2.0
sample of data
Is there a simple way to filter for Unicode string direct instead of converting string to hex string.
What I should enter in the find tool when picking the textbox Wide (UTF-16) to search for the ASCII string e.g. "select" but as a Unicode string
Q.Is there a simple way to filter for Unicode string direct instead of converting string to hex string
The "matches" operator, allows a filter to apply to a Perl-compatible regular expression (PCRE).
For the word "select", the display filter will be:
frame matches "s.e.l.e.c.t"
The dot here represent any character, in our case it's \x00 character
for case-insensitive like Select , SELECT :
frame matches "(?i)s.e.l.e.c.t"
(?i) performs a case-insensitive pattern match.
Q. What I should enter in the find tool when picking the textbox Wide (UTF-16) to search for the ASCII string e.g. "select" but as a Unicode string
Click the "find tool" from the tool bar, in dropdown list select the following:
Pick "Packet bytes" => pick "Narrow & Wide" => pick "String"
Enter the word to search for e.g. "select" in the textbox.
If the word exist, you find the frame data in "Pack Bytes" area
I've hit a problem during parsing of a CSV file where I get the following error:
CSV::MalformedCSVError: Illegal quoting on line 3.
RAILS code in question:
csv = CSV.read(args.local_file_path, col_sep: "\t", headers: true)
Line 3 in the CSV file is:
A-067067 VO VIA CE 0 8 8 SWCH Ter 4, Loc Is Here, Mne, Per Fl Auia/Sey IMAC NEK_HW 2011-03-09 09:47:44 2011-03-09 11:50:26 2011-01-13 10:49:17 2011-02-14 14:02:43 2011-02-14 14:02:44 0 0 771 771 46273 "[O/H 15/02] B270 W31 ""TEXT TEXT 2 X TEXT SWITC" SOME_TEXT SOME_TEXT N/A Name Here RESOLVED_CLOSED RESOLVED_CLOSED
UPDATE: Tabs don't appear to have come across above. See pastebin RAW TEXT: http://pastebin.com/4gj7iUpP
I've read numerous threads all over StackOverflow and Google about why this is and I understand that. But the CSV row above has perfectly legal quoting does it not?
The CSV is tab delimited and there is only a tab followed by the quote on either side of the column in question. There is 1 quote in that field and it is double quoted to escape it. So what gives? I can't work it out. :(
Assuming I've got something wrong here, I'd like the solution to include a way to work around the issue as I don't have control over how the CSV is constructed.
This part of your CSV is at fault:
46273 "[O/H 15/02] B270 W31 ""TEXT TEXT 2 X TEXT SWITC" SOME_TEXT
At least one of these parts has a stray space:
46273 "
" SOME_TEXT
I'd guess that the "3" and the double are supposed to be separated by one or more tabs but there is a space before the quote. Or, there is a space after the quote on the other end when there are only supposed to be tabs between the closing quote and the "S".
CSV escapes double quotes by double them so this:
"[O/H 15/02] B270 W31 ""TEXT TEXT 2 X TEXT SWITC"
is supposed to be a single filed that contains an embedded quote:
[O/H 15/02] B270 W31 "TEXT TEXT 2 X TEXT SWITC
If you have a space before the first quote or after the last quote then, since your fields are tab delimited, you have an unescaped double quote inside a field and that's where your "illegal quoting" error comes from.
Try sending your CSV file through cat -t (which should represent tabs as ^I) to find where the stray space is.