omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. jldiaz

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 10
    • Best 0
    • Controversial 0
    • Groups 0

    jldiaz

    @jldiaz

    0
    Reputation
    731
    Profile views
    10
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    jldiaz Unfollow Follow

    Latest posts made by jldiaz

    • RE: A shorter way?

      The following code is a bit shorter than the one with the elifs, but this is not necessarily better (it is more difficult to understand). Anyway, it was a fun exercise.

      def name(x):
          compass = ['N', 'NE', 'E', 'SE',  'S', 'SW',  'W', 'NW', 'N'     ]
          angles  = [-20,   20,  70,  110,  160,  200,  250,  290, 340, 380]
          i = 0
          while i<len(compass):
              if i%2==0:   # Index is even
                  if angles[i] <= x <= angles[i+1]:
                      return compass[i]
              else:        # Index is odd
                  if angles[i] < x < angles[i+1]:
                      return compass[i]
              i = i + 1
          return "Error"
      

      Note: I much prefer the solutions given by onionradish and henryiii (I myself thought of something similar), but these functions do not give exactly the same results than Dann's one, which does not use equally-sized sectors.

      posted in Pythonista
      jldiaz
      jldiaz
    • RE: Opening Word documents in Pythonista

      Probably the webbrowser module, or console.quicklook() can open word documents

      http://omz-software.com/pythonista/docs/library/webbrowser.html

      posted in Pythonista
      jldiaz
      jldiaz
    • Useful workflow for sharing clipboard with desktop computer

      I love Editorial so much that I'm starting to use it as my editor of choice for writing Markdown, even replacing the one in the desktop computer (I used vim for that).

      However, I miss the speed of copy&pasting of the desktop. In the iPad, selecting text to copy it from the browser, pdf readers, or any other app, is still a slow and frustrating experience. Moreover, switching tasks decreases a lot my productivity (specially since I upgraded to iOS7, which tends to restart all background tasks, probably due to memory limitations of my iPad2).

      So I wrote two small pieces of software that allow me to have the best of both worlds.

      Now, I have the iPad with Editoral for note-taking while browsing, reading pdfs, and researching in the desktop computer and, when I find something interesting, I can copy the text to the computer's clipboard and paste it in my notes on the iPad.

      I'm so happy with this setup that I needed to share it :-) If you want to try it, you'll need:

      • Python in the desktop, with module xerox installed. It works with Linux (tested), Windows (tested) and OSX (still untested).
      • My clipboard server script, copypaste.py, which you can download from: https://gist.github.com/jldiaz/8002349
      • Editorial in the iPad (you have it already, don't you?)
      • My Editorial Workflows Paste from remote and Copy to remote

      How to use it:

      • In the desktop computer, run the script copypaste.py. Take note of the IP and port which are displayed
      • In the iPad, configure the above workflows, setting the IP and port obtained in the previous step (you have to enter these values in the first action of "Paste from remote", and the last one of "Copy to remote")
      • Select some text in the desktop and copy it to the clipboard (eg. Ctrl-C in Windows)
      • In Editorial run the Workflow "Paste from remote" and see how the text appears in the editor. It is also stored in the system clipboard, so you can use it in other apps.

      It can be run in the other direction too:

      • Write some text in the iPad, select it and copy it to the clipboard.
      • Run Editorial Workflow "Copy to remote"
      • In the desktop computer press Ctrl-V (paste) and the text copied in the iPad will appear. Useful for sharing URLs for example.
      • Enjoy!
      posted in Editorial
      jldiaz
      jldiaz
    • RE: Useful workflow for sharing clipboard with desktop computer

      It is easy to share between different computers using the iPad as a brigde. You only need to run the server in each computer (linux, mac), and then duplicate the workflows in the iPad to have different configurations (IP and port of each server). You can rename these workflows with names such as "Copy from linux", "Paste to mac", etc.. to avoid confusion.

      posted in Editorial
      jldiaz
      jldiaz
    • RE: New to programming

      I don't know what are you doing exactly to access to the intepreter, but obviously it doesn't work how you tried :-)

      There are several ways to run python code. From easy to difficult, they are:

      1. Go to the "Preview" screen. Notice four buttons at top. One of them is "Console". Press it, and you will arrive to a blank screen with a bar at the bottom which has the symbol >. You can write there direct python expressions such as 2+2 (do not write the >>> which is not part of the python language, but the prompt used by standard python interpreter in other operating systems). The answer appears in the blank area.
      2. The approach in 1 is good for small snippets, but if you want to write something longer, press the button "Python Scratchpad". Write your program there and run it pressing the "▶ " button. Note that, since you are not in the console anymore, expressions such as 2+2 will not print any result by default. If you want to see the result of an expression, you have to print it, eg: print 2+2
      3. As part of a workflow. Once you are confident with you python skills, you can write python code which is executed as part of a workflow. For that, you have to use the "Run python script" action from the Action Library. Typically you'll want that your script can have access to other workflow variables, such as the selection or the input. This is somewhat advanced stuff, so better leave it for the future.
      posted in Editorial
      jldiaz
      jldiaz
    • RE: can't get paramiko to connect no matter what

      The code looks good. The line ssh.load_system_host_keys() is not required, since you are auto-accepting any host key anyway, but I don't think it could cause problems.

      You say that the script hangs before ssh.connect(). I guess you mean it hangs when that line is executed, which would mean it is trying the connection without success.

      The main suspect is then the value of vps_ip variable. Are you sure you are providing a valid IP? Perhaps your host is behind a NAT and you are using the private IP? Or there is some kind of firewall between you and your host?

      To help the diagnosis, can you contact to the same IP from the same iPad, but using other SSH software (such as iSSH, for example)?

      posted in Pythonista
      jldiaz
      jldiaz
    • RE: Useful workflow for sharing clipboard with desktop computer

      I was wrong about python Editorial not including cryptographic libraries. Crypto module is available, and I did some tests for using AES with SHA256 checksums to provide basic authentication (via a shared secret) and confidentiality. It works well.

      However, adding this to my simple Workflows would require additional setup both in the client and server, and more computational power used . I still think that for private local networks it does not worth the pain.

      I guess I could release two different versions, with and without encryption, so that each user can choose depending of its needs and environment. Anyone would be interested in the secure version?

      posted in Editorial
      jldiaz
      jldiaz
    • RE: Useful workflow for sharing clipboard with desktop computer

      I thought about it, but I didn't implement it. I don't think it is needed, since the typical usage is inside a private network (after all you need to be near both devices), probably at home, behind a wireless router which implements NAT, which makes you inaccesible from the outside. And in any case you can choose any port for the comunication, which can be seen as a kind of "pin", because both client and server need to know the chosen port.

      Anyway, the kind of information I pass between the desktop computer an the ipad is not sensible information. Only text or code copied from books or websites, urls, that kind of things.

      If required, basic encryption could be implemented via a shared secret that the user should type both in the client and the server. Since editorial comes without cryptographic libraries I should implement my own, so a simple algorithm like RC4 should do. I don't know if it would be possible to access the crypto functions of ssl or paramiko, to use DES or AES. I know I could set up a proper ssh connection between client and server, but that seems overkil...

      posted in Editorial
      jldiaz
      jldiaz
    • RE: Useful workflow for sharing clipboard with desktop computer

      You are right, but since you have to enter the IP anyway, I didn't thought it was neccessary to set default values. Perhaps I should have removed the placeholder value to reduce the risk of confusion.

      By the way, I forgot to mention that it is possible to assign a keyboard shortcut for these actions. I use rpp for "remote paste" (inspired by ppp which is asigned by default to standard paste).

      posted in Editorial
      jldiaz
      jldiaz
    • RE: Best way to grab output from a web-based API call?

      You can write a snippet of python code which does the call and sets the output with the result.

      Editorial comes with requests package, which makes the task almost trivial:

      import requests, workflow
      
      r = requests.get('http://download.finance.yahoo.com/d/quotes.csv?s=EURUSD=X&f=sl1d1t1c1ohgv&e=.csv')
      # r.text contains the required answer, in this case I'll parse it a bit more
      rate = r.text.split(",")[1]  
      workflow.set_output(rate)
      

      If you put the above code in a Run Python Script action, you'll get the current conversion rate from Euro to Dollar (as provided by Yahoo) as the output of the action, which you can use as Input in the next action (eg. to display it in a Show Alert).

      posted in Editorial
      jldiaz
      jldiaz