Thoughtshttps://thoughts.wallproductions.com
Software development thoughts and ideasTue, 01 Jan 2019 23:23:02 +0000en-UShourly1https://wordpress.org/?v=5.0.3Ubuntu fstab mountinghttps://thoughts.wallproductions.com/2016/06/ubuntu-fstab-mounting/
https://thoughts.wallproductions.com/2016/06/ubuntu-fstab-mounting/#respondFri, 24 Jun 2016 20:10:59 +0000http://thoughts.wallproductions.com/?p=292I recently discovered a good way to automount an external hard drive to my server. Automounting basically is the mounting of the drive when the system starts up. Pretty self explanatory. Once it’s mounted it’s good to go until the system is restarted. The issue I was having with my external hard drive as it wasn’t mounting automatically. I was manually mounting it after the system was up. Which really sucks having to do that each time the server is rebooted. The first solution I tried was usbmount. Usbmount seems to be the go to solutuion for most people. For some reason I couldn’t get that to work. It would properly install it but then would not automount the drive at all. Then I ran into a solution that works great called fstab. In order to get it to work I added the following configuration to the /etc/fstab file. Then saved and exited the file.

/dev/sdb1 /media/usb auto utf8 0 0

Now on reboot it’s able to auto mount my external hard drive without any issues.

Add

Push Tags To Remote

All Together

]]>https://thoughts.wallproductions.com/2016/06/git-tags/feed/0CanCan (CanCanCan)https://thoughts.wallproductions.com/2015/03/cancan/
https://thoughts.wallproductions.com/2015/03/cancan/#commentsWed, 04 Mar 2015 02:48:16 +0000http://thoughts.wallproductions.com/?p=220CanCan was written by Ryan Bates to make role based security simple and fast for Ruby on Rails applications. It was first published in late 2009 and was the go to role based security gem for rails applications. There were several reasons why so many developers wanted to use it. Some of those reasons were because it was fast, easy to setup and worked well. Support for the original CanCan gem ended in mid 2013. Ryan Bates decided to take a break from development all together so the gem was forked by Bryan Rite and is being maintained by him today. This allowed the gem to work with the latest version of rails and is able to keep working when new versions of rails are released. As one of the developers that use’s CanCanCan I can say that it’s just as stable as it’s ever been. It’s a mature gem by this point in time so you won’t see too many breaking changes if any.

Features

One thing that I really love about CanCan is that it gives you an ability class that allows you to define all of your roles and what they can do in one place. You can define as many roles as you want and have them share operations with little effort. Also you are able to assign multiple roles to a user. This will give you the flexibility to only have one role for one purpose. Instead of mixing roles together to fit some custom role you need. You are able to just give the user two roles instead. Another thing that I found really useful is you can pass in a set of criteria that can be applied to the role check. For example a user creates a new record. That record belongs to that user and should only be able to be viewed or edited by that user. With CanCan you can simply pass in a scope like can :edit, ModelName, user_id: user.id. This will apply this scope to the check so only the user who created the record will be able to view or change it. This is really powerful because you can do it all in one place. If you want to setup multiple roles per user simply following this guide (Role-Based-Authorization). Here is how I implemented it based on that how to.

One thing I learned while working on my project using CanCan is you need to setup the scopes for the can statements. Originally when I had developed this project I did not add these scopes on. This gave any user the ability to edit any record they had access to. So for example a user was able to view and edit a record that they did not create. This would have caused major issues if it wouldn’t have been caught before going live. Here is an example on how you can provide a scope to your can statement.

can :show, Vehicle, id: user.vehicles.map { |vehicle| vehicle.id }

This will allow a user who’s user_id is in the vehicle table and only that user to view that record. So if a user decided to change the id in the url they will get the access denied error message. You can do this with any active record call as long as it ties back to a user.

Alternatives

