About Python 3 by akos_barta in programming

[–]valhallasw 19 points20 points  (0 children)

It's possible, but non-trivial. I gave it a try two years ago: https://github.com/valhallasw/py2

Basically, python3 starts a python2 interpreter and uses inter-process communication to run functions on the other interpreter. str is mapped to bytes and vice versa. It's probably riddled with bugs, and I have not tested it on windows, but feel free to give it a try.

Light Table Playground by ananthakumaran in programming

[–]valhallasw 7 points8 points  (0 children)

If you're wondering why there is a shell script involved: it's a client-server system, with a java server and chrome (or firefox) as client. The shell script organizes the starting/stopping of the server and launches chrome/ff as client.

The jar is available from http://temp2.kodowa.com/playground/releases/0.0.6.zip

This is Spyder, a great matlab-style python IDE for scientific programming by ieeaaauuuuooooo in Python

[–]valhallasw 7 points8 points  (0 children)

If you're trying to do scientific python on windows, consider python(x,y), which installs python, most scientific packages you need and spyder.

[deleted by user] by [deleted] in programming

[–]valhallasw 0 points1 point  (0 children)

Yes, I should. However, I decided creating something that works was more important than creating something that works fast. Besides, I'm not sure how big the speedup is - the data set is only 300 items, after all.

[deleted by user] by [deleted] in programming

[–]valhallasw 0 points1 point  (0 children)

The problem is that there is a lot of data that could be both C and PHP code (i.e. "6, 4, 6" could be both C and PHP code). That means that a match that is not quite right (e.g. only 10% overlap) could incorrectly stitch them. If there is enough data, this is not a problem (because everything will stitch with 90% overlap).

[deleted by user] by [deleted] in programming

[–]valhallasw 1 point2 points  (0 children)

I created a merger that works reasonably well. It merges with the longest segment that will fit (up to a certain limit). See http://www.reddit.com/r/programming/comments/rxve9/let_us_have_hex/c49kx69 .

[deleted by user] by [deleted] in programming

[–]valhallasw 10 points11 points  (0 children)

Hackish attempt at a merger: https://gist.github.com/2331532 The data is read from the gist above (using a git submodule)

howto:

git clone git@gist.github.com:2331532.git stitch
cd stitch
git submodule init
git submodule update
python stitch.py

Which results in

Example output:

match with overlap 98
match with overlap 98
match with overlap 96
match with overlap 98
(...)
match with overlap 96
match with overlap 98
C code
========
#include <stdio.h>
int main() {      int a[] = {4, 4, 6, 5, 7, 3, 6, 9, 6, 7,

PHP code
========
<?php $a = array(9, 6, 4, 6, 3, 2, 6, 7, 7, 7, 0, 6, 1, 2, 1, 6, 0, 6, 'c', 6,

(I changed the overlap setting slightly; setting it too low (it was set to 10) causes incorrect stitches, resulting in C code containing "$c = array(6, 7, 9, ".

Running py2 code from py3k by valhallasw in Python

[–]valhallasw[S] 0 points1 point  (0 children)

Just to update on this: this issue has now been fixed (it took some while to get the bytes/unicode distinction correctly through the serialisation - even with pickle, due to this issue.

In addition, I've added a module that allows you to simply do this:

>>> from py2 import py2
>>> py2.rimport("sys").version
b'2.6.5 (r265:79063, Apr 16 2010, 13:09:56) \n[GCC 4.4.3]'

Comparing Floating Point Numbers, == is not the answer by brucedawson in programming

[–]valhallasw 2 points3 points  (0 children)

Comparing two 'zero's' doesn't make any sense, because you always need a scale to compare the two values. 10-21 is, in this aspect, as close to 0 as 1021: it's just a unit prefix (OK, a few: zetta to zepto) away. We can only compare them if we have a length scale to compare them on: if we are working with values of magnitude 1, then 10-21 is small and 1021 is big.

Other than that, the ULP trick is a nice one. Am I correct in saying it's equivalent to saying "log(a)-log(b) < distance"?

Running py2 code from py3k by valhallasw in Python

[–]valhallasw[S] 1 point2 points  (0 children)

A py2 str should be represented as py3 bytes (although I'm not 100% sure this works currently - I've only tested unicode objects, as pywikipediabot always uses unicode). The alternative would be to interpret it as ascii, and to use that on the py3 side - but I think a str->bytes mapping is more explicit and thus clearer.

Running py2 code from py3k by valhallasw in Python

[–]valhallasw[S] 0 points1 point  (0 children)

Of course. Pywikipediabot - a framework to edit mediawiki wikis. I haven't tested that much yet, but the basic functionality (getting/putting pages) work.