Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

24 September 2012

Geek goes to PyCon PL 2012 - day 1

Last week, I went to my first programming conference ever - PyCon PL 2012!

Here's what I wore on the first day:


I fooled a few people that I worked at Google, which wasn't my intention, but this misunderstanding was promptly explained.

Day one was mainly the trip there and being too tired afterwards to party like it's PyCon 2012. Still, the lectures were rich in content and very interesting.

Łukasz Langa talked about Ralph, an asset management system for your data centers. Written in-house to manage the biggest cloud in Poland, it is now open-source. Łukasz talked about how Ralph was born: out of need, when adding new admins wasn't helping to keep the huge and varied infrastructure in order. The beginnings were tough, as there was only one developer and no process like scrum was in place. This one developer wanted to do everything for everyone, which of course couldn't work well. The solutions for this situation were:
  1. more devs
  2. applying scrum by the book (I never knew that in the real scrum, a task from outside the sprint cancels the entire sprint!)
  3. git workflow
  4. one good changelog
  5. one good backlog
  6. thematical sprints.
 The second talk was by PyCon PL's youngest speaker ever, 18-year-old Marek Šuppa. He talked about programming Lego NXT robots with Python and how he taught it to kids. He created his own IDE, nxtIDE, complete with a simulator, for that purpose. The show was the best part:





 The third talk was by lvh, about fractal architectures. Big data is big these days and everyobody is scaling up - but why not scale down first? Why not, for example, shard your data by user and for every user, set up a separate SQLite database? Once you've scaled down this much, scaling up is easy. Well, except when it's not. Some problems arise, like wide queries for statistics, global, non-user-specific data, handling transactions... Depending on your project, these issues might be bigger or smaller and a fractal architecture can be a good solution for you or not. It's not a silver bullet, but definitely an interesting concept.

The last talk on that day was about forms in Python, their challenges and existing solutions. Szymon Pyżalski presented them, along with a framework of his own: Anthrax. (See his page for PyCon materials and more on Anthrax.) Szymon works for STX Next, the daughter company of my previous employer. Having dealt a lot with forms at that job, I knew exactly what Szymon was talking about. :) Since my current job is so different, however, (I basically have one big form!), I wasn't very interested in the details and didn't take many notes.

After the talks, I had a few drinks with STX Next people, then went to sleep.

To be continued...

06 August 2011

Blogging my thesis - second edtition

Ladies and gentlemen, welcome to the second edition of "Blogging my thesis".

This time, I'm doing a cloud version of the Sage Notebook. I'm doing the front-end in ASP.NET MVC 3 with C# and Razor, the back-end in Python and an SQL Server database in-between.

Since a screenshot is worth around 1024 words, here's a little preview:


The good news is that it's cool and I'm learning a lot while writing it (like MVC or jQuery).

The bad news is that it's due on September the 30th. I wished to have it finished by the beginning of next month, but I'm afraid it will take too much work.

Well, however it turns out, it's cool.

07 August 2010

Silverlight 4 with C# and Python (it's three!)

I recently felt like making a new Silverlight 4 app, but not just any app. I wanted it to have the following features:

  1. use an existing Python library
  2. be written in C#.
There is a way better way of using Python code - it is to write the app in Iron Python from the start. Picking C# to achieve that sounds like a bad decision.

However, I wanted to do something new and challenging, so I went for C#. Doing it on my own was hard, way harder than just following an "embedding Python in C#" tutorial. Finally, I found that working example and got something starting from there.

What I got is a three on a golden background:


Okay, maybe that's not the right angle to start with. What I did was used the numbthy Python library and used it's gcd function to compute the greatest common divisor of 15 and 3, and it's three!

Getting there was hard. Finding the right libraries to embed Python, importing them the right way were tough tasks for an inexperienced user - some error messages would be very cryptic. Then, the app would hang on the splash screen if something was wrong in the Python code, the debugger wouldn't show where the problem was, and the "problems" in the Python code were:
  1. the print statement
  2. a class inheriting from object.
Not obvious, and definitely not the kind of problems PyDev would warn you about. So I am afraid that importing bigger chunks of code could be hard - that is to be explored further.