When originally choosing CanCan I took the time to look into a couple of alternatives. One of the major players today in rails is Pundit. When Ryan decided to take a leave from the development world a lot of people started looking for an alternative to CanCan. Since it was no longer going to be maintained. A lot of people chose Pundit. I have never used or setup Pundit fully but while doing my research I couldn’t figure out a good way to assign multiple roles to one user. Leave a comment if this is actually simple and I just missed it in the Pundit documentation. I’m sure this is possible but I didn’t want to invest the time digging through the code to find out. CanCan had good documentation in how to do so. At the end of the day I encourage everybody to do their research and determine the solution that best fits their application. I’ve seen CanCan used in multiple applications and so far it’s been able to handle everything thrown at it.

]]>https://thoughts.wallproductions.com/2015/03/cancan/feed/4Wallproductions on Railshttps://thoughts.wallproductions.com/2015/01/wallproductions-on-rails/
https://thoughts.wallproductions.com/2015/01/wallproductions-on-rails/#respondSun, 04 Jan 2015 23:14:15 +0000http://thoughts.wallproductions.com/?p=218Wallproductions is a portal like site that will contain many applications. Currently it contains a couple of applications Gas Tracker and Budget Tracker. Both of these projects are live and are in production use. Over the years it’s gone through a couple of transformations. When it was first created it was a side project. It was something to work on during the weekends to see what was possible outside of what I was doing at work. The reason why the project started was due to a lack of existing applications that did what I wanted. So I set out to create my own.

When it was originally written it was done using PHP. It started out without an off the shel framework. This was a pretty good solution for a while until the project started to get larger. The larger it got the more I thought about it. I was thinking that a framework would be needed. Unless I wanted to spend all my weekends doing tedious things that were already done in the various frameworks. As the only developer working on the project it was important to be able to complete tasks with speed. So instead of creating everything myself I could use some shared code from the framework to handle all of the standard things. Things like ActiveRecord and Routing. So I looked around and I found a couple of frameworks. At the time the Yii framework seemed the most appropriate for my situation. The reason why I choose Yii instead of the other frameworks was simply because I was more familiar with how their ActiveRecord implementation worked. Also it had a pretty good extensions library so I could reuse code shared by others in the community. So I went with that and build the second version of Wallproductions off of it. This worked well and it stayed in the Yii framework for about two years.

During this period of time I change directions in my career and instead of doing PHP development I started doing Ruby development. Specifically working with Ruby on Rails. I did not know much about Ruby or Rails when I started. But after working with it for a short amount of time I was able to be more productive than ever before. Over the course of the next year Wallproductions stayed in the Yii framework. Making additional features and fixing existing bugs. Then the Yii framework introduced their new framework Yii 2. This was a complete rewrite of the framework. So I had a decision to make. Do I want to stay on the first version of Yii for a long time, do I want to rewrite the majority of my PHP code or just move to Ruby on Rails. Seeing that I work on Ruby on Rails on a daily basis it was an option. After carefully considering it I decided that I wanted to go with Ruby on Rails. So I set off on the path of rewriting my entire site using Ruby on Rails.

The first step was to gather all of the old requirements for the system. Then I needed to make sure that I met them. This was not very hard as I was the only developer on this project. Also since I wrote the entire application myself I didn’t need much documentation to understand it. Also I needed to set milestones for myself so I knew I was progressing. I didn’t want to get stuck and then have to go back. But I also didn’t want to keep spinning my wheels if it wasn’t going to work out. As I am sure you realize we all have had side projects that we start and then never finished. I decided early on that if I was going to put a ton of effort into converting Wallproductions I would finish.

The conversion itself actually went faster than I expected. I knew Ruby was very powerful and Rails added even more power to it. What I did not realize is how much power it added. I was able to convert something that I worked up for over three years in under three months. This was not your typical conversion either since it was going cross languages. Also I was not working on this conversion process full time. I was doing so like always on the weekends or nights after regular working hours. Now that I am on Ruby on Rails I am able to complete new tasks at greater speeds. At the end of the day I am glad that it’s on Ruby on Rails. I am a huge fan of the framework and the language. Also the community around it is really good.

