counter.cairo:7:1: Unexpected character "#" - cairo

The code starts with # as seen :
####################
# STORAGE VARIABLES
####################
#storage_var
func counter() -> (count : felt):
end
I run : starknet-compile ../counter.cairo --output counter_compiled.json --abi counter_abi.json
and the result is:
counter.cairo:7:1: Unexpected character "#"
Why this problem arises ? Is it about the cairo version ?

Related

How to find specific string, with certain starting and ending character in Powershell

how to find all the strings which starts with open square bracket and ends with close square bracket in text file.
used below code but getting some unwanted contents also. How to avoid those unwanted contents
Select-String -Path "text.txt" -Pattern '\['
input file:
some conents [hello]
adfhjadf adfjkkf [ghad]
[check] dfgsf sfgfs
required output file
[hello]
[ghad]
[check]
Here, try this:
$string = #'
some conents [hello]
adfhjadf adfjkkf [ghad]
[check] dfgsf sfgfs
'#
([regex]'\[.*?\]').Matches($string)
Note, this will match anything inside the brackets. If you're looking only for English characters you should refine the regex.
Output should look like this:
Groups : {0}
Success : True
Name : 0
Captures : {0}
Index : 13
Length : 7
Value : [hello]
Groups : {0}
Success : True
Name : 0
Captures : {0}
Index : 39
Length : 6
Value : [ghad]
Groups : {0}
Success : True
Name : 0
Captures : {0}
Index : 47
Length : 7
Value : [check]
If you just want to see the matches you can do:
PS /> ([regex]'\[.*?\]').Matches($string).Value
[hello]
[ghad]
[check]

Odd school assignment, about displaying emojis in powershell

I've had the pleasure to get the assignment of posting emojis in Powershell, the only problem is they have to be on the same line, and there are three. This is, my first assignment, and we have no prior teaching in this subject so after googling and searching YouTube, my best shot was this below, however, it came with some error saying something about either too high value, or too low value.
Full error text: Exception calling "ToInt32" with "2" argument (s): "The value was either too large or too small to a UInt32. "
At C: \ Users \ EG \ Downloads \ Herningsholm \ Powershell H1 \ Hardware Information.ps1: 3 char: 5
$ UnicodeInt = [System.Convert] :: toInt32 ($ StrippedUnicode, 16)
CategoryInfo: NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId: OverflowException
$FullUnicode = ('U+1F60E') + ('U+1F436') + ('U+1F642')
$StrippedUnicode = $FullUnicode -replace 'U\+',''
$UnicodeInt = [System.Convert]::toInt32($StrippedUnicode,16)
[System.Char]::ConvertFromUtf32($UnicodeInt)
Try this out:
Full emoji list > here
# saves unicode for each emoji https://unicode.org/emoji/charts/full-emoji-list.html
$FullUnicode0 = 'U+1F606'
$FullUnicode1 = 'U+1F605'
$FullUnicode2 = 'U+1F605'
# removes the U+ bit
$StrippedUnicode0 = $FullUnicode0 -replace 'U\+',''
$StrippedUnicode1 = $FullUnicode1 -replace 'U\+',''
$StrippedUnicode2 = $FullUnicode2 -replace 'U\+',''
# Converts the value of the specified object to a 32-bit signed integer
$UnicodeInt0 = [System.Convert]::toInt32($StrippedUnicode0,16)
$UnicodeInt1 = [System.Convert]::toInt32($StrippedUnicode1,16)
$UnicodeInt2 = [System.Convert]::toInt32($StrippedUnicode2,16)
# Converts the specified Unicode code point into a UTF-16 encoded string so that you have an emoji
$Emoji0 = [System.Char]::ConvertFromUtf32($UnicodeInt0)
$Emoji1 = [System.Char]::ConvertFromUtf32($UnicodeInt1)
$Emoji2 = [System.Char]::ConvertFromUtf32($UnicodeInt2)
write-host "$($Emoji0), $($Emoji1), $($Emoji2)"

Drools rule issue after migrating to 6.x from 5.3

