Title Case in AutoHotkey - case

Is it possible to transform the text in the Clipboard in a Title Case form?
For example if the text in the clipboard is "The quick brown fox" then the script will have to transform it into:
"The Quick Brown Fox"
It would be nice to also work with non-ASCII characters too (diacritics), transforming "anders ångström" into "Anders Ångström"

Try this:
StringUpper, ClipBoard , ClipBoard , T
Send, ^v
Return

Old question but in case anyone else in my boat looking for this or something similar this reddit post got me what I needed:
^!u::
clipboard := ""
send ^{c}
clipWait, 0.3
stringUpper, clipboard, clipboard
send ^{v}
return
^!l::
clipboard := ""
send ^{c}
clipWait, 0.3
stringLower, clipboard, clipboard
send ^{v}
return
^!t::
clipboard := ""
send ^{c}
clipWait, 0.3
stringLower, clipboard, clipboard, T
send ^{v}
return
After setting up holding CTRL+ALT and "l", "u" or "t" will change the case of your selected text.

Related

Shortcut to paste clipboard contents into RStudio automatically surrounded by quotes?

Sometimes we copy/paste a string into RStudio, in which case we need to manually surround the text with quotes.
Is there a native way to paste with automatic quoting?
Example
If the clipboard contained here is my text, such a shortcut would result in "here is my text" being pasted in the R console/script pane.
This can be done in R:
x <- readClipboard()
x
## [1] "Here is my text"
This also works:
x <- readLines(stdin())
...paste clipboard into R & press ctrl-z (windows) or ctrl-d (unix)...
x
## [1] "Here is my text"
If you want a way to make the text contents of your Clipboard reusable in a script you can do
dput(readClipboard())
This has the benefit of automatically making multi-line text into a concatenated character vector. For example if I copy:
Alas, poor Yorick!
I knew him, Horatio;
a fellow of infinite jest,
of most excellent fancy;
Then I can do
dput(readClipboard())
# c("Alas, poor Yorick! ", "I knew him, Horatio; ", "a fellow of infinite jest, ",
# "of most excellent fancy; ")

Google translate text to speech and apostrophes

I am using google API to translate a sentence. Once translated I use text to speech google API with the result of the translation.
Translation and text to speech work pretty well in general. However, I have a problem with the apostrophes. For example:
1) Translation result: I & # 3 9 ; m tired (Note: I had to separate the characters with spaces because it was shown as "I´m tired" in the preview...
2) Text to speech result says : "I and hash thirty nine m tired" (or something similar)
What kind of encoding do I need to use in the 1st step to get the output string right (i.e. I´m tired)
The program is in python. I include an extract here:
def tts_translated_text (self, input_text, input_language):
from google.cloud import texttospeech
client = texttospeech.TextToSpeechClient()
input_text = input_text.encode ("utf-8")
# Set the text input to be synthesized
synthesis_input = texttospeech.types.SynthesisInput(text=input_text)
voice = texttospeech.types.VoiceSelectionParams( language_code=input_language, ssml_gender=texttospeech.enums.SsmlVoiceGender.FEMALE)
audio_config = texttospeech.types.AudioConfig(
audio_encoding=texttospeech.enums.AudioEncoding.LINEAR16)
response = client.synthesize_speech(synthesis_input, voice, audio_config)
# The response's audio_content is binary.
with open('output.wav', 'wb') as out:
# Write the response to the output file.
out.write(response.audio_content)
Thanks in advance,
Ester
I finally found what was wrong. Google Translate API returns the string with HTML encoding. And Google Text-To-Speech expects UTF-8 encoding.
I am forced to use python2.7 so I did the following:
translated_text = HTMLParser.HTMLParser().unescape (translated_text_html)
Where translated_text_html is the returned string from the translation API invocation
In python3 it should be:
translated_text = html.unescape (translated_text_html)

Xamarin Forms: Pasted test contains + symbol instead of white space