The goal of Chef is to give you the ability to have an immutable infrastructure. This could be for your stand alone project or for an entire business. The purpose of Chef is to be able to create cookbooks that build your servers automatically. These cookbooks enable you to build your infrastructure in a logical and object oriented way. You don’t have to come from a server administration background to create them either. Chef was built using Ruby scripts. So as long as you have programmed in the past and know a little bit about Ruby you should be all set. For server knowledge all you really have to have is a basic understanding of how servers work. You will also have to have an understanding of what components you need. After that you can browse around for cookbooks and find what you are looking to install. After you build your initial cookbook or download an existing one you will start seeing how simple it can be. I would suggest that you start out with an existing cookbook. You will start finding out that the majority if not all cookbooks you need were already built by the community. Most developers give you full access to their cookbooks Github page. If for some reason you cannot find an existing cookbook you should be able to reference others for how to do it. When I setup my Chef infrastructure all cookbooks were already created. I simply had to modify a couple of them to fit my needs.

Why use Chef

Chef has many use cases. The main one of course is the ability to have an immutable infrastructure. These days with virtualization being so hot it’s important to be able to create a new instance of your infrastructure without having to thinking about. Traditionally before Chef server administrators would write their own shell scripts. After creating these shell script’s they would run them manually after installing the fresh OS. Not only was it time consuming to run these scripts on each server but they also had to be updated all the time. For example if a new version of the application came out. So they tended to get out dated faster. So a tool came out called Puppet. The purpose of Puppet was to take all of these shell scripts and to put them into a tool. This tool would provide some infrastructure so it was easier to manage the scripts. It also allowed you to create generic scripts so when an update came out the process was easier to upgrade. Puppet allows you to define a series of scripts to run. It was definitely a step up from running all of those shell scripts manually. It was a better way to manage these scripts and keep them organized.

After Puppet was out for a while Chef came out. Chef took a lot of the ideas from Puppet and made them better and even easier to use. Chef is the tool that allows a developer to create the infrastructure. It takes infrastructure out of the hands of server administrator’s and into the hands of developers. The reason why Chef is so friendly and powerful is because it was written in Ruby. Ruby is a very elegant language and is very human friendly. Also it’s an object oriented language so it’s very easy to abstract your cookbooks.

Another advantage to Chef is it has great enterprise support. If you sign up for Chef enterprise you can configure which cookbooks run and when. Then you can run a simple knife command and it will interact with the Chef enterprise server. It will look for your cookbooks defined per server and run them in the order you put them in. You can set a different order per server. You can also set it to run different cookbooks per server. Chef enterprise is actually free up to five nodes. If you are at all interested in it it’s a great place to start. So you can create up to five different configurations for free.

How do you use Chef with Vagrant

Vagrant ships with Chef Solo integrated. It’s very easy to get Vagrant started with Chef. The first thing you need to do is get Vagrant installed and setup. You can follow the following instructions on how to do that. After you get that installed you need to setup your Vagrant file with all of your chef configurations.

The following shows some of the configuration needed to get it up and running. The first line is the operating system you want to use. For my case it was ubuntu 14.04 but you can use whatever you like. This even includes Redhat. The next line is even more important. This will tell it to use the latest omnibus version. This line tells Vagrant to install chef on the server before anything else. When you put in :latest in it will take whatever the latest version of Chef available at the given time.

This next set of code is the configuration for Chef to use. These configuration settings are what Chef Enterprise allows you to do through their nice GUI interface. In Vagrant of chef solo you have to define these in the Vagrant file. In turn for Chef Enterprise you define them using their tool.

You can also run Chef solo by itself. If you use it standalone without Vagrant you have to tie everything together. I am not familiar with that and cannot speak to how that would work. I hope that this overview helps you learn a little bit more about Chef. I hope that it at least sparks your interest enough to play around with it. Vagrant is a great place to start if you do not have a server to work with.

]]>https://thoughts.wallproductions.com/2014/07/build-your-vagrant-box-using-chef/feed/0Why use Phusion Passenger for your Rails serverhttps://thoughts.wallproductions.com/2014/05/why-use-phusion-passenger-for-your-rails-server/
https://thoughts.wallproductions.com/2014/05/why-use-phusion-passenger-for-your-rails-server/#respondSun, 18 May 2014 20:55:18 +0000http://thoughts.wallproductions.com/?p=185Phusion Passenger is one of three big players in the rails server game. The other two players are Unicorn and Puma. No matter which one you choose if you can configure it correctly and get through the setup process all of them work. All three of them are considered viable and able to handle the job. In my opinion though I feel that Passenger is the best out of the three.

