Javascript: Dynamically set up onmouseup with an object - javascript-events

I am setting up an onmouseup event like this:
html += ' onmouseup="' + func + '(event, \'' + tileInfo.targetURL + '\', \'' + tileInfo.id + '\')"
where func is a var with a value like "launchA" or "launchB". The launchA and launchB methods expect three arguments, event, targetURL (which is a string) and id (which is also a string).
Since both targetURL and id are properties of the same object (tileInfo), I would prefer to pass tileInfo to the launch methods, and let them make references to tileInfo.targetURL and tileInfo.id, but when I set it up like this:
html += ' onmouseup="' + func + '(event, \'' + tileInfo + '\')"
when it hits launchA, tileInfo is an Object, but tileInfo.id is undefined.

More specifics were provided in a separate but related question, which was answered here: Javascript attach new property to element.

Related

Adding multiple CC recipients in VBScript; Recipient.Type not working

I am working on a jsx (extendscript project) in which I am calling a VBS snippet with app.doScript. I cannot get the email_cc and email_cc2 recipients to show up as cc; they are stuck in the main "To" sending. I will not know in advance whether they exist in the users' address book, so I am adding them as recipients than trying to set their Type.
var vbs = 'Dim objOutl\r';
vbs += 'Set objOutl = CreateObject("Outlook.Application")\r';
vbs += 'Set objMailItem = objOutl.CreateItem(olMailItem)\r';
vbs += 'objMailItem.Display\r';
vbs += 'strEmailAddress = "' + email_address + '"\r';
vbs += 'objMailItem.Recipients.Add strEmailAddress\r';
vbs += 'strSubject = "' + the_subject + '"\r';
vbs += 'objMailItem.Subject = strSubject\r';
vbs += 'objMailItem.Body = "' + the_bodytext + '"\r';
if (email_cc && email_cc != "") {
vbs += 'Set cc1Recipient = objMailItem.Recipients.Add ("' + email_cc + '")\r';
if (email_cc2 && email_cc2 != "") {
vbs += 'Set cc2Recipient = objMailItem.Recipients.Add ("' + email_cc2 + '")\r';
vbs += 'cc1Recipient.Type = olCC\r';
vbs += 'cc2Recipient.Type = olCC\r';
}
else {
vbs += 'cc1Recipient.Type = olCC\r';
}
}
if (has_attachment) {
vbs += 'objMailItem.Attachments.Add "' + pdf_file + '"\r';
}
Check out the following points:
Try to use the fully qualified name in the code with the enum name, for example:
OlMailRecipientType.olCC
Use the Resolve method which attempts to resolve a recipient object against the address book. It returns true if the recipient was resolved.
Call the Save method to apply changes made through the OOM. Sometimes it makes sense to close the item, switch to another Outlook item, and then come back to check out results. Outlook caches changes and doesn't propagate changes made using the OOM immediately.
Read more about these methods and properties in the How To: Fill TO,CC and BCC fields in Outlook programmatically article.

Inconsistent formatting of Go code?

Here are some example code:
func main() {
os.MkdirAll(outDir + id, 0755)
os.Create(outDir + id + "/txt")
os.OpenFile(outDir + id + "/" + ".tmp", os.OWRONLY|os_APPEND)
os.Stat(outDir + id + "/.tmp")
}
The following is the output after formatting with either go fmt or pressing Format on the Go Playground:
func main() {
os.MkdirAll(outDir+id, 0755)
os.Create(outDir + id + "/txt")
os.OpenFile(outDir+id+"/"+".tmp", os.OWRONLY|os_APPEND)
os.Stat(outDir + id + "/.tmp")
}
Spaces in os.MkdirAll() and os.OpenFile() are removed while they are untouched in os.Create() and os.Stat(). I would expect that formatting to be identical.
Why is this happening?
See: https://github.com/golang/go/issues/12720
gofmt uses spaces around binary expressions to express binding
strength. Depending on nesting level, spaces are removed.
You could also find these easily by searching for "gofmt inconsistent spaces".
See also issue #1206, #1848, #1861, #7880, and #11497.

xamarin camera - No overload for method 'Exists' takes '1' arguments

