Weird HyLang dot notation behavior - hy

Why does the following work:
(def session (sessionmaker))
(.configure session :bind engine)
...but (def session (.configure (sessionmaker) :bind engine)) causes my Hy application to throw a NoneType TypeError?

So (sessionmaker) makes a "session" object? Does the (.configure (sessionmaker) :bind engine) method call return that session object? Or is it just for a side effect? I suspect it's the latter and just returns None. You might be looking for the doto form, which lets you configure an object, but then returns it at the end. So the code would be
(def session (doto (sessionmaker) (.configure :bind engine)))
If you're familiar with Python, the $ hy --spy option in the REPL is very useful for understanding how Hy gets compiled.

Related

Can't set uid for operator Timestamps/Watermarks that doesn't exist

I am working on a project and have turned on the Flink option disableAutoGeneratedUIDs so as to make sure everything is given a proper uid. But I am getting an error when trying to run the job that says:
java.lang.IllegalStateException: Auto generated UIDs have been disabled but no UID or hash has been assigned to operator Timestamps/Watermarks
Now I ran into the error for the operators I made when they didn't have uid set (as expected), but this operator isn't one I made or named. So I assumed it is the code for creating the WatermarkStrategy the source functions are using, but I can't give a WatermarkStrategy a uid so that was a dead end.
I looked online and saw there was a bug a year ago that said Partition required a uid when it shouldn't have and am wondering if this is a similar case (http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/How-to-assign-a-UID-to-a-KeyedStream-td32052.html).
What can I try next?
Just figured it out. I think it was just an overlook.
So the code originally was just:
getSource().name(NAME).assignTimestampsAndWatermarks(getWatermarkStrategy())
.process(new CountOperation())
.name(COUNT_OPERATION_NAME);
In my first attempt I tried adding uid here:
getSource().name(NAME).assignTimestampsAndWatermarks(getWatermarkStrategy())
.uid("WatermarkUid")
.process(new CountOperation())
.name(COUNT_OPERATION_NAME);
Thinking that this would handle the whole "piece". Then when I first got errors saying "this count operation name doesn't have a uid" I moved the uid to after the .process:
getSource().name(NAME).assignTimestampsAndWatermarks(getWatermarkStrategy())
.process(new CountOperation())
.uid("WatermarkUid")
.name(COUNT_OPERATION_NAME);
Then that is when I saw the error saying operator Timestamps/Watermarks doesn't have a Uid. And I started looking for the operator named that in the code. But in my hazy "friday-brain" logic I somehow didn't figure out that the error was solved by the first uid because that is the default name for the assignTimestampsAndWatermarks (thank you #hourcos for the tip to look at the dashboard ui. Seeing the name in the operator block made everything click). So what solved it was just adding a uid like so:
getSource().name(NAME).assignTimestampsAndWatermarks(getWatermarkStrategy())
.uid("WatermarkUid")
.process(new CountOperation())
.uid("ToCountUid")
.name(COUNT_OPERATION_NAME);

Use token obtained using R package AzureAuth to Query data

I am using the following code to get an access token using AzureAuth package in R
library (AzureAuth)
AuthToken <- get_azure_token("120d688d-1518-4cf7-bd38-182f158850b6",tenant="72f988bf-86f1-41af-91ab-2d7cd011db47", app="1950a258-227b-4e31-a9cf-717495945fc2");
However, I don't see any examples on how to use the obtained AuthToken in query data from an API?
Appreciate any help!
Pls point out my mistake if I misunderstand your question.
=======================Update=======================
Yes, I found some documents and I followed the sample. And I found that, if I wanna to call graph api, I just need to 'install.packages("AzureGraph")', and with this package I can reach my goal. And if I need to use AzureR to do some other operations on azure, the ducoment above has offered an example to illustrate how to create a resource group and storage account in AzureRMR, and a registered app in AzureGraph.
===================================================
Getting started with httr
I use this code to get httr get request, and http post request is similar, look up the document above for more details:
a <- GET("https://graph.microsoft.com/v1.0/me", add_headers(Authorization = "Bearer <accesstoken>"))
I just figured out the syntax. I found it difficult on two counts
Syntax for POST command. There are lot of examples for GET command but not many on POST
Getting to access_token. However once I started using R Studio, I was able to inspect the object and find the right field. Here is the syntax that worked for me
res <- POST(EnvironmentFqdnUrl,add_headers(Authorization = paste("Bearer", AuthToken$credentials$access_token)), body = upload_file("body.json"), verbose())
print(res)

iOS Gmail API - Sample code to retrieve Gmail messages for a given label in Swift 4 / Xcode9

first question for me on stackoverflow.com so hopefully I am doing it correctly!
I currently have the following code (Xcode 9 / Swift 4) using the example provided in the Gmail API web site which works fine:
let query = GTLRGmailQuery_UsersMessagesList.query(withUserId: "me")
service.executeQuery(query,
delegate: self,
didFinish: #selector(displayResultWithTicket2(ticket:finishedWithObject:error:))
However instead of retrieving all emails for "me", I just want to retrieve the emails for a given label. Google has an example here in its API reference where one of the parameters can be a label but unfortunately I cannot find the equivalent Swift code. They "only" cover: Java, .Net, Php, Python and Javascript.
My question is about: how do you code this in Swift? The method above "GTLRGmailQuery_UsersMessagesList.query" only accepts a User Id.
Alternatively the example mentions the use of HTTP request and parameters (in particular "q"), can I use that in Swift and how?
Thanks!
Oh my, it was soooo simple! After the first line of code (let query...), you just need to call the properties of "query", e.g.
let query = GTLRGmailQuery_UsersMessagesList.query(withUserId: "me")
query.q = "is_unread"
service.executeQuery(query,
delegate: self,
didFinish: #selector(displayResultWithTicket2(ticket:finishedWithObject:error:))
Lots to learn for me! But hopefully that will be useful to someone!

What mail service errors can AppEngine produce?

I would like to control and embed my send() calls in a try/except, but I'm not sure of what errors it can produce.
Looking around the SDK, it seems like MailServiceError is the one, but not sure since I don't know how to test an error like that.
Can anyone confirm this?
Here are the exceptions that can be thrown by a call to send(): https://developers.google.com/appengine/docs/python/mail/exceptions
Here's an example of how you could catch these:
from google3.apphosting.api import mail
# other code to create 'message' here
try:
message.send()
except mail.InvalidSender, e:
# Do something special for an invalid sender error
pass
except mail.Error, e:
# This will catch all the other exceptions in the doc above.
pass

How do I get the values from the counter after I processed all the records with Google AppEngine MapReduce?

How do I get the values from the counter after I processed all the records with Google AppEngine MapReduce?
Or am I missing the use case for counters here?
Sample Code from http://code.google.com/p/appengine-mapreduce/wiki/UserGuidePython
How would I retrieve the value of counter counter1 when the mapreduce is done?
app.yaml
handlers:
- url: /mapreduce(/.*)?
script: mapreduce/main.py
login: admin
mapreduce/main.py
from mapreduce import operation as op
def process(entity):
yield op.counters.Increment("counter1")
mapreduce.yaml
mapreduce:
- name: <Some descriptive name for UI>
mapper:
input_reader: mapreduce.input_readers.DatastoreInputReader
handler: main.process
params:
- name: entity_kind
default: <your entity name, e.g. main.MyEntity>
OK. Since you're posting the code from the docs I'll assume you haven't tried to run a mapper yet. The results from the counter should show up on the admin page for the mapreduce session. There must be a way to access the values from within the mapper as well but I am not familiar enough with the Python version of the API to tell you how. I know it is doable in the Java side.

Resources