Posts

Showing posts with the label programming

Android TDD Using JUnit, Robolectric and Mockito

Image
Android now supports unit testing. Android unit testing runs on devices or emulators that adds extra time during development. I'm a big fan of TDD and the way android testing is done does not help me much. However... Thanks to Robolectric, headless testing is now possible by leveraging gradle. I wrote this post as a result of trying out several different approaches that confused me. Hopefully this one will help you set it up better. How? First, current common Android development projects are tightly coupled. Most stuffs are done in the Activity or Fragment, blame the tutorials. This makes it hard for us to actually do unit testing since a unit test should be isolated. The tight coupling makes unit testing impossible. Then, come this approach called Model - View - Presenter (MVP). MVP aims at separating concerns. The three components involved handles different concerns: Model This component groups all data related concerns. This component handles data que...

Minimalist Distraction Free Setup

Image
I got a new MacBook air at the new company I work at . Unlike my previous MacBook air, this one only runs i5, 4GB Memory and 128 SSD which means I have to preserve a lot of space to have a nice coding rig. I have to be able to code android and iOS on this one. Plus, I should be able to hack stuffs on it for my personal fun as well. So how do I deal with that? I need to reserve around 9GB for XCode, 7 GB for Android Studio + SDK and around 20 GB for basic OSX stuffs. Plus I have to reserve the iWork and iLife stuff since this is a company laptop and someone else who's gonna use it later after me. I'm a big fan of music and movies, and the space limits it. So how do I deal with it? Use the cloud. I put all my old codes in a private git repo. I stream all my music using deezer and put all my favorite movies on my Google Drive account. Now I can still have it while I run on a minimal setup. As a comparison, now I have 83.59GB of free space out of 128GB on the new ...

Been a long while

It's been a long while since I last wrote on this blog. I know. It's been almost a year but I was busy doing a lot of stuffs. Along with my team, we built a retail platform that combines augmented reality, location technology and cool analytics as one product. I also built zappr  in my free time and I have several more ideas that I want to build within 1-2 months. I have learned a lot in the past 11 months. I learned more on how to lead engineers to actually build products and how to market it. I learned how to manage engineers by treating them as normal human beings, not production machines. I believe that I have had some of the best lessons so far in my life. Also, I'm going to go for a new challenge. After more than 2 years at Ice House , I finally decided on taking up a new challenge in a product company. Make no mistake, doing services for others are cool and you can learn a lot of things. I just want to do things that I can actually pour my heart into. Build t...

Form and JSON Post Request Value to Model Mapper Functions For Flask

One of the iritating part that you have to deal with when you're handling POST requests in Flask is how you map the values into the model. It could be in JSON or in common form format. Usually this is what you do # say this is your model # using SQLAlchemy class User(db.Model): username = db.Column(db.String(50)) password = db.Column(db.String(50))         email = db.Column(db.String(50)) first_name = db.Column(db.String(50)) last_name = db.Column(db.String(50)) # this handles the common form request app.route('/process_form',methods=['POST']) def data_process(): new_user = User(                                  username = request.values.get('username')                                  password = request.values.get('password')                   ...

Simple FTP Server Solution With Python

I spent the last few days dealing with setting up an ftp server on by ubuntu vps and haven't figured out a solution. Then I tried asking my friends thru my facebook account. My friend Sakti  came up with a very simple and elegant solution using python. The solution uses pyftpdlib package. To install the package is really simple: $ easy_install pyftpdlib or $ pip install pyftpdlib after that create the folowing script and save it as a python file: from pyftpdlib.authorizers import DummyAuthorizer from pyftpdlib.handlers import FTPHandler from pyftpdlib.servers import FTPServer authorizer = DummyAuthorizer() authorizer.add_user("user", "password", "/home/user", perm="elradfmw") authorizer.add_anonymous("/home/nobody") handler = FTPHandler handler.authorizer = authorizer server = FTPServer(("0.0.0.0", 21), handler) server.serve_forever() T hen run the script and try accessing your server using ftp. Only 10 line...

Why Python?

A lot of people asked me this when I told them that I'd always prefer to use python whenever possible. The answer is: For me it is the language that is elegant, very readable, easy to use and learn and it has limitless potentials. I can develop more things after using it for 2 years compared to what I can develop after using PHP for more than 5 years. I'm not saying that the other languages are not good and that python is the best. All I'm saying is that it's the language that fits me best, makes me happy and performed accordingly to my expectation. For other uses I'd use other language as the right tool for the right job. What's your preferred programming language? Why? regards -E- follow  @femmerling on twitter. I recently revamped my website after 2 years. Visit http://www.emfeld.com if you have time

Creating Python Virtual Environment Without Installing To The System

When you develop projects in python, you often met the situation where you will need to install various packages that will clutter the general python installation in your system. Usually people will use the famous virtualenv. However, it often brings trouble when you have to run 2 or more python environments simultaneously. I'm about to share a simple trick that you can use to separate those environment, still using virtualenv but we're using it differently. The examples are in unix/linux, but the usage is quite similar in windows. First, download virtualenv.py from  https://raw.github.com/pypa/virtualenv/master/virtualenv.py . That should be done in seconds. Next up, create any folder where ever you want to create the virtual environment and copy the downloaded virtualenv.py  file inside the folder. Now, run the following command: python virtualenv.py env That will create a folder called env inside your current folder and the folder will contain your newly created...

LDAP Login Authentication Using Python LDAP

About 2 days ago, I have to create an app for internal company use. I'm using EmeraldBox to develop it. At first I created the user model to save user credentials and using it during the login process. However, the boss came with an idea that I should use LDAP login since we have it and it provides a single sign-on solution, which is better. So, I googled around and found python-ldap . You can easily install it by running: pip install python-ldap and it's ready to use. The question is, how can I use it? Check out the code I use below for references. The steps should be the same. However, you need to adjust some values accordingly to the LDAP settings in the server. It's as easy as that and you can perform login and get the user credentials. In my app, I use Flask's session to put the user credentials so I can fetch it whenever I need to. Feel free to use my code. Happy hacking!!! regards -E-

EmeraldBox: My New Boilerplate Python Framework And A Mini Tutorial

I believe that developing web apps should be done in the easiest and most efficient ways. Python offers that. However, most of the available frameworks required a deep learning curve for new users and most users have problems deploying the web app. After using several python web frameworks as well as using other languages' frameworks like Rails, Django, CodeIgniter and Zend over the years, I came to a conclusion that python is the easiest and most efficient language. However, it will require tools that may speed up development. It that sense, Rails has a very good approach and will be implemented for the helper tools. Integration with 3rd party packages should also comes easily without having the need to interfere with the main OS, hence comes virtualenv. Thus, comes EmeraldBox, an easy-to-use, light-weight, and easy-to-deploy framework. EmeraldBox comes in a localized environment and includes standard packages that are commonly used in web development. The tool includes f...

Changing Directions

I've always have a strong interest in software engineering. It is the reason why I took Computer Science in college and also why I minorred in software engineering. However, since I dont have any interest in developing desktop softwares, I only had one job as a software engineer back then in 2005. I'm always interested in the web and I established my own web software company, Emfeld. I did projects and enjoyed things with Emfeld. And so there I was, graduating from college and then from grad school working for non software companies. I even developed career paths as teachers and IT auditors. Even when I'm enjoying my career growth, I never felt any satisfaction working outside of software engineering. I took side projects and work during the night, simply to relax and enjoy things. Yeah, you heard that right. I write codes to relax. Sounds geeky? I know, and I'm proud to be one. Starting this year, my interest in programming grew even stronger. I joined a hacka...