Adding Custom Function to OpenCPU Store - opencpu

I am trying to figure out how to add a custom function to my OpenCPU store.
I understand that we have to create an object in R/tmp. After creating a store in /home/, Then we have to move that object from R/tmp to /home/store/ using:
PUT /home/[store name]/[object name]
It's easy to do with functions/packages already in R/pub, but when I try to do it with my own custom function, I get stuck.
I can create an R/tmp/[hashkey] object with my own custom function at this webpage, in the third form:
http://public.opencpu.org/userapps/opencpu/opencpu.demo/runcode/
Which returns:
{
"object" : "x0188b9b9ce",
"graphs" : [],
"files" : {}
}
So I move this to my store via
PUT /home/[store name]/new.function
with parameter: object = 'x0188b9b9ce'
and then I see:
[
"/R/user/[user name]/[store name]/new.function"
]
But when I:
POST /R/user/[user name]/[store name]/new.function/save
I get this response:
HTTP 400 Bad Request
Object: new.function not found in /R/user/[user name]/[store name]/
So what am I doing wrong?
And yes, I have replaced [user name] and [store name] with actual strings, I just wanted to keep it as straightforward as possible and clearly connected to the documentation.

This was a server side problem. Posting and using a custom function via the above will work. Thanks to Jeroen for making the needed changes to the host server firewall.

Related

Using the google ad manager api to delete a line item

I need some help with the google ad manager API. I am trying to delete a lineitem with the following:
from googleads import ad_manager
client = ad_manager.AdManagerClient.LoadFromStorage()
def test(id):
line_item_service = client.GetService('LineItemService',version='v202002')
line_item_name = str(id)
statement = (ad_manager.StatementBuilder(version='v202002').Where('OrderId = :OrderId').WithBindVariable('OrderId',app.config['AD_MANAGER']['ORDER_ID']))
response = line_item_service.performLineItemAction(line_item_service.DeleteLineItems(),statement.ToStatement())
My problem lies with DeleteLineItems() as I am not sure how to call it correctly. I am not able to find clear usage examples, hence my attempt above. Below are the docs I could find. The error of my current attempt is:
{success: false, error: "<class 'googleads.errors.GoogleAdsValueError'>", message: "Service DeleteLineItems not found"}
https://developers.google.com/ad-manager/api/reference/v202011/LineItemService.DeleteLineItems
https://developers.google.com/ad-manager/api/reference/v202011/LineItemService#performLineItemAction
So I finally found the answer.
The performLineItemAction takes in 2 parameters. The first one is the LineItemAction and the second is a Statement. I found the docs a little confusing because I thought the LineItemAction was a method of the LineItem object. It turns out that the first parameter is actually a dictionary.
line_item_service.performLineItemAction({'xsi_type':'ArchiveLineItems'},statement.ToStatement())
As a side note, once a line item is being delivered we cannot delete it. We can either pause it or archive it. In this case I've chosen to archive it. The different types of line item actions can be found here.
https://developers.google.com/ad-manager/api/reference/v202011/LineItemService#performLineItemAction

How to use kubebuilder's client.List method?

I'm working on a custom controller for a custom resource using kubebuilder (version 1.0.8). I have a scenario where I need to get a list of all the instances of my custom resource so I can sync up with an external database.
All the examples I've seen for kubernetes controllers use either client-go or just call the api server directly over http. However, kubebuilder has also given me this client.Client object to get and list resources. So I'm trying to use that.
After creating a client instance by using the passed in Manager instance (i.e. do mgr.GetClient()), I then tried to write some code to get the list of all the Environment resources I created.
func syncClusterWithDatabase(c client.Client, db *dynamodb.DynamoDB) {
// Sync environments
// Step 1 - read all the environments the cluster knows about
clusterEnvironments := &cdsv1alpha1.EnvironmentList{}
c.List(context.Background(), /* what do I put here? */, clusterEnvironments)
}
The example in the documentation for the List method shows:
c.List(context.Background, &result);
which doesn't even compile.
I saw a few method in the client package to limit the search to particular labels, or for a specific field with a specific value, but nothing to limit the result to a specific resource kind.
Is there a way to do this via the Client object? Should I do something else entirely?
So figured it out - the answer is to pass nil for the second parameter. The type of the output pointer determines which sort of resource it actually retrieves.
According to the latest documentation, the List method is defined as follows,
List(ctx context.Context, list ObjectList, opts ...ListOption) error
If the List method you are calling has the same definition as above, your code should compile. As it has variadic options to set the namespace and field match, the mandatory arguments are Context and objectList.
Ref: KubeBuilder Book