Support

The first reason why I really like Passenger is because they have really great documentation. If you are unable to resolve your issue after reading through their documentation you didn’t look close enough. For example this is Passengers documentation for their nginx module. Yeah it has a ton of configuration options that you can just stick into your nginx configuration file and go. Also if you are wondering why something is not working you will be able to find the answer easily either by going through the documentation yourself or going to Google. If you Google for an issue using Unicorn you will probably end up finding it but it could take you a while. When I consider choosing a technology to use support is the first place I look at like am I able to get support and is the tool so easy to use that I most likely won’t need that support. If the answer is yes to both of them to me that is a good place to start. If the answer is yes to documentation but not to suppose I think that is an okay starting point. Sometimes you will not be able to find both.

Popularity

This one is a little controversial as the saying goes just because it’s popular doesn’t mean it’s great. That saying does hold true in some cases but when it comes to technology it usually doesn’t mean that it usually means a good sign. I have noticed that people in technology usually don’t stick with something too long if it’s not satisfying their needs. Passenger has great support including the rails core team. It also has support from some major companies including Basecamp, The New York Times, AirBnb, and Apple to name a few of them. If you would like to see a bigger list check out builtwith. Now the argument could be made that all of these companies have no clue what they are doing using Passenger but they all have very high levels of traffic and are well known as reputable companies. There is a reason why and passenger is a tool that helps them get there.

Ease of Use

To be totally honest I only have experience in running Passenger and Unicorn. I have never had the experience setting up Puma so I will only be comparing Unicorn and passenger here. Although I have looked at Puma’s documentation and it doesn’t look so bad. Unicorn seems to be pretty easy to install on a single instance rails server. You can get your rails application up and running in a short amount of time. There are a lot of Unicorn scripts out there to get you started and up and running. The problem with Unicorn is when you have to do anything outside of running one application on the server. Dealing with multiple environments on one machine is possible (I think) but it seems like it wasn’t made for that. It also feels like Unicorn isn’t fully polished yet. Small things kept coming up like shutting down a Unicorn process without using the kill command. Like that example it just feels like commands that are suppose to work don’t. Now to be honest I am no server administrator so the problem may be obvious to someone else. So if you are a experience Unicorn professional these arguments could easily be debunked. The problem is most rails developers are not and therefore that argument really doesn’t matter. A lot of companies are rolling with developers being the server administrators also so the easier the tool is the better.

Install passenger is also a very simple process. The reason why it’s so simple is it ships with an installer that installs both passenger and nginx. You also install passenger and apache if that is your goal. In my case it was nginx. How cool is it that you get both nginx and passenger with one install. If you already installed nginx it’s recommended that you remove it and then run the passenger install. Also once it’s installed and started passenger handles everything else. This holds true even when you have multiple environments running on the same server. You don’t have to do any extra configuration to set this up either. You basically create another nginx file point it to the directory and go. Of course if you are adding another application on you will have to restart nginx but not passenger. Also passenger comes with a couple of pretty cool tools to monitor memory and performance. You simply type in the following command to get the memory usage.

rvmsudo passenger-memory-stats

Yes it’s that easy to monitor your rails processes. Unicorn you have to manually so a ps -ef | grep ‘unicorn’ to see the process. I suppose there are some tools like this for Unicorn but they don’t see as obvious to use. This tool is built into passenger so you can run it from anywhere you have an application running.

