Friday, January 18, 2013

Copyright laws

I was recently thinking what is wrong with this world. I mean, why the hell netflix streams only to US? Yes, I know the reason, that they have rights only for US, but why?

Why are modern (well, actually the problem is that they aren't very modern) copyright laws so wrong? I am not requesting that it should be completely fine to just copy stuff all over internet (while it's a dream :D ).

But take netflix (and his content providers) as example. I WANT to give them my money. I WANT to pay for stuff (come one, 8 bucks per month? that very nice). But I can't, because I am from Europe. And believe me, in my country there simply isn't possibility of just buying most of movies and series. Not from home over internet.

So, netflix (all copyright laws in general) is forcing me to piracy. Because there is not legal easy way to get that content.

To sum up, I just put it this way: I want to give them my money, why the hell they don't want them?

Thursday, January 3, 2013

Keyboard switcher for awesome 4.5+

So there was Awesome update recently, which totally changed syntax of rc.lua (or at least how Awesome uses this language). I have very little changes in rc.lua, mainly widget for changing keyboard layouts.

What I did is that I deleted my old ~/.config/awesome/rc.lua, copied the default one (on Arch linux it is in /etc/xdg/awesome/rc.lua) and recreated widget for switching keyboard layouts.

So here's code of widget:
-- keyboard switcher
-- Keyboard map indicator and changer
    kbdswitcher = {}
    kbdswitcher.cmd = "setxkbmap"
    kbdswitcher.layout = { { "us", "" }, { "cz", "qwerty" } }
    kbdswitcher.current = 1  -- us is our default layout
    kbdswitcher.widget = wibox.widget.textbox()
    kbdswitcher.widget:set_text(" " .. kbdswitcher.layout[kbdswitcher.current][1] .. " ")
    kbdswitcher.switch = function ()
       kbdswitcher.current = kbdswitcher.current % #(kbdswitcher.layout) + 1
       local t = kbdswitcher.layout[kbdswitcher.current]
       kbdswitcher.widget:set_text(" " .. t[1] .. " ")
       os.execute( kbdswitcher.cmd .. " " .. t[1] .. " " .. t[2] )
    end 
-- Mouse bindings
kbdswitcher.widget:buttons(awful.util.table.join(
    awful.button({ }, 1, function () kbdswitcher:switch() end)
))
you can just copy&paste this into your rc.lua (I have it under definition of mytextclock widget) and it should do the trick.

Don't forget to add keyboard switcher to your widgets to display, I have it after clock widget in right corner:
right_layout:add(mytextclock)
right_layout:add(kbdswitcher.widget)
And if you want to use keyboard shortcut in addition to mouse to switch layouts, add this to globalkeys array:
-- Alt + Right Shift switches the current keyboard layout
awful.key({ "Mod1" }, "Shift_L", function () kbdswitcher:switch() end),
I hope this will be useful to anyone ^_^

PS: yes, for those of you who noticed, the widget is not my by origin, I merely updated it to work under awesome 4.5

Sunday, November 18, 2012

pyicmp (ping in python)

I'm  writing program for my programming class this semester (more about it later) and I needed some means of doing ping and traceroute in pure python, because just parsing output of ping (traceroute) commands is not very reliable or cross-platform.

So I created library which uses raw sockets and Internet Control Message Protocol (ICMP) to do basically anything with ICMP allows, but I focused on ping and traceroute.

It's probably only IPv4 (IPv6 was not tested and it's not supported, however some messages may work, I didn't study ICMP6 to see which messages are the same). IPv6 support is planned.

Usage is very simple:

ping:
import pyicmp.ping
p = pyicmp.ping.Ping('1.2.3.4')
traceroute:
import pyicmp.traceroute
t = pyicmp.traceroute.TraceRoute('1.2.3.4')
Yeah, it's that simple.

See docstrings for each classes for more details.

Oh and there is one bad thing... It requires root (administrator for windows) permissions and it'll remain this way, it's not possible to bypass this problem.

You can clone from here: git://github.com/volftomas/pyicmp.git

Wednesday, August 15, 2012

Easymail

I needed simple way for sending emails from python (debug info from server app), so I created VERY simple library to wrap smtplib into something more useful. Here is a link:
https://github.com/volftomas/easymail

Friday, August 3, 2012

Claws mail python plugin

I am using Thunderbird right now, but as I got new PC I will be installing Archlinux on it, so I ask myself if it's time to move to something lighter and more extendable by plugins.. as I like Python, using python as plugin language would be great.

I picked Claws-mail which is a great, capable and lightweight email client supporting both GPG encryption/signing and Python plugins..

But there is virtually no documentation on writing those plugins :'( So I just tried it, open console from claws-mail menu and tried it as described in demo.

But I got
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'clawsmail' is not defined
When I tried accessing clawsmail modul. After a while, I found that all you need to do is first import clawsmail modul.
import clawsmail
Simple ^_^

I will probably make some kind of tutorial for this (python plugins in claws mail) so no one else have to do the "digging".

Tuesday, July 31, 2012

lookbehind regex in PHP

Today, I was facing a problem how to split something like following text
a="Some Text" b="Some more Text" c="Even more text about \" this text\"" d="aaaaaaa"
into array, into pairs key => value. I couldn't just use explode(), because spaces could be inside the quotes..

After a little searching, I founded that solution lies in lookbehind regular expressions.. Nifty things ^_^

This
/(?<![\\\|=])\" /
expressions would split it into following array:
array (
  0 => 'a="Some Text',
  1 => 'b="Some more Text',
  2 => 'c="Even more text about \" this text\"',
  3 => 'd="aaaaaaa"',
)
so exactly what we wanted :)

Tuesday, July 24, 2012

YaCy on Archlinux

Today I decided to deploy YaCy on my VPS running Archlinux. I installed package and all went well until I noticed, that no images are being displayed. After some searching (30 minutes?) I finally figured it out.

To correctly show (generated) images, YaCy requires X Server and libcups, even on server running only in console.

I already requested adding those two packages into dependecies, but until it's done, if you having problem running YaCy without X server, just run "pacman -S xorg-server libcups" and it should be ok.