I am getting issue in below rule. This is working fine in 5.3 but throwing error (must be boolean expression).
String drl="import com.drools.Applicant;"
+ "rule \"Is of valid age\" "
+ " when $a : Applicant(age > 18 && name matches \"(?i).*\"+ name + \"(.|\n|\r)*\")"
+ " then $a.setValid( true ); "
+ " System.out.println(\"validation: \" + $a.isValid());\n"+
"end";
Issue is with line :
" when $a : Applicant(age > 18 && name matches \"(?i).\"+ name + \"(.|\n|\r)\")"
Any advise.
The expression isn't correct since name cannot be resolved as part of an experssion. Use a binding.
$a : Applicant($n: name, age > 18, name matches \"(?i).*\"+ $name + \"(.|\n|\r)*\")"
(I don't think the the constraint makes much sense - it's merely a test whether a name matches itself, with or without arbitrary characters before and after. Moreover, the ?i is superfluous.)

Adding a single space between each consecutive separators with SED

This looked easy but it's messing with my head.
Convert this
"value:::text:::::othervalue:::::::text"
to this
"value: : :text: : : : :othervalue: : : : : : :text"
SED isn't recursive, so I get this:
$ echo "value:::text:::::othervalue:::::::text" | sed 's/::/: :/g'
> value: ::text: :: ::othervalue: :: :: ::text
Workaround, sed twice
$ echo "value:::text:::::othervalue:::::::text" | sed 's/::/: :/g;s/::/: :/g'
> value: : :text: : : : :othervalue: : : : : : :text
This doesn't look elegant, and it's not intuitive. Is there any command (in sed maybe?) that might do this more cleanly?
Thanks!
Note: I'm looking for readability.
With GNU sed:
echo '"value:::text:::::othervalue:::::::text"' | sed ':a;s/::/: :/g;ta'
Output:
"value: : :text: : : : :othervalue: : : : : : :text"
From sed man page:
t label: If a s/// has done a successful substitution since the last input line was read and since the last t or T command, then branch to label; if label is omitted, branch to end of script.
: label: Label for b and t commands.

Advanced Command-Line Replace Command In VBScript

I'm writing a compiler for my won computer language. Now before the language can be compiled i actually need to replace all apostrophes (') with percents (%) via a command-line vbs program. But the apostrophes only need to be replaced if there is NOT a circumflex accent (^) in front of it. So for example, in this code:
color 0a
input twelve = 0a "hi! that^'s great! "
execute :testfornum 'twelve'
exit
:testfornum
if numeric('1) (
return
) ELSE (
print 0a "oops 'twelve' should be numeric"
)
return
the apostrophe at line 2 should not be replaced, but the ones at line 3, 6 and 9 should be.
can anyone help me?
this is what i have so far:
'syntax: (cscript) replace.vbs [filename] "StringToFind" "stringToReplace"
Option Explicit
Dim FileScriptingObject, file, strReplace, strReplacement, fileD, lastContainment, newContainment
file=Wscript.arguments(0)
strReplace=WScript.arguments(1)
strReplacement=WScript.arguments(2)
Set FileScriptingObject=CreateObject("Scripting.FileSystemObject")
if FileScriptingObject.FileExists(file) = false then
wscript.echo "File not found!"
wscript.Quit
end if
set fileD=fileScriptingobject.OpenTextFile(file,1)
lastContainment=fileD.ReadAll
newContainment=replace(lastContainment,strReplace,strReplacement,1,-1,0)
set fileD=fileScriptingobject.OpenTextFile(file,2)
fileD.Write newContainment
fileD.Close
As #Ansgar's solution fails for the special case of a leading ' (no non-^ before that), here is an approach that uses a replace function in a test script that makes further experiments easy:
Option Explicit
Function fpR(m, g1, g2, p, s)
If "" = g1 Then
fpR = "%"
Else
fpR = m
End If
End Function
Function qq(s)
qq = """" & s & """"
End Function
Dim rE : Set rE = New RegExp
rE.Global = True
rE.Pattern = "(\^)?(')"
Dim rA : Set rA = New RegExp
rA.Global = True
rA.Pattern = "([^^])'"
'rA.Pattern = "([^^])?'"
Dim s
For Each s In Split(" 'a^'b' a'b'^'c nix a^''b")
WScript.Echo qq(s), "==>", qq(rE.Replace(s, GetRef("fpR"))), "==>", qq(rA.Replace(s, "$1%"))
Next
output:
cscript 25221565.vbs
"" ==> "" ==> ""
"'a^'b'" ==> "%a^'b%" ==> "'a^'b%" <=== oops
"a'b'^'c" ==> "a%b%^'c" ==> "a%b%^'c"
"nix" ==> "nix" ==> "nix"
"a^''b" ==> "a^'%b" ==> "a^'%b"
You can't do this with a normal string replacement. A regular expression would work, though:
...
Set re = New RegExp
re.Pattern = "(^|[^^])'"
re.Global = True
newContainment = re.Replace(lastContainment, "$1%")
...