At the end of the day you have to use a tool that works best for your situation. Is passenger that tool probably but if you are an experience server administrator tools like Unicorn may be better. We all have our reason for choosing our toolset but you should have justification for those reason. At the end do whatever makes your life easier. In my case Passenger made my life easier as a non server administrator.

]]>https://thoughts.wallproductions.com/2014/05/why-use-phusion-passenger-for-your-rails-server/feed/0Feedly Blog Managerhttps://thoughts.wallproductions.com/2014/05/feedly-blog-manager/
https://thoughts.wallproductions.com/2014/05/feedly-blog-manager/#respondWed, 14 May 2014 16:33:28 +0000http://thoughts.wallproductions.com/?p=176I didn’t start getting into blogs until about a year ago. So I missed the whole Google Reader era. I always thought blogs were useless for some reason. I still feel that way about certain kind of blogs but technology blogs are very useful in my opinion. It’s a good way to pick up on what others are doing. So when I started getting into blogs I noticed that I was having to bookmark a lot of pages. Not only that but I also was having to visit these blogs to check if anything was updated. I was talking with a co-worker and he said he use to use Google reader but Google shut it down. He said he recently started to use Digg Reader. I looked at Digg and also Feedly and decided that I would go with Feedly. Nothing against Digg I just thought Feedly had a bigger user based and there had to be some reason behind that.

After using it for over a couple of months now I would have to say I am glad with my decision. Not only is it a great blog manager but you also get a lot of neat features for free. The main feature of course as it shows you only posts you have not read yet. This is nice so you know I have ten new blog posts to read. Then you don’t have to filter them out yourself Feedly does that for you. Also you can read the post inside the application so you don’t have to bounce from site to site. This can be nice but you do miss out on certain content like comments. If you are not into those then this might be the way to go. Another feature of the free version is it updates the blogs every four hours. For me this is fine I don’t check posts every day even sometimes I get to it once a week.

Another thing I like about Feedly is there Android application. It seems really well made and I am able to read posts while on the go. The posts just like the website open up inside the application so I don’t have to bounce around. Also you can go to the website just like you go on the site version.

Feedly also offers a pro version which you can upgrade for only 45 dollars a year. That is a decent price and you get a lot more features. So if you are really into blogs you can do things like send them to your Evernote account or get your blog posts 30 minutes sooner than the free version. In my opinion the free version is more than what I need but others may like the additional features.

So if you are looking for a blog manager I suggest you at least check out Feedly. It’s free, easy to use and works great.

I recently had to setup multiple SSH profiles for Github. The reason why I had this requirement as my work required me to have a Github account outside of my personal account. The machine I am using is used for both work and personal development. I needed both SSH keys to work. I had never ran into this before as I never had two Github accounts. Since you are not able to use the same ssh key between multiple accounts in Github I had to come up with a way for both to work together. This makes sense for security purposes that the key should only be identified with one account. The process to set this up was pretty simple overall but that is after you understand what you need to do. Understanding exactly what is needed can be tricky at least from the documentation I found online.

The first thing you need to do is create a SSH key pair for both your personal account and work account. They should be using different email addresses.

After that is done you should have a couple of keys. For example you could have id_rsa and id_rsa_work or whatever you called them. Add the proper SSH keys to your Github accounts following Generating SSH Keys – Github. The documentation there is really well done so no further explanation is needed.

So now you should be able to use each SSH account by adding it. Everything will work at this point but you will have to keep adding the ssh-add when you switch between accounts. If you don’t switch often this may be fine but it’s a really pain if you switch often. Also you tend to forget overtime why it’s broken all the sudden.

ssh-add ~/.ssh/id_rsa

The next step is you need to create an SSH config to handle the multiple accounts.

Save and close it out and that part should be all set. The next part is the most critical. If you have an existing repo go and modify your SSH string to add in the -work or -personal. This is whatever you named your host. Here is an example for my personal project.

git@github.com:[host-name]:[repo-name]/[repo-name]