“Error no label add or removes specified” when trying to modify labels using Gmail's Ruby API

I've looked at https://www.rubydoc.info/github/google/google-api-ruby-client/Google/Apis/GmailV1/ModifyThreadRequest and the examples https://developers.google.com/gmail/api/v1/reference/users/labels/update for Python and JS but can't figure out how to format the request properly in ruby.
I'm trying:
service.modify_thread('me',thread_id,{'add_label_ids'=>['UNREAD']})
and various other permutations of the object but can't get anything other than Google::Apis::ClientError: invalidArgument: No label add or removes specified in response.
Any help appreciated
modify_thread expects a Google::Apis::GmailV1::ModifyThreadRequest object as third argument according to the documentation.
In the source of the constructor of ModifyThreadRequest you can see that it looks for a key :add_label_ids in its arguments.
So if modify_thread creates the ModifyThreadRequest object itself then
service.modify_thread('me',thread_id, add_label_ids: ['UNREAD'])
should work.
If that fails I would try
mtr = Google::Apis::GmailV1::ModifyThreadRequest.new(add_label_ids: ['UNREAD'])
service.modify_thread('me', thread_id, mtr)

Creating a simple, basic page object in Nightwatch.js

Ok, so I've read up on the use of page_objects in nightwatch.js, but I'm still getting issues with it (which I'm convinced is due to something obvious and/or simple).
Using http://nightwatchjs.org/guide/#page-objects as the guide, I added the the file cookieremoval.js in my page_objects folder.
module.exports = {
elements: {
removeCookies: {
selector: '.banner_continue--2NyXA'
}
}
}
In my nightwatch.conf.js file I have;
page_objects_path: "tests/functional/config/page_objects",
And in my test script I have;
module.exports = {
"/cars/road-tax redirects to /car-tax/ ": browser => {
browser.url(browser.launch_url + browser.globals.carReviews)
.assert.urlEquals(browser.launchUrl + "/car-reviews/")
.waitForElementPresent('#cookieRemove', 3000)
.click('#cookieRemove')
.end();
},
};
However, when I run the test, I keep getting an error reading;
Timed out while waiting for element <#cookieRemove>
Any ideas why this is not working?
Many thanks
First of all, you never instantiated your page object. You're asking the browser object to search for an unknown element, that's why it's timing out. Your code should look something like this in your test script: var cookieRemoval = browser.page.cookieremoval(); then use this object to access those variables and functions in your page object. For example, if you wanted to access the remove cookie element, then you would do this cookieRemoval.click('#removeCookies');.
Secondly, you will have to know when to use the global browser object and when to use your page object. If you need to access something within your page object, obviously use the page object to call a function or access a variable. Otherwise, browser won't know the element you're looking for exists. Hope this help you out, I would definitely spend some more time learning about objects and specifically how they're used in nightwatch.js.

AWS S3 API - Objects doesn't contains Metadata

trying to figure AWS S3 API and failing miserably...
I currently got a bucket which consist lots of videos.
I need to request all the videos as an object, that will have the video meta-data which I set once uploading, and the link to share the video.
Problem is I'm getting the object without any of the above...
What Iv'e got so far -
AWS.config.update({accessKeyId: 'id', secretAccessKey: 'key', region: 'eu-
west-1'});
var s3 = new AWS.S3();
var params = {
Bucket: 'Bucket-name',
Delimiter: '/',
Prefix: 'resource/folder-with-videos/'
}
s3.listObjects(params, function (err, data) {
if(err)throw err;
console.log(data);
});
Thanks for reading :)
UPDATE - found that when using getObject and adding ExposeHeader to the CORS setting I can indeed get the metadata I set.
problem is getObject only works on a specific Object (video in my case).
any Idea how I can get all the object like listObject and have values of each object like I do on getObject?
Only solution I can think of is doing listObject to get a list of all the objects, and then by this result to do for each object an getObject ajax?... rip UX
thanks :)
A couple of things to sort out first.
As per the documentation, http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#listObjects-property listObjects API returns exactly what is mentioned in the callback parameters. Using a delimiter causes the S3 to list objects only one level below the prefix given. It won't traverse all objects recursively.
In order to get the URL, you can use http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrl-property. I am not really sure what you meant by meta-data.

Resources