Last year I asked a question about copy the entry value in xamarin forms.
When I test it now the white spaces in the text are filled by a + symbol. Also when pasting the emojis it is not working properly.
I am using Xamarin.Plugins.Clipboard NuGet package for copy the text to the clipboard. When copy text to clipboard I am using the following code:
CrossClipboard.Current.SetText(message);
When long press in the device it shows the paste option. I am using that option for pasting the copied text.
Please suggest a solution for avoiding the + symbol? Also for emoji copy paste.
Thanks in advance.
Problem should need to WebUtility.UrlDecode(String) the text :
Converts a string that has been encoded for transmission in a URL into a decoded string.
If characters such as blanks and punctuation are passed in an HTTP stream, they might be misinterpreted at the receiving end. URL encoding converts characters that are not allowed in a URL into equivalent hexadecimal escape sequences. The UrlEncode method creates a URL-encoded string.
URL decoding replaces hexadecimal escape sequences with corresponding ASCII character equivalents. For example, when embedded in a block of URL-encoded text, the escape sequences %3c and %3e are decoded into the characters < and >.
Sample as follow:
using System.Net;
Console.WriteLine("Encode:" + WebUtility.UrlEncode("😂"));
// out ==> %F0%9F%98%82
Console.WriteLine("Decode:" + WebUtility.UrlDecode("%F0%9F%98%82"));
// out ==> 😂
Console.WriteLine("Encode:" + WebUtility.UrlEncode("this is a text message"));
// out ==> this+is+a+text+message
Console.WriteLine("Decode:" + WebUtility.UrlDecode("this+is+a+text+message"));
// out ==> this is a text message
Solution:
Not directly CrossClipboard.Current.SetText(message);
Try with CrossClipboard.Current.SetText( WebUtility.UrlDecode(message));

R: Why does the 'space' character in an externally generated string have ASCII value 'NA'?

I'm working with some SurveyMonkey response data, which I'm importing from a .xlsx file.
Something along these lines was happening:
> unique(responseColumn)
[1] "This string"
[2] "Something else"
>(responseColumn == unique(responseColumn)[1])
[1] 25
>sum(responseColumn == "This string")
[1] 0
>unique(responseColumn)[1]
[1] "This string"
>unique(responseColumn)[1] == "This string"
[1] FALSE
Obviously that was confusing. I played around for a while and found that I could use
writeClipboard(unique(responseColumn)[1])
to catch the offending string and paste it into my code.
In the console, it looked exactly the same: "This string".
In my script editing window, however, it appeared as:
I copied the red dot to the clipboard and did some testing:
>readClipboard()
[1] " "
>readClipboard() == " "
[1] FALSE
>utf8toInt(" ")
[1] 32
>utf8toInt(readClipboard())
[1] NA
What is this mysterious character? I wrote the Survey Monkey questions and distinctly remember hitting 'space' on my keyboard when specifying this option. Other spaces in the response have remained as they were (In fact the response in question actually has multiple spaces IRL and only one of them has been converted into this mysteryChar). What's going on?
My guess here is that the "red" dot is just some non ASCII, possibly UTF-8, character. That you can't see it in R console does not mean that it still is not logically there in the Windows clipboard. It could just mean that R console is not displaying UTF-8 characters correctly.
If your R tool is not displaying the character correctly, then consider configuring it to support UTF-8.

Return text in .R script as a string

This may be a strange request, and there is not much I can do to actually show an example. Though I will try my hardest. Let's say I have an R script, such as a simple one that looks like this:
library(lubridate)
setwd("")
df=read.csv("...")
df=df[df$month != "" & !is.na(df$month),]
colnames(df)[3]="metric"
Is there now a way, to return a string which contains the actual text in my script? Or a creative way to save the information and read it back into the environment. For instance, I would like to create a string variable which is equal to:
"
library(lubridate)
setwd("")
df=read.csv("...")
df=df[df$month != "" & !is.na(df$month),]
colnames(df)[3]="metric""
This just requires a quick google search.
how to replace single backslash in R
Which function should I use to read unstructured text file into R?
Assuming that you have a text file named test.txt
tt <- readLines("test.txt")
gsub("\\\"","\'",tt)
Results:
> gsub("\\\"","\'",tt)
[1] "'"
[2] "library(lubridate)"
[3] "setwd('')"
[4] "df=read.csv('...')"
[5] "df=df[df$month != '' & !is.na(df$month),]"
[6] "colnames(df)[3]='metric'"
But...
I changed "" to ''...for example look at setwd
I would be careful with the gsub part. By that I mean you have to be
aware of what your text file contains. If a text file contains back
slashes: "\\path\\to\\file" then the code will fail

Resources