HashBuiltin - Cairo - starknet

I am having this contract.cairo:3:59: Unknown identifier 'HashBuiltin'
after doing :
starknet-compile contract.cairo
--output contract_compiled.json
--abi contract_abi.json
code :
#external
func increase_balance{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
amount : felt):
let (res) = balance.read()
balance.write(res + amount)
return ()
end
# Returns the current balance.
#view
func get_balance{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}() -> (
res : felt):
let (res) = balance.read()
return (res=res)
end
Any explanation ?

I forgot to add
from starkware.cairo.common.cairo_builtins import HashBuiltin

You have to add this line to import it from Cairo libraries.
from starkware.cairo.common.cairo_builtins import HashBuiltin
That should do the trick.

Related

ZIO.fail not fail

I want learn methods refineXXX of zio library.
For this purpose I write simple code
import zio.ZIOAppDefault
import zio.Unsafe.unsafe
import zio._
import java.sql.SQLException
object Bot extends ZIOAppDefault {
val codeWithExc: ZIO[Any,Throwable,Int] =
ZIO.fail(new SQLException("message of SQL error."))
val MainApp: ZIO[Any, Throwable, Int] = for {
_ <- Console.printLine("Begin")
res <- codeWithExc
_ <- Console.printLine(s" res = $res")
} yield res
def run: URIO[ZIOAppArgs, ExitCode] =
for {
res <- MainApp.exitCode
} yield res
}
unsafe{ implicit u =>
Runtime.default.unsafe.run(Bot.run.provide(ZIOAppArgs.empty))
}
When I run it in IDEA worksheet I see output:
Begin
res0: zio.Exit[Nothing,zio.ExitCode] = Success(ExitCode(1))
and expect fail in res <- codeWithExc and death of the main fiber.
The problem here is that You are mapping ZIO to .exitCode which returns URIO that cannot really fail. Failure will be mapped to success and the only reason to tell that it did actually fail is to verify that ExitCode was not 0. If You change Your code and replace that with something like below, it will look work correctly:
def run = MainApp

Display file size in a directory

I am hoping to return and print a dictionary of the files and their file size, what I have written is this;
file_size = {}
for fn in glob.glob('*'):
with os.stat(fn) as f:
file_size[fn] = f.st_size
print (file_size)
But I am getting the AtributeError: enter
To use with statement you need to have the methods __enter__() and __exit__() in the object methods.
That is not the case for os.stat(). Remove the with statement and your problem will be fixed:
import glob, os
file_size = {}
for fn in glob.glob('*'):
f = os.stat(fn)
file_size[fn] = f.st_size
print (file_size)

How to get the string value of an HTTP header that I just set in Go?

I have the following mind-blowingly simple Go code.
package main
import (
"fmt"
"net/http"
)
func main() {
h := http.Header{
"my_id": []string{"XYZ"},
}
fmt.Println("h.Get(\"my_id\") = ", h.Get("my_id"))
}
But when I run it it doesn't work as expected, Here is the output:
h.Get("my_id") =
Why can't I print out the value of the header I just set?
Here is the live code for you to see yourself: https://play.golang.org/p/L45LzVqd341
Header.Get uses http.CanonicalHeaderKey to lookup keys. If you use h.Set or put My_id, it will work.
This is explained in Header.Get documentation.
Yeah the Headers are just a map[string][]string. So you can always get access to them by simply
if myID, ok := h["my_id"]; ok {
fmt.Println("myID", myID)
} else {
fmt.Println("my_id header not found")
}

Where is qtRunLoggedCommand defined?

I often see the calling of qtRunLoggedCommand in Qt project files but cannot find where it is defined. Can anybody provide a link to the document of this function or let me know where the function is defined in the source code? Thanks!
The function is defined in qtbase/mkspecs/features/configure_base.prf:
defineTest(qtRunLoggedCommand) {
qtLog("+ $$1")
!equals(3, false): \
1 = "( $$1 ) 2>&1"
output = $$system("$$1", lines, result)
lg =
for (l, output): \
lg += "> $$l"
qtLog($$lg)
!isEmpty(2) {
$$2 = $$output
export($$2)
}
!equals(result, 0): return(false)
return(true)
}

How to override delete-event in pygtk?

I am coding a simple text editor, so I am trying to check unsaved changes before closing the application. Now I know it has to be something with 'delete-event', and by googling around I have found a way, but it gives an error.
This is my code:
__gsignals__ = {
"delete-event" : "override"
}
def do_delete(self, widget, event):
print 'event overriden'
tabsNumber = self.handler.tabbar.get_n_pages()
#self.handler.tabbar.set_current_page(0)
for i in range(tabsNumber, 0):
doc = self.handler.tabbar.docs[i]
lines = self.handler.tabbar.lineNumbers[i]
self.handler.tabbar.close_tab(doc, lines)
# if self.handler.tabbar.get_n_pages() == 0:
# self.destroy_app()
def destroy_app(self):
gtk.main_quit()
And this is the error I get:
TypeError: Gtk.Widget.delete_event() argument 1 must be gtk.Widget, not gtk.gdk.Event
What is the right way to do it?
I found the answer,
self.connect('delete-event', self.on_delete_event)
and
__gsignals__ = {
"delete-event" : "override"
}
def on_delete_event(event, self, widget):
tabsNumber = self.handler.tabbar.get_n_pages()
#self.handler.tabbar.set_current_page(0)
for i in range(tabsNumber, 0):
doc = self.handler.tabbar.docs[i]
lines = self.handler.tabbar.lineNumbers[i]
self.handler.tabbar.close_tab(doc, lines)
self.hide()
self.destroy_app()
return True
The key is in return True. It prevents the default handler to take place and for somehow the error doesn't appear any more.

Resources