I recently integrated a slack based logging in Flask and managed to put together a small guide as a gist, enjoy!
Log Cabin
Happy to announce my latest project, a Time Tracker for Mac called Log Cabin.
There are plenty of time trackers out there, but I have never used anything that suited my needs, so I decided to roll my own.
What makes this tracker different?
- It has a really easy to use time tracker with itunes-like controls
- Editing is super easy through a view anyone can recognize, a ical/google calendar view.
- Export with markdown support
- Being able to write comments (it sounds weird but plenty of trackers misses this)
- A progress bar so you can keep track of your daily goal (comes in the next update)
If this sounds like something for you, please try it out (we currently have a 33% discount) and let me know what you think!
Directory Based Fabricrc With Fabric
I'm a big fan of Fabric, such a big fan that I decided to base a deploy tool around it. But once small annoyance I have is how it deals with fabricrc files. If not supplied in the fab command, fabric will look for a file in $HOME/.fabricrc
. Since I always use project based fabricrc files it ends up with me having to supply fabricrc on every command call.
So I put together a little script to change this, what this script does is to look for .fabricrc or fabricrc.txt in the directory where fab is run, before looking in $HOME
.
Using The Fetch Api With Django Rest Framework
The fetch api is a pretty cool thing that can really simplify client networking code. So how would one go about to use it with django-rest-framework?
Server
First, make sure you use the SessionAuthentication in Django. Put this in your settings.py
Django rest framework
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication'
]
}
Client
Then start with including the getCookie method from the Django Docs.
Finally use the fetch
method to call your endpoint.
var myData = {
hello: 1
};
fetch("/api/v1/endpoint/5/", {
method: "put",
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken"),
"Accept": "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify(myData)
}).then(function(response) {
return response.json();
}).then(function(data) {
console.log("Data is ok", data);
}).catch(function(ex) {
console.log("parsing failed", ex);
});
Easy!
Summary Of 2014
2014 was a productive year for me. I would round it up like this: less cms/more frameworks (at work), two new side projects and a couple of open source libraries out in the open.
Work
My second year as a developer at Fröjd, while running MadeInStockholm on the side. Really enjoying this combination.
Programming
Python
I got to do a lot more Python this year, mostly by shipping a couple of Django projects, both at work and home. Also dug deeper into Flask by building a static blog generator. Spent time on tooling by creating a capistrano'ish Fabric clone. Created a couple of smaller os-libraries. Attended DjangoCon in Stockholm.
Android
Spent most of my spare time, and during summer, work time, with Android. Got more into modularity and package handling through Gradle, finally threw out Eclipse and replaced it with Android Studio. Tried out a couple of libraries, those worth mentioning are: Volley, OkHttp and ButterKnife. Java comes pretty natual to me.
iOS
In opposit of Java, Objective-C does not come naturally to me at all, I put some of the blame on XCode. So I tried out AppCode from Intellji and liked it. Started to move away from storyboard based layouts towards building interfaces programmatically. Learned package handling with CocoaPods and improved my logging with Lumberjack.
JS
Started to play around with Angular on a couple of projects, switched AMD to CommonJS, through Browserify. Unexpectedly got into a full blown Node.js project at work based on Restify and MongoDB. Attended Nordic.js - which was awesome!
PHP
Literally business as usual, since I only use PHP at work. My most memorable work this year was setting up standards and putting together wordpress boilerplates.
Tools
Besides programming languages I did changes among my dev tools. Found a screen replacement in tmux and finally replaced janus with my own Vundle based Vim package.
Projects
Spent a bit of the summer building this music discovery tool, it finds new music releases, rates them and makes them easy to access through streaming services. Lots of Django, BeautifulSoup and Angular.
A easy to use Boxee remote for Android. You can read more about it here.
Spent the first half of 2014 providing VW with a steady stream of features, mostly related to social features, as well as a more minimalistic redesign.
Open Source
Blog system built in Flask through Flask-Freeze with FTP and S3 publishing.
Python library that digs through music reviews and attempts to find the genres discussed in review.
Digs through wordpress exports file and returns a well formatted python dict.
A super simple Android logging tool that in short replaces Log
and accepts a wide range of parameters (no more casting) and gives details about the whereabouts of the log statement.
Lets you load define and load settings by xml files through Androids raw cataloge.
Uses decorators to apply fonts through a dependecy injection manner. Does not support fragments yet.
Provides a way of enabling/disabling feature flags in Android.
2015
Finally, these are my goals for 2015.
- Try out React.js
- Build something in Swift
- Play with Docker
- More Linux - more systools.
- Continue on the Vim path.
- Better mobile dev TDD
- Read more programming books (starting with Test Driven Development with Python)
- Start to use twitter again
- Tinker with Ansible
- Ship ship ship!
Trying Out Objective-Clean
A issue I have when it comes to Objective-C is consistency. With iOS I work in bursts, I can go from working 2-3 months daily with the platform, to not touching it for 5-6 months. With those routines you could end up with pretty inconsistent code. Since the language is using header files, has plenty of ways of writing code and with no clear style guide (like PEP8 for Python) I think things are already difficult to begin with.
But I still though my code was pretty unified. Until I tried Objective-Clean.
Objective-Clean is a tool built by a third party developer (non Apple) that generates and makes sure style guides are followed. It is easy to set up and works with both latest XCode and CocoaPods.
But it is not without flaws. Since the validation runs as a custom shell it can be a bit slow. I also noticed a couple of issues with the validation, these are the things I discovered:
Mistreated multiplication sign
My biggest problem is that the validator treats the multiplication sign wrong when used in a math context.
Look at this line:
float imageArea = self.frame.size.width-(margin*2);
Looks fair right? Here the validator returns the error bjClean: There should be a space before the *, but not after
. It is because it handles it as a method signature.
You can see it when you rearrange the code a bit. This passes validation.
float imageArea = self.frame.size.width-(margin *2);
Validation in comments
The validator treats comments as code, you can see this if you would type // Do this + that
with no spaces between math operators as a setting. It is not a big issue, but I would prefer if comments was ignored altogether.
Pragma mark above row collides with method closing row.
This is also a big issue. Sometimes the validator ignores the setting where pragma mark requires num lines above in favor for num empty lines below method closing brace.
-(void) hello {
[self sayHello];
}
# pragma mark Delegate
This line complains that there needs to be 1 empty row below method closing brace, while at the same time I have a 2 empty rows above pragma mark.
Conclusion
With that said, I've already contacted Code Clean (who makes the app) and will update this post with my findings. Issues or not, consistensy is for the win. The $10 the app costs is well worth it and I've already made it a part of my Objective-C toolbelt.
I've also posted my style guide here, for those who are interested.
Hello Atomicpress!
This project originated from last year when I started to experiment with Flask and Frozen-Flask to build a site generator. It was pretty cool how much you could do with a relative small codebase. (After all, Flask started as a joke[2]). I ended up building madeinstockholm.se using those libraries.
Another opportunity came two weeks ago when someone hacked my Wordpress blog and I decided to build a replacement[1]. Using the static file approach was the obvious choice, since its pretty hard to hack... Once again hello Flask.
Sure, I looked at the alternatives, Octopress, Jekyll, Pelican, Hyde (there are plenty out there), but they where heavy in features, I wanted something lighter and I like to code.
So I built AtomicPress, a lightweight, for developers, static generator built to handle Wordpress exports well. I even based the db structure after Wordpress to make users porting from Wordpress more at home, and made sure building themes and extensions would be simple. This system also ships with the ability to deploy sites to both S3 and FTP.
I will continue to make improvements where I see fit, with a rss feed as the next feature on the list.
Sounds interesting? Take a look: AtomicPress on Github. You can find a example implementation under /examples
in the repro and installing is done through pip install atomicpress
.
References:
-
My fault, since it's hosted on a shared hosting account I started ten years ago.
-
Reference: http://en.wikipedia.org/wiki/Flask_(web_framework)#History
(tl;dr: I build a flask based blog generator who handles Wordpress well. Take a look).
For Boxee - A Better Remote
![logo-promo](/blog/uploads/logo-promo-150x150.png)
I've been meaning to write about my boxee app for a while now, but hasn't gotten around to it until now.
Background
It all started when the remote for my Boxee device stopped working, I began to research and found out that it is not an uncommon issue, in fact it is propably the most common one.
I went on Google Play and looked for replacement apps instead and tried a few ones out, but lets just say, they left me with a slight nausea (have a look for yourself).
So I decided to write my own remote, after about two weeks of spare time work I managed to get something up and running. Something I would end up naming "A Better Remote - For Boxee".
Under the hood it's a straightforward Android app that is optimized for 4.0 (ICS) with okhttp from square as the most prominent third part library.
The tricky parts.
- The keyboard. Getting the keyboard to display correctly was harder then it looks, by using a command called `getKeyboardText` a xml dump is retrived that contains keyboard visibility. That command is then used for pinging the device for visibility.
- Discovery. To find the actual device was tricky, by broadcasting on port 2563 with a hard coded shared key, challange and application we get the necessary details, achieved with DatagramSocket and DatagramPacket.
- Lag. One of the features of the app is the hold down to repeat button functionality, the problem is that since the Boxee sports a traditional web server (Apache?) to receive the commands they are sometime queued, which results in lag. I avoided some of the lag by acually slowing down the interval commands are sent.
Release:
I went on to sell it on Google Play. I did not expect a lot of downloads, but it is performing better then expected, with a 4.6 rating and 82 purchases.
So if you are looking for a Boxee remote replacement, please try it out, let me know what you think!
Authorizing A Rdio Application In Django
Applog On The Central Repository
You can include it as a dependency like this in your build.gradle:
dependencies { compile 'se.marteinn.utils.logging:applog:2.1.2' }For anyone interested in publishing libraries to The Central Repository, I recommend reading Publish an aar file to Maven Central with Gradle. I also recommend using gradle-mvn-push for publishing.