Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Sunday, September 30, 2012

Personal analytics with Selfspy and Google Spreadsheets

In the spirit of the Quantified Self movement, this article provides steps to:
  • use an activity tracking daemon SelfSpy to capture the usage habits for all your applications and
  • Google Drive spreadsheets to store and graph productivity stats/aggregates

Wednesday, July 25, 2012

Weight tracking/exercise spreadsheet+

We started a protein diet with Mana a couple weeks ago and over the time I put together a spreadsheet to track your weight + fat/water/muscle percentages. The setup is simple, you just enter your height in cm. Then just enter a date of measurement together with the measured values and it gives you your current BMI. In addition to that for each of the measured values you get:

  • total difference between the first value (when you started tracking) and the current value - good for motivation ;-)
  • you can specify a target value for any of the measured variables and the spreadsheet calculates an estimated date when you reach your target (linearly considering the progress so far)
  • nice charts!
Here is a link to the spreadsheet with some sample values - just create your own copy and good luck!
https://docs.google.com/spreadsheet/ccc?key=0AnJ2BfrzQpQGdFRkcDB6XzVCLVU5RlpWZ2hoSEhvcGc

Thursday, March 1, 2012

Chord progress in Celery

On our company blog I described the new server stack we use to run 47posters.com. One part of this stack is a distributed task queue Celery. We use it for 2 reasons:

hard task throttling - we have certain more processing heavy tasks, that if spawned by all Gunicorn processes at the same time would overwhelm the RAM of the server. With celery we can start them synchronously and use the --concurrency flag to control the number of heavy tasks processed in parallel

asynchronous tasks - we have one task that can take time in the order of minutes. This task is actually a collection of tasks that can be all done in parallel and then one synchronization tasks that runs after all the partial tasks are finished.
This synchronization task is done with chord and the collection of parallel tasks is modeled with a TaskSet.

There is only one tricky part - chord returns an AsyncResult corresponding to the synchronization task. If you then query the task_id given by this result, you can check for the cord completion. What you can't do is to track progress of the taskset completion. To do this, we have to create a new chord like this:
from celery.utils import uuid
from celery.task.chords import Chord
class progress_chord(object):
    Chord = Chord

    def __init__(self, tasks, **options):
        self.tasks = tasks
        self.options = options

    def __call__(self, body, **options):
        tid = body.options.setdefault("task_id", uuid())
        r = self.Chord.apply_async((list(self.tasks), body),
                                   self.options,
                                   **options)
        return body.type.app.AsyncResult(tid), r

(I highlighted the difference against the default celery.task.chord).
Now if you call the chord like this:

result_chord, result_set =
    tasks.progress_chord(taskSet)(syncTask.subtask(params))

You will be able to get both the result_chord.task_id and result_set.task_id.

Then what remains is to create a view that polls for the task status:
def check_batch_result(request):
  chord_result = AsyncResult(request.GET.get("chord_task_id",""))
  task_set_result = AsyncResult(request.GET.get("set_task_id","")).result
  response = {}
  response["tasks_completed"] = task_set_result.completed_count()
  response["tasks_total"] = len(task_set_result.results) 
  
  if chord_result.state == celery.states.PENDING:    
    response["status"] = "pending"
    
  elif chord_result.state == celery.states.STARTED:
    response["status"] = "started"

  elif chord_result.state == celery.states.RETRY:
    response["status"] = "retry"

  elif chord_result.state == celery.states.RETRY:
    response["status"] = "failure"
    
  elif chord_result.state == celery.states.SUCCESS:
    response["status"] = "successful"
    response["result"] = chord_result.result

  return Structure2JsonResponse(response)

Friday, January 6, 2012

pdfx.sty date conversion

Hi everybody,

there has been a bazillion changes in my life (finishing the Google internship and working in my startup fulltime) and I want to sum that up in another post. This is just a quick tip for people who want to generate PDF/X files with LaTeX.

Wednesday, August 17, 2011

Looking for a job in Switzerland

My story

I came to Switzerland on the 15th of July and I already have a job, but I wouldn't say that it is easy to find a job here. It depends on your field, I'm structural engineer, so I'm writing from my point of view. I sent 22 emails and had 3 interviews until I got a job. I made a spreadsheet so I know where and when I sent an email, what they replied and more details (Danny's idea), very useful. I will write you some tips, which can help you to find a job.

Monday, April 4, 2011

Dynamic programming checklist

There are many articles that talk about this programming technique, but I have never seen complete and generic step by step tutorial on how to deal with Dynamic programming problems. So here I present mine suited to my personal taste, but you may still find it useful.

Thursday, March 31, 2011

MySql job failed to start

I've got this message from MySQL, after importing some data and building indexes. The DB stopped responding and hitting the
/etc/init.d/mysql restart
gave me the aforementioned very non-descriptive error. My problem was that the DB didn't have enough disk space for some temp files, so increasing that solved the problem.

Thursday, March 17, 2011

Python multiprocessing utility

This article talks about a simple python command line utility that lets you run your existing programs in parallel, feeding them input and collecting their output to utilize the power of a multi-core processor.

Wednesday, March 9, 2011

From webhosting to VPS

Hi all,

I have started a migration of our startup-ish project from a basic webhosting at http://www.webfaction.com to a linode 512 account over at http://www.linode.com today, which is a VPS with root access and all the related perks. The project is Django based and uses MySQL as well as some C++.
I was really afraid of the configuration, but so far it is turning out quite easy, although I am a COMPLETE noob. The steps I took so far:

Tuesday, March 8, 2011

Programátorské súťaže - návod

Programátorské súťaže sú v podstate druh športu, v ktorom si ľudia porovnávajú schopnosti s otatnými. Existuje veľa druhov programátorských súťaží, nás momentálne zaujímajú tie zamerané na algoritmy. Vo všeobecnosti v nich ide o to, že súťažiaci v limitovanom čase riešia presne definované a ohraničené problémy a na základe kvality svojho riešenia sú nakoniec zoradení.

Draw in Allplan, calculate in Scia Engineer

Here I present a "cookbook" for making 3D model of construction in program Allplan, exporting it to program Scia Engineer and making calculations there. I'm sure that there are many better ways, but this one is my best for now.