AppleScript syntax all messed up, how to re-build? - applescript

One of my AppleScripts hasn't been working for a few weeks, so I decided to investigate why. Upon opening it in the Script Editor of OS X, I was kind of surprised to see the code formatted like this. Snippet:
FasdUAS 1.101.10ˇˇˇˇ
k
lˇ˛ˇ˛Get battery level± "Get battery level
ˇ˝
l|ˇ¸ˇ˚
Q|
ˇ˙
ks
r
Iˇ˘ˇ¯
ˇ˘.sysoexecTEXTˇˇÄTEXT
m±Pioreg -w0 -l | grep "\"MaxCapacity\" = "ˇ¯
oˇ˜ˇ˜0maxcapacitymaxCapacity
r
lˇˆˇı
n
4ˇÙ
ˇÙ
cwor
m
ˇÛˇÛˇˇ
oˇÚˇÚ0maxcapacitymaxCapacityˇˆˇı
oˇÒˇÒ0maxlevelmaxLevel
r !
Iˇ"ˇÔ
ˇ.sysoexecTEXTˇˇÄTEXT
As you can see, a lot of weird characters that pretty much make this script impossible to use, and impossible to "fix", syntax-wise.
What can cause something like this to happen and how can I rectify it? It will take me hours to rebuild it manually.

Related

rxCrossTabs crashes on a character variable

When I run this in Revolution R Enterprise, it totally crashes Rstudio on the last line:
require(RevoScaleR)
set.seed(1)
a = sample(c("happy", "sad", "other", NA), 100, replace = TRUE)
y = data.frame(a)
y$a = as.character(y$a)
rxCrossTabs(1 ~ a, data = y)
This seems buggy to me. Shouldn't it at least throw a warning and return me the command prompt?
The quick fix above is to simply exclude the line y$a = as.character(y$a), but I'd rather really understand what is going on. I'm having the same sort of crash with rxCrossTabs when I try to run it on a .xdf file, and I wonder if it is a related issue. I.e., perhaps somehow R is reading in a column of the file as character only instead of as factor, but I'm not sure how to investigate that directly.
This is not a Revolution R problem; it's an Rstudio problem. If I run your code in R in a terminal session, it does not crash, but it does throw an error message that Rstudio should have relayed to you:
Evidently your challenge now is to figure out how to put the right variable type on each column of interest in your .xdf file. Specifically, you need to have a factor variable to use the rxCrossTabs function.

Julia doing something strange with assignments