05 June 2010

Rijndael S-box Sage implementation

It's no secret I like Python and Sage a lot. Today, I had the pleasure of working with Sage again: as a school assignment, I was required to show the calculations that prove that the value of the Rijndael S-box in row 2, column d, was indeed d8. While I am able to invert a polynome of this size by hand (let alone apply an affine transformation), I see no reason to do it, as a suitable tool is available.

So, here we go, the Rijndael S-box in Sage:

F.<y> = GF(2, name='y')[]
K.<x> = GF(2**8, name='x', modulus=y^8 + y^4 + y^3 + y + 1)

bin_digits = lambda h: [((int(str(h), 16))//(2^i)) % 2
for i in range(3, -1, -1)]
bin_poly = lambda n : sum([b * x^(3-i)
for i,b in enumerate(bin_digits(n))])

b1 = 2
b2 = 'd'

s = x^4 * bin_poly(b1) + bin_poly(b2)
p = (1/s).polynomial().coeffs()
p.reverse()

b = [0]*(8 - len(p)) + p
b.reverse()
c = [1,1,0,0,0,1,1,0]
d = [int((b[i] + b[(i + 4) % 8] + b[(i + 5) % 8] +
b[(i + 6) % 8] + b[(i + 7) % 8] + c[i]).n()) % 2
for
i in range(8)]
d.reverse()

s1 = sum([d[i] * 2^(3-i) for i in range(4)])
s2 = sum([d[i+4] * 2^(3-i) for i in range(4)])

print hex(s1), hex(s2)

I admit: the above is code, not calculations, but I did the calculations in class and worked hard on the code. My main problem was the bit order. Nowhere in the original publication did it say to reverse the bytes. Adding all the reverses was a moment of desperation, and imagine my surprise when it worked. I wonder how much credit that solution will get me.

A great Friday night it was.

14 November 2009

Why I love Sage in 6 simple lines

This is why I love Sage:

e = sqrt(log(4*B) / log(P)) + (5 / (4*d))

g = [P^(a - i) * (x*B - R)^i for i in range(a)]
h = [(x*B - R)^a * (x*B)^i for i in range(d - a)]

m = matrix(Integers(), d, [list(k) + [0] * (d - len(list(k))) for k in g+h]).LLL()

w = sum([x^i * m[0][i] for i in range(d)])

return filter(lambda x: x[0].is_integral() and gcd(P, x[0] - R) < P**e , w.roots())

(That's a crucial part of my thesis.)

04 October 2009

I got to level two at Project Euler

I just got to level one at Project Euler - four months after reaching level one. Here's the well-deserved cube:


I'm still writing practically only in Python. The problems are getting more difficult and so is getting to the next level - I need to solve 50 more problems to get an octahedron. That's a nice 2010 resolution.

Anyone else doing Project Euler?

06 June 2009

I got to level one at Project Euler (and would like to thank my boss and everyone...)

I go to level one at Project Euler! I got this pretty picture as a reward:


Now what does this have to do with my boss...

First, let's precise that the term "my boss" means "those guys who make the decisions and I don't know which one decides what" - no sucking up! So, "the boss" transferred me to a Python project and with a bunch of guys, we're learning Python.

Remember how I wrote I started learnig Python by solving Project Euler problems? Well, that's what we're told to do at work! There's a contest going on, in which many problems are from there, so when I solved one, I submitted it both to work and Project Euler and it was the last one I needed to get to level one, so here I am.

Can something be more motiviating than a contest at work? I have to code...

19 December 2008

Yet another programming language

I blogged about learning Java and C#, and here I am again, learning a new language again: Python.



They made me. At work. First, I was a bit mad: I'm learning Objective Caml at school, C# for the 70-536 exam, can my brain take much more?

But as soon as I tried it, I loved it for the easy syntax and operations on lists. It also supports supports multiple programming paradigms (primarily object oriented, imperative, and functional) - how cool is that?


Okay, so I started learning. First thing I did was, of course, "Hello, World!". Then, my new favourite way of learning programming languages - Project Euler! That was cool - doing something I love, learning and getting paid! Ain't I a lucky geek?