I am trying to use the camera in Xamarin and have a method that gets a unique path as follows
private string GetUniquePath(string path, string name)
{
string ext = Path.GetExtension(name);
if (ext == string.Empty)
ext = ".jpg";
name = Path.GetFileNameWithoutExtension(name);
string newName = name + ext;
int i=1;
while (File.Exists(Path.Combine(path,newName)))
newName = name + "_" + (i++) + ext;
return Path.Combine(path, newName);
}
I get an error with -- while (File.Exists(Path.Combine(path,newName)))
The error is no overload for method 'Exists' takes 1 argument.
Yet thats the same format I see everywhere. any suggestions?
Error CS1501: No overload for method Exists' takes1' arguments
I would assume that it is picking up Java.IO.File.Exists which does not take any arguments.
Try fully qualifying the namespaces:
while (System.IO.File.Exists(System.IO.Path.Combine(path,newName)))
newName = name + "_" + (i++) + ext;

Using Swift's Repeat collection

In pre-Swift 2.0 sample code, I've come across something like:
var val = "hello" + Repeat(count: paddingAmount, repeatedValue: "-") + "."
In Xcode 7.0/Swift 2.0 Playground, this produces the error:
note: expected an argument list of type '(String, String)'
How would you use the Repeat collection and get the value that's held by the collection for use?
String has an initializer that will return a string of repeated characters, I would recommend using that in your case:
let padding = String(count: paddingAmount, repeatedValue: Character("-"))
var val = "hello" + padding + "."
It's now Array(count: paddingAmount, repeatedValue: "-").

F#: Breaking out of a loop

I am new to programming and F# is my first language.
I have a list of URLs that, when first accessed, either returned HTTP error 404 or experienced gateway timeout. For these URLs, I would like to try accessing them another 3 times. At the end of these 3 attempts, if a WebException error is still thrown, I will assume that the URL doesn't exist, and I will add it to a text file containing all of the invalid URLs.
Here is my code:
let tryAccessingAgain (url: string) (numAttempts: int) =
async {
for attempt = 1 to numAttempts do
try
let! html = fetchHtmlAsync url
let name = getNameFromPage html
let id = getIdFromUrl url
let newTextFile = File.Create(htmlDirectory + "\\" + id.ToString("00000") + " " + name.TrimEnd([|' '|]) + ".html")
use file = new StreamWriter(newTextFile)
file.Write(html)
file.Close()
with
:? System.Net.WebException -> File.AppendAllText("G:\User\Invalid URLs.txt", url + "\n")
}
I have tested fetchHtmlAsync, getNameFromPage and getIdFromUrl in F# Interactive. All of them work fine.
If I succeed in downloading the HTML contents of a URL without using all 3 attempts, obviously I want to break out of the for-loop immediately. My question is: How may I do so?
use recursion instead of the loop:
let rec tryAccessingAgain (url: string) (numAttempts: int) =
async {
if numAttempts > 0 then
try
let! html = fetchHtmlAsync url
let name = getNameFromPage html
let id = getIdFromUrl url
let newTextFile = File.Create(htmlDirectory + "\\" + id.ToString("00000") + " " + name.TrimEnd([|' '|]) + ".html")
use file = new StreamWriter(newTextFile)
file.Write(html)
file.Close()
with
| :? System.Net.WebException ->
File.AppendAllText("G:\User\Invalid URLs.txt", url + "\n")
return! tryAccessingAgain url (numAttempts-1)
}
please note that I could not test it and there might be some syntax errors - sorry if
as we are at it - you might want to rewrite the logging of the invalid url like this:
let rec tryAccessingAgain (url: string) (numAttempts: int) =
async {
if numAttempts <= 0 then
File.AppendAllText("G:\User\Invalid URLs.txt", url + "\n")
else
try
let! html = fetchHtmlAsync url
let name = getNameFromPage html
let id = getIdFromUrl url
let newTextFile = File.Create(htmlDirectory + "\\" + id.ToString("00000") + " " + name.TrimEnd([|' '|]) + ".html")
use file = new StreamWriter(newTextFile)
file.Write(html)
file.Close()
with
| :? System.Net.WebException ->
return! tryAccessingAgain url (numAttempts-1)
}
this way it will only be logged once the attempts where all made

Resources