Python: Simple HTTP Server on python.

(Repost from old blog)

Python have several modules that help you to achieve your goals. This week, on my spare time that is getting every day more scarce I spend time figuring out how to create a Python Web Server, I was planing to use it over an application that I’m developing on ICT Consulting. At the end I didn’t use it because I didn’t want a “passive” communication, but probably I will use this code on the CRM Desktop application that we use here.

Anyway, this code may be helpful for you too. I found that creating a small web server is really simple, It starts getting bigger as you add functions to that web server, but the basis is quite simple.

import os import cgi import sys from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler class customHTTPServer(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write('<HTML><body>Get!</body></HTML>') return def do_POST(self): global rootnode ctype,pdict = cgi.parse_header(self.headers.getheader('Content-type')) if ctype == 'multipart/form-data': query = cgi.parse_multipart(self.rfile, pdict) self.send_response(301) self.end_headers() self.wfile.write('Post!') def main(): try: server = HTTPServer(('',8080),customHTTPServer) print 'server started at port 8080' server.serve_forever() except KeyboardInterrupt: server.socket.close() if __name__=='__main__': main() read more

Image as background in a Gtk Application.

(Reposted from the old blog)

This time I’m going to talk about putting an image as the application background in Gtk. In Gtk we are used to leave the colors of the application to the theme, but sometimes we will need to use an image as background. I already wrote how to draw a pixbuf in a gtk.DrawingArea (Esp), we could use that, but we will “draw” directly on the widget window instead.

Yes, I said the widget’s window instead the widget itself. You should know that every widget that has been packed in a container has a gtk.gdk.window object and is the responsible for containing your widget. Well, we can draw on that object.

What we need is to create a simple gtk.gdk.Pixbuf and call the gtk.gdk.window.draw_pixbuf method using your widget.window object on the expose-event.

The code should look like this:

#!/usr/bin/env python import gtk def draw_pixbuf(widget, event): path = '/home/markuz/wallpapers/WMwall1024x768.gif' pixbuf = gtk.gdk.pixbuf_new_from_file(path) widget.window.draw_pixbuf(widget.style.bg_gc[gtk.STATE_NORMAL], pixbuf, 0, 0, 0,0) window = gtk.Window() window.set_title('Drawing Test') window.set_size_request(640,480) window.connect('destroy',gtk.main_quit) hbbox = gtk.HButtonBox() window.add(hbbox) hbbox.connect('expose-event', draw_pixbuf) button = gtk.Button('Press Me!') hbbox.pack_start(button, True, False, 10) window.show_all() gtk.main() read more

Trying the new wordpress desktop app

Basically looks like the wordpress.com site in a frame. And there is one thing that needs to improve, something that needs to change also in the mobile app (iPhone, iPad and possibly in Android too): Integration.

Yes, wordpress needs to integrate with the system, WordPress is by many people used as a CMS more than a blogging system. Many “news” sites use wordpress, maybe they do need to enter to the desktop/web app to write all that stuff, but others use wordpress as a simple blog system. read more

no sugar

Just to let a note on my blog, I’m starting a new challenge, no sugar week, if I can do it for one week then I’ll try to make it for another week and so on. that’s why I’m drinking coffee with no sugar.

I’m also trying to get rid of meat, so, this is also my no meat week challenge, I tried to do it last week but I failed on Thursday I think, kids wanted pizza, I wanted pizza, but they didn’t wanted the veggie one :-(. I hope I can do it this week.

I’m also doing some workout, I hope the workout + no sugar + no meat help me to get rid of this ~20 extra kilograms I have. read more

Option-arrow navigation in iTerm2 – BrettTerpstra.com

useful way to map “Option+left”/”Option+right” keys in iTerm2 to do by word jump (left and right). Although sending ^[b and ^[f seems to be cleaner.

I’ve been trying to get Option-arrow keys to move by word in iTerm2. I figured out a solution, but it’s weird. If anyone has an explanation or a better way to do this, let me know.

Source: Option-arrow navigation in iTerm2 – BrettTerpstra.com

High price on a system with a built-in “compress” feature?, who the hell runs WinZip?

I was looking for rar applications on the App Store, and I saw that WinZip was there, although the price was scaring knowing that OS X have a built in compress/decompress feature, no need to use WinZip, still, knowing that maybe some Windows nostalgic user wants to the WinZip app it would be better to have a lower price (even a free version). Why bother in paying a $99USD developer license if your app will probably sell 0 licenses.

Which remind me this:

TripMode

Just a small post about TripMode a small app (and kernel extension) that helps a lot to control which program is having access to internet, not only incoming connections but more importantly outgoing when you are on a limited connection.

Since a little more than a month I’ve moved to a place where the internet connection was not that good. I used do have 20Mb/s connection and was working perfectly fine, but when I moved here.. well.. the internet was pretty unstable and the bandwidth was like with dial-up modems. read more

I’m getting used to this

I know I said 3D touch is not the thing, but is handy. Of course, I’m used to the usual way to do things (entering to the app and then hit the action button) and I expect the apps really make use of this technology, I hope.

And talking about the device, It’s great, as you can see in my flickr photostream I’ve been using it for a couple of weeks now, pictures are great although with the bandwidth I have here (near to Guatemala) is hard to upload several pictures, not to mention videos. But pictures are fine, about 2MB in size and look definitively great (I still want my DSLR camera). In terms of performance, you can watch several videos about the 6S performance in youtube. Its also great, reloading apps happens not to often, sometimes it’s barely noticeable, sometimes it is but almost all time you won’t notice. read more