I am trying to learn Julia by repeating some of the easy ProjectEuler problems in Julia. Everything has been really smooth so far, up until I encountered this frustrating problem. I spent some time debugging my code, and here's what I found:
(Hopefully I'm not missing something really stupid here)
function is_abundant(n::Int) #just a function
return prod(map(x->int((x[1]^(x[2]+1)-1)/(x[1]-1)),factor(n))) > 2 * n
end
abundants=[12] #there should be a better way to initialize an Array
for i=13:28120
if is_abundant(i)
push!(abundants,i)
end
end
le=abundants; #The following lines are the problems
ri=abundants;
d=length(abundants)
println(d)
pop!(le)
shift!(ri)
println(le==ri, " ", endof(ri), " ", endof(abundants))
The output I get is:
6964
true 6962 6962
which means that Julia has changed all three sets of le , ri and abundants with each of pop! and shift! commands. I was able to work around this bug/problem by using a dumb extra identity mapping:
le=map(x->x,abundants)
ri=map(x->x,abundants)
Now the output would change to what I initially expected:
6964
false 6963 6964
My question is, if this is not a bug, why is Julia keeping an equivalence relation between le , ri and abundants sets in the first place? Also, can anyone reproduce this behaviour? I am using Julia "Version 0.3.0-rc3+14 (2014-08-13 16:01 UTC)" on Ubuntu 14.04.
le and ri both point to the same list that abundants points to, so this is expected behavior - they are all operating on the same memory. This part of the manual might help you understand. Or possibly the MATLAB differences section, as it is different in MATLAB (but most other languages are like Julia).
For
abundants=[12] #there should be a better way to initialize an Array
how about
abundants = {} # Vector of anything
or
abundants = Int[] # Vector of ints
and instead of your map(x->x,...), you can just use copy.

AIX Shell Script - Formatting a long line of 255 Characters into a 10 line paragraph

I am trying to find a solution (Korn Shell Script) to my problem of splitting a long line of text into a multi-line paragraph. The script will run on AIX 5.3
The text will be a maximum of 255 Characters long and is read from a Oracle table column field of VARCHAR2 Type.
I would like to split it into 10 lines of minimum 20 and maximum 30 Characters per line and at the same time ensuring that the words don't get split between 2 lines.
I have tried and so far, I have achieved the ability to split within the SQL Query itself by using multiple SUBSTR calls but that does not solve my problem of not having the same word split across two lines and hence hoping to see if this can be solved within the Shell Script.
So for example, if the input variable is
Life is not about searching for the things that could be found. It's about letting the unexpected happen. And finding things you never searched for. Sometimes, the best way to move ahead in life is to admit that you've enough.
Output should be
Life is not about searching for
the things that could be found.
It's about letting the unexpected
happen. And finding things you
never searched for. Sometimes, the
best way to move ahead in life is
to admit that you've enough.
Appreciate if someone could guide me. Can this be achieved using sed or awk? Or something else.
How about this?
echo "Life is not about searching for the things that could be \
found. It's about letting the unexpected happen. And finding things \
you never searched for. Sometimes, the best way to move ahead in life \
is to admit that you've enough" |
fmt -w 30
Result:
Life is not about searching
for the things that could be
found. It's about letting
the unexpected happen.
And finding things you never
searched for. Sometimes,
the best way to move ahead
in life is to admit that
you've enough
One way using awk:
awk '{for(i=1;i<=NF;i++){printf("%s%s",$i,i%6?" ":"\n")}}'
Test:
$ echo "$line" | awk '{for(i=1;i<=NF;i++){printf("%s%s",$i,i%6?" ":"\n")}}'
Life is not about searching for
the things that could be found.
It's about letting the unexpected happen.
And finding things you never searched
for. Sometimes, the best way to
move ahead in life is to
admit that you've enough.
Don't you guys know about "man" ?
man fmt
gives a page, the top has
/usr/bin/fmt [ -Width ] [ File ... ]
thus:
fmt -20 < /etc/motd
*******************************************************************************
*
*
*
* * Welcome to AIX
Version
6.1!
*
*
*
*
* * Please see the
README file in
/usr/lpp/bos for
information
pertinent to *
* this release of
the AIX Operating
System.
*
*
*
*
*
*******************************************************************************

Best way to use R in Ruby

I want to visualize some of my statistical caluclations in Ruby.
My problem is, that I can't find the right gem for that.
rsruby doesn't seem to be up-to-date and I can't install it in Ruby 1.9.2.
Do you know a way how to run the R commands in Ruby?
I just saw this post and thought I should comment since I use R pretty extensively. If you are coming from an R background the best gem I have found is Rinruby. The reason it is fantastic is because you don't interpret the commands in ruby, you use actual R code. For example:
require "rinruby"
#Set all your variables in Ruby
n = 10
beta_0 = 1
beta_1 = 0.25
alpha = 0.05
seed = 23423
R.x = (1..n).entries
#Use actual R code to perform the analysis
R.eval <<EOF
set.seed(#{seed})
y <- #{beta_0} + #{beta_1}*x + rnorm(#{n})
fit <- lm( y ~ x )
est <- round(coef(fit),3)
pvalue <- summary(fit)$coefficients[2,4]
EOF
On the Rinruby website I listed above there are some fantastic examples to get you started. Hope this helped.
-Sean
As #Hansi mentioned, RServe is the best way I've found to run R remotely. If you're using Ruby from a web-context especially, RServe can offer some nice benefits.
Best of all (in my mind), you don't get locked into any one programming framework, as there are RServe clients for a variety of languages including Java and C++. When using web-accessible platforms, you can even keep Rserve running on a separate host and route traffic over TCP/IP for added security.

Programmatically adding appointments to Oracle Calendar 10

I'm trying to integrate a Web scheduling appliance with my organization's calendar system, Oracle Calendar 10. Getting meetings out is just a matter of parsing the UNICPOUTR output, and I thought I had a handle on getting meetings in with UNICPINR, but I'm getting a couple of odd errors.
Basically I grab the room description from UNICPOUTR, append the data for the new meeting, write out to /usr/tmp, and try to import the resulting file. I created a test resource to try things out, but something's gone odd. Here's the resource description from UNICPOUTR:
{
F Unison Export File
V A.02.53
E FALSE
X
R a Test Resource
R b
R c 10
R d
R e
R f
R g
I
P 4 480 1080 1 30 190 2 1 60 0 0 10
N 0
}
But trying to use this as a basis for an import file results in the rather odd error:
"R=Test Resource/N=Test Resou/CA=10/LOC=10/PHONE=10/EXT=10/FAX=10/PSW=g"
does not exist
Trying to get a handle on the resource with the -ls flag on UNICPINR, as
unicpinr -ls /usr/tmp/meeting.test
just spits out
unicpinr: file pattern not found - First
after a message on how to use the utility.
Is anybody out there familiar enough with the system that they can tell me what's going wrong here, or better yet suggest an alternate way to get new meetings in?
Okay, so after spending a day chewing on it, I've come up with this solution. There were a couple problems at work here (notwithstanding the -ls which I haven't investigated).
First: while UNICPOUTR will produce blank lines for acceptable nulls in the resource description, UNICPINR will for some reason assume that a blank line means to use the value from the previous line of input.
Second: UNICPINR doesn't seem to be able to search on anything other than the resource name.
Solution: take the resource description block and filter out the lines that start with X (room administrator), I (room password), and "R b" through "R g" (various resource identifiers). UNICPINR can run a search with "R a" just fine.
The resulting import, however, leaves all the meetings thinking they were created (M) and owned (W) by the room itself, but the original creator/owner are in the comments section prefaced by "Event creator: " and "Event owner: ", so I can work with that.
This may be a problem that only I will ever face, but it's responsible to leave the solution, however kludgy, in case someone else is out there groping about blindly. So here it is.

Resources