If you are adding a new clone or new remote continue to use the same host name you set in your SSH profile. After you run the process it all makes sense it looks at the ssh config to determine which key to use.

]]>https://thoughts.wallproductions.com/2014/05/setting-up-multiple-ssh-profiles-with-github/feed/0Yii CNumberFormatter FormatPercentage Suckshttps://thoughts.wallproductions.com/2014/04/yii-cnumberformatter-formatpercentage-sucks/
https://thoughts.wallproductions.com/2014/04/yii-cnumberformatter-formatpercentage-sucks/#respondSun, 27 Apr 2014 18:57:21 +0000http://thoughts.wallproductions.com/?p=152I was working on some code that I wanted to use a number formatter on. In this specific project I use the Yii framework which provides a class called CNumberFormatter to handle such things. I was looking specifically for the formatPercentage method after digging around for a little bit.

I noticed that the method only takes in a raw number. Which seems very odd why wouldn’t you be able to pass in a precision. Not all percentages should be rounded with the same precision. So for example it would take in ‘0.245’. I would expect an easy way to override the currently rounding rules. But from the documentation I read that is not possible. The rounding rules for this specific case is barred deep inside the framework in a translation file. This would work great if everybody wanted to round their decimals up to the nearest decimal. So for example the number above would round to 3% not 2.45% as I wanted. After digging around for 15 or so minutes I gave up and just rolled my own formatter. It’s a pretty big disappointment that the framework is unable to handle such a simple request. In comparison I use Ruby on Rails for my daily job and they have a method that actually takes in a precision argument number_to_percentage. This forward thinking really makes me regret not starting this project out in Ruby on Rails. Of course when you have been coding on it for over five years it’s nearly impossible to get out. So I created my own extension and am going to roll with that for now. But it’s pretty disappointing when the framework isn’t able to help in these simple situations.

]]>https://thoughts.wallproductions.com/2014/04/yii-cnumberformatter-formatpercentage-sucks/feed/0Vagranthttps://thoughts.wallproductions.com/2014/04/vagrant/
https://thoughts.wallproductions.com/2014/04/vagrant/#respondThu, 17 Apr 2014 00:28:12 +0000http://thoughts.wallproductions.com/?p=127I started using Vagrant just over a year ago. When I first started using it I didn’t know much about it. To use it you really don’t need to know much about it either. The concept of vagrant is you create your development environment in a virtual box and then use vagrant’s technology to connect to it. This connect is like a regular SSH connection but also has various other features. Vagrant basically supplies a way to make the virtual box act as a server. I recently had to create my own vagrant box from start to finish and had an interesting experience. Overall the experience was good and it went pretty smooth. For not knowing what I was doing at first I was able to get everything installed and running within five hours. That’s not to bad when you add in download time and reading about how to do things. If you need to know how to install vagrant I would follow the documentation as it was well done. While doing the instal through I found some advantages and disadvantages to using vagrant.

I see a lot of advantage to vagrant. The first of course is you can create a vagrant box and then deploy it to many machines. So one developer on your team spends the time creating the box and the rest of the team benefits by not having to create it themselves. They simply can download the .box file and vagrant up. It’s that easy. This is a great time saver when you have a team. Even if you are by yourself it can be a time saver if you ever switch machines. Another advantage is everybody on the team is literally using the same environment. This is everything from OS version down to package version. This can be important especially if a major version is the difference. You can also start with a predefined box using Vagrant Cloud. For example you could start with a fresh Ubuntu box or you could search for specific package you need installed. This can save you time because you don’t have to do all of the installation process yourself. Even thought there is a lot of good there is some downside to using Vagrant.

First you have to be running a virtual machine using either VirtualBox or VMWare. This can slow down your machine and it takes extra resources. So if you have a machine that is not very powerful this can be a huge burden. Another disadvantage is everything has to go through that server connection. So when you access localhost:3000 it has to call the virtual server and run through that. This will add a little bit of overhead compared to just running it on your local machine. This can be a little frustrating to deal with if you are use to developing on your local machine.

To sum it up I think Vagrant is a great tool and has really advanced over the last year. Vagrant Cloud looks super neat and is a great idea. To share these environments should help developers for years to come. The biggest pain for a developer is to setup their environment. Vagrant makes that whole process a whole lot easier.