How to plot a graph in SAGE using non-english symbols? - sage

Simple command I try to run:
sage: Graph({'Б':[1,2]}).plot().save('/tmp.plot.png')
fails:
/usr/lib/sagemath/local/lib/python2.7/site-packages/matplotlib-1.5.1-py2.7-linux-x86_64.egg/matplotlib/text.py in set_text(self, s)
1204 ACCEPTS: string or anything printable with '%s' conversion.
1205 """
-> 1206 self._text = '%s' % (s,)
1207 self.stale = True
1208
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)
Can someone help with this?
SageMath version 7.2, Release Date: 2016-05-15

Apparently the way we use matplotlib doesn't allow non-ascii strings. See Trac 21008.
Update: This ticket now has a fix and positive review, so hopefully it will be in Sage 7.3, or possibly 7.4 depending on how fast 7.3 gets out.

Related

Max line length of 1023 in iESS (R in emacs)?

When I try to enter the line below into R in an iESS buffer, it doesn't work -- it prints out ^G and hangs until I press Ctrl-C. It's 1024 characters long. If I shorten the line by one character, it works as expected. Any suggestions on how to fix this? Thanks.
I'm using emacs 25.1 (9.0). ESS installed via spacemacs on macOS Sierra.
a=c("2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345678","2345780")

Openmdao 1.7.3 error with unicode variables in python2

In the file openmdao/core/problem.py on lines such as 1619 and 1638, it checks if a variable is a string by using:
isinstance(inp, str)
however, this will return false if inp is unicode in python2, and eventually cause the program to raise an exception. In python2, the correct syntax is:
isinstance(inp, basestring)
I understand that basestring is not available in python 3, but there are several ways to write python 2/3 compatible code. Can this be fixed?
feel free to submit a pull request, but please add a test that checks the new functionality

File date metadata not displaying properly

I have been trying to write a Powershell script based on some code online that will read the metadata info from picture, video and other files and then sort them based on one of the dates (date taken currently seems to be the best bet if it's available, but date modified works on files that have not yet been altered).
However, when I run the script and pull the info, I can't convert the string to a date. Here's roughly how I get the info through a COM object:
PS C:/> $objShell = New-Object -ComObject Shell.Application
PS C:/> $objFolder = $objShell.namespace("C:\MyFolder")
PS C:/> $date = $objFolder.GetDetailsOf($objFolder.Items().Item(0), 12)
PS C:/> $date
7/‎10/‎2014 ‏‎7:09 PM
The problem is I should be able to convert this to a datetime object. For instance, if I manually write it in it works:
PS C:/> [datetime]::ParseExact("7/10/2014 7:09 PM","g",$null)
Thursday, July 10, 2014 7:09:00 PM
But if I substitute the variable it doesn't work:
PS C:/> [datetime]::ParseExact($date,"g",$null)
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
At line:1 char:1
+ [datetime]::ParseExact($date,"g",$null)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FormatException
This is most likely due to the fact that the variable isn't actually what I'm seeing. It's in fact longer. Not to mention the fact that if you iterate through all the characters, you can see where the extra length is coming from:
PS C:\> $date.Length #should be about 16, you'd think
22
PS C:\> $datearray = #()
PS C:\> for ($i = 0; $i -lt $date.Length; $i++) {$datearray += $date[$i]}
PS C:\> $datearray #i'm printing on one line and in quotes for ease of viewing
" 7/ 10/ 2014 7:09 PM"
If you try printing the array with a join or something similar, the results are (to me, without knowing what's going on) unpredictable. It treats it like it has 22 characters, but prints ignoring the spaces.
I'm sure I could spend a bit of time and do some string formatting, but I'd rather just be able to parse the given date. What's going on?
Edit: I'm able to access the file info easily, though I prefer not to. I'm mainly focusing on why the results I'm seeing are inconstant and showing a length that doesn't match how it prints out, and how I can deal with them. If nothing else, I'm curious as to what is going on.
I wanted to know what the extra characters were ( you dont mention already looking at this. ). I Updated your array code $datearray += $date[$i] to $datearray += [int][char]$date[$i]. The truncated output showed two oddities 8207 and 8206 which translate to left-to-right mark and right-to-left mark. They are normally associated with html. Unfortunately i cannot provide insight to their presense. Good news is that they are easy to remove.
$date = ($date -replace [char]8206) -replace [char]8207
[datetime]::ParseExact($date,"g",$null)
Which nets the output
Thursday, March 26, 2009 1:43:00 PM
Hopefully this is a little bit closer of what you wanted. I tried searching for reasons for the presence of those ascii codes but i didn't find anything useful.
Extra Information for other readers
I did this since i didnt know what the index 12 was. So i made an array that contains the friendly names of all the file meta data possible (288 entries!). I have the here-string located here for brevity.
With this i was testing the following code against a picture of mine.
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.namespace("C:\Temp\")
0..$Meta.GetUpperBound(0)| %{
$metaValue = $objFolder.GetDetailsOf($objFolder.Items().Item(2), $_)
If ($metaValue) {Write-Host "$_ - $($meta[$_]) - $metaValue"}
}
$Meta is the array i spoke of earlier.
The code will cycle though all the details of my file, indicated by Item(2), writing to screen all file details that contain values. In the end there is a line converting the string to a date value. Script output below
0 - Name - IMG_0571.JPG
1 - Size - 3.12 MB
2 - Item type - JPEG image
3 - Date modified - 3/26/2009 3:34 PM
4 - Date created - 8/24/2014 5:19 PM
5 - Date accessed - 8/24/2014 5:19 PM
6 - Attributes - A
9 - Perceived type - Image
10 - Owner - TE_ST\Cameron
11 - Kind - Picture
12 - Date taken - ‎3/‎26/‎2009 ‏‎1:43 PM
19 - Rating - Unrated
30 - Camera model - Canon EOS DIGITAL REBEL XS
31 - Dimensions - ‪3888 x 2592‬
32 - Camera maker - Canon
53 - Computer - TE_ST (this computer)
155 - Filename - IMG_0571.JPG
160 - Bit depth - 24
161 - Horizontal resolution - ‎72 dpi
162 - Width - ‎3888 pixels
....output truncated....
247 - Program mode - Normal program
250 - White balance - Auto
269 - Sharing status - Not shared
When I run your code, $objFolder.GetDetailsOf($objFolder.Items().Item(0), 12) I get an empty string. I even changed the item number and the folder I was looking in to make sure I was getting a file object.
However if I do this:
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.namespace("C:\Temp")
$date = $objFolder.Items().Item(3).ModifyDate
I get a value that is already a DateTime object.
(the code above uses my folder and item index)

Decrypting a XOR encrypted file

I'm trying to decrypt a XOR encrypted file, after running the key length test using xortool I got this key: "fallen"..
# python xortool.py -c 00 /cygdrive/c/Users/Me/Desktop/ch3.bmp
The most probable key lengths:
1: 10.6%
3: 11.6%
6: 18.5%
9: 8.8%
12: 13.8%
15: 6.6%
18: 10.4%
24: 8.1%
30: 6.4%
36: 5.2%
Key-length can be 3*n
1 possible key(s) of length 6:
fallen
Whatever is there a way to decipher the file (a bmp file) and get the original one, using tools like openssl or gpg?? Do they have a XOR operation?
Neither OpenSSL nor GPG have such XOR functionality that I'm aware of, however writing a program to do it yourself should be trivial.
Given that you know that the file is a .bmp, you should be able to use this fact to decrypt the file quite easily, especially given that .bmp files have a well defined structure. For example, the first two bytes when decrypted should be 0x42, 0x4D (that's ASCII BM), and the following 4 bytes are the (big-endian) size of the entire file in bytes, so you should be able to get at least 6 bytes of the key immediately.
Since you already have xortool, just use xortool-xor from the xortool distribution:
python xortool/xortool-xor -s fallen /cygdrive/c/Users/Me/Desktop/ch3.bmp > decoded.bmp
Also note that xortool itself saves the decoded output in the xortool_out folder, so after using xortool to find the key, you could just do:
mv xortool_out/0_fallen decoded.bmp

Apache Pig: OutOfMemory exception with simple GROUP BY in local mode

I'm getting an OutOfMemory exception from Pig when trying to execute a very simple GROUP BY on a tiny (3KB), randomly-generated, example data set.
The pig script:
$ cat example.pig
raw =
LOAD 'example-data'
USING PigStorage()
AS (thing1_id:int,
thing2_id:int,
name:chararray,
timestamp:long);
grouped =
GROUP raw BY thing1_id;
DUMP grouped;
The data:
$ cat example-data
281906 13636091 hide 1334350350
174952 20148444 save 1334427826
1082780 16033108 hide 1334500374
2932953 14682185 save 1334501648
1908385 28928536 hide 1334367665
[snip]
$ wc example-data
100 400 3239 example-data
Here we go:
$ pig -x local example.pig
[snip]
java.lang.OutOfMemoryError: Java heap space
at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.<init>(MapTask.java:949)
at org.apache.hadoop.mapred.MapTask$NewOutputCollector.<init>(MapTask.java:674)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:756)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370)
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:212)
[snip]
And some extra info:
$ apt-cache show hadoop | grep Version
Version: 1.0.2
$ pig --version
Apache Pig version 0.9.2 (r1232772)
compiled Jan 17 2012, 23:49:20
$ echo $PIG_HEAPSIZE
4096
At this point, I feel like I must be doing something drastically wrong because I can't see any reason why 3 kB of text would ever cause the heap to fill up.
Check this: [link] http://sumedha.blogspot.in/2012/01/solving-apache-pig-javalangoutofmemorye.html
neil, you are right, let me explain the things like this: In the bin/pig script file, the source code is :
JAVA_HEAP_MAX=-Xmx1000m
# check envvars which might override default args
if [ "$PIG_HEAPSIZE" != "" ]; then
JAVA_HEAP_MAX="-Xmx""$PIG_HEAPSIZE""m"
fi
It is setting the Java_heap_size to maxium ("x") using the -Xmx switch only,but i didnot know why this script overriding is not working, that is the reason, i asked you to specify directly the java heap size using the paramters as specified in the link. I didnot got time to check why this problem is raising. If any one have idea please post it here.
You pig job is failing around the following code in MapTask.java:
931 final float recper = job.getFloat("io.sort.record.percent",(float)0.05);
932 final int sortmb = job.getInt("io.sort.mb", 100);
...
945 // buffers and accounting
946 int maxMemUsage = sortmb << 20;
947 int recordCapacity = (int)(maxMemUsage * recper);
948 recordCapacity -= recordCapacity % RECSIZE;
949 kvbuffer = new byte[maxMemUsage - recordCapacity];
So i suggest that you check what the configured value of io.sort.mb and io.sort.record.percent is, and whether following the above logic, maxMemUsage - recordCapacity this is close to, or bigger than your configured JVM heap size (4096 MB)
I toyed with it for a while and ended up switching from the debian packages for hadoop/pig to the raw tarballs, and the problem went away. Not sure what to make of that :)

Resources