Getting a URL with GtkClipboard - c

I'm trying to check if a url is on the system clipboard and if so get it from the clipboard. While reading the GTK API docs I came across gtk_clipboard_wait_for_uris but it seems to always return NULL:
g_print("%s", gtk_clipboard_wait_for_uris(gtk_clipboard_get(GDK_SELECTION_PRIMARY)));
What would be the correct/best way of getting a url from the clipboard?

wait_for_uris only works if the clipboard contains data tagged as a URI list (text/uri-list), e.g. when you perform a copy action in a file manager. It won't work as you expect if you copy a piece of text that just happens to contain a URI, e.g. "http://stackoverflow.com/". When you copy that string, it's most likely tagged as plaintext (text/plain).
The solution is to use wait_for_text and check whether it's a URI.

Related

How to get the URL of an attachment in a message

I'm trying to get the URL of any attachments in a message. I can't seem to find a way to do this: whenever I try to run console.log(message.attachments.url), it just outputs undefined. What am I doing wrong?
I've tried reading the docs and other Stack Overflow questions but nothing worked.
I expect the output to be a URL of the attachment, i.e. 'https://cdn.discordapp.com/attachments/serverid/channelid/file.png' However, it just outputs undefined.
message.attachments is a Collection (a Map with additional Utility functions) so you either have to get the specific attachment via message.attachments.get('ID') or if you are sure that the message only has one attachment you can use message.attachments.first(). Otherwise you have to iterate through the Collection via
message.attachments.forEach(attachment => {
// do something with the attachment
const url = attachment.url;
});
I linked to the Collection docs of Discord.js. You also have access to the typical Map functions as well.

How to upload multiple files on single statement in selenium?

I am not getting any warning or error message while executing the program.
wd.findElement(By.xpath("XPATH")).sendKeys("ABC.jpg","XYZ.jpg");
But no file is uploading.
wd.findElement(By.xpath("XPATH")).sendKeys("can we make CTRL+A operation" );
Thanks in advance.
I think you may be going about this while "file upload in Selenium" thing wrong, so that's what I'm going to address.
This article by SauceLabs covers the basic steps to handle a file upload through Selenium in both Java and Ruby. Assuming you're using Java, there are a few steps you'd need:
Set the FileDetector method for your WebDriver
Get a WebElement pointing to a valid HTML input tag of type file
Have Selenium type in the file's path (Not sure if this requires absolute paths, but it's probably a good idea)
Submit the form
The following code listing demonstrates how to perform each of these steps:
wd.setFileDetector(new LocalFileDetector());
// point your webdriver to the page containing the upload form.
WebElement upload = wd.findElement(By.xpath("XPATH")); // TODO replace xpath!
upload.sendKeys("/path/to/ABC.jpg");
upload.submit(); // NOTE: Submits the form *containing* the upload field!
Because you've set the file detection method to LocalFileDetection, Selenium will be able to find the appropriate file. If this is not set, then Selenium defaults to the UselessFileDetection implementation, which fails every time to avoid accidental file uploads.
Caveat: If you're using a Javascript or Flash-based multiple file upload system, then this probably won't work, since those typically bypass the original input field or handle upload independently from the form's submission.
You are not getting an error because sendKeys() accepts an array of CharSequence objects. and you are conforming to that method contract
But no file is uploading
That is because the way your code is written now, will actually send the text: ABC.jpgXYZ.jpg.

Close method not working in Office

Im trying to use Microsoft.Office.Interop.Word._Document.Close() in a .net 3.5 windows form app.
No matter how much I search here and on Google I cannot find the correct parameters to put in the Close method.
I am using version 14.0.0.0 of Microsoft.Office.Interop.Word and I would like to close the document without saving and ideally ensure that the application can isolate the document thread so that users can still open word documents outside the running application.
See the Close method of the Document class described in MSDN. If you need to omit the parameter and use the default value - pass the Type.Missing parameter.
Try this:
object doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
object missing = System.Reflection.Missing.Value;
_Document.Close(ref doNotSaveChanges, ref missing, ref missing);
This is the source
I'm not sure if you'll need the middle line or not. It's not from the original source it's from here

How secure is str(BlobKey)?

I have implemented a generic blob serving handler as mentioned in the appengine docs. The handler will serve any blob to you, as long as you know that blob's key string. I am using it to easily compose URLs that clients can use to download their files. If client A inspects the URL to download their file and finds their blob key (i.e. 1CX2kh468IDYKGcDUiq5c69u8BRXBtKBYcIaJkmSbSa4QY096gGVaYCZJjGZUpDz == str(BlobKey)), can they somehow reverse-engineer this key and easily construct another key that can be used to download client B's files? Or does the key have a random component added?
For reference, there is this note about str(db.Key), which is what raises my question:
Note: The string representation of a key looks cryptic, but is not
encrypted! It can be converted back to the raw key data, both kind and
identifier. If you don't want to expose this data to your users (and
allow them to easily guess other entities' keys), then encrypt these
strings or use something else.
I am creating the files like this, which does not specify a filename parameter, so I think the question boils down to, how does create() "pick" a filename when one is not specified? I suppose I could generate a random filename and pass it in here to be doubly sure this is secure.
file_name = files.blobstore.create(mime_type='application/octet-stream')
BlobKeys are non guessable. If a user has one key, that in no way enables them to guess another key. Unlike datastore keys, which contain full path information, BlobKeys do not encode any such data. You can share them safely without risk of a user doing an attack as you describe.
(I could not locate docs for these claims - this is based on my recollection.)
Assign a filename when creating a blob:
name = .....
file_name = files.blobstore.create(mime_type='application/octet-stream', _blobinfo_uploaded_filename=name)
And you do not need to use str(BlobKey). The BlobKey can be part of your serving url

Receive multi file post with google app engine

I want to receive multi file post from image uploader.(i use this)
Most examples show how to receive one image from post.
I tried many ways but never got the results.
For example
self.request.POST['Filename']
gives only first filename.
What to do when there are multiple files/images in post?
The reason for this is to resize before upload images, that are too big for google app engine
to upload.
EDIT:
self.request.POST.multi.__dict__
shows
{'_items':
[('Filename', 'camila1.jpg'),
('Filedata[]', FieldStorage('Filedata[]', 'camila1.jpg')),
('Upload', 'Submit Query\r\n--negpwjpcenudkacqrxpleuuubfqqftwm----negpwjpcenudkacqrxpleuuubfqqftwm\r\nContent-Disposition: form-data; name="Filename"\r\n\r\nbornToBeWild1.jpg'),
('Filedata[]', FieldStorage('Filedata[]', 'bornToBeWild1.jpg')),
('Upload', 'Submit Query')]}
Your flash uploader is designed to work with PHP and sends multiple Filedata[] fields (php interprets this as an array for easy access)
So you need to iterate and get them all:
def post(self):
for file_data in self.request.POST.getall('Filedata[]'):
logging.info(file_data.filename)
data should be file_data.value
Are you using the Django libraries available to you? If so, check this out.
Call self.request.POST.getall('Filename') to get a list of FieldStorage objects; each one contains one file. You can access the file data with .value, the name with .name, and the mimetype with .type.
I have no idea how that multi uploader works, I have made one in the past however and I just added a number on the end of input field name, then hide it. Then add a new file input field to add another file. The reason for this is that they don't let you play around with input file fields to much because you could make it upload files they didn't want you uploading.
Using my conventions, in your example the 2 files in your example would be "Filename0" and "Filename1". You could also use firebug to see what it renaming the input file fields to.
Edit: I had a look, and it's using flash. So i have no idea how it works.

Resources