Ben Lobaugh Online

I think, therefore I am. I am, therefore I sail

Quick tip to access protected properties in PHP object

Calling an object that has a protected property that you need access to? This function will allow you to quickly access data stored in protected properties of PHP objects.

Note: I tested this on PHP 7.4. It will likely work on other versions, but may need tweaking.

Good developers will protect the internals of their objects with private and protected scopes. That means from outside of the object your code will not be able to access whatever is protected. What I am about to show you breaks that encapsulation. Generally, this is not something you want to do, however, if you are working with an object you have no control over, it may be necessary. I ran across this while working with an object from an external library.

This method works by typecasting the object to an array. You can then access the property using a little known method.

Let’s see the code!

    function getProtectedValue( $object, $prop_name ) { 
        $array = ( array ) $object;
        $prefix = chr( 0 ) . '*' . chr( 0 );
        return $array[ $prefix . $prop_name ];
    } 

Photo courtesy of Unsplash https://unsplash.com/photos/Vp3oWLsPOss

Finally- A Diet That Works! My Experience With Intermittent Fasting

I was huge, giant of a man…. but in the wrong direction. Hey, I like to eat ok? Though I am always busy, I am not particularly active. In the last few years the pounds have really packed on.

I felt yucky and uncomfortable in my own skin. A change was needed, and quickly.

When it comes to what I eat, I am pretty lazy. Whatever is quick is what I will grab, which usually also means the most unhealthy. Knowing my history of not putting much effort into meals, I knew that whatever diet I went on had to be easy, in the extreme. No special foods, or big meal prep days. I would fall off that wagon quickly.

It was at this point a coworker introduced me to Intermittent Fasting (IF).

Fasting is simple, just do not eat. Well, that solves one checkbox, but I was concerned about lack of concentration, energy, and focus.

The more research I did into IF, the more benefits for the body and brain I uncovered, and then I ran across this video by Dr. Jason Fung and was hooked.

I committed to trying IF for one month, decided on the 16:8 model, and set a date to begin (I had to finish all the cookies in the house first!).

The 16:8 model means you fast for 16 hours and have an 8 hour window where you can eat. 16 hours is the shortest amount of time that will put your body into ketosis, or the first level of fat burning.

The first day was surprisingly easy, and the second, and the third, and the first week, and the third week. In fact, it has all been easy. Before starting IF, I was often hungry, and if anything, knowing I was working toward a goal made it easier to go without food and remain a good human. My energy level has gone up, not down.

As it so happened, with my work schedule, I have averaged 19.5:4.5 for the past month and a half. That puts my body in a much longer state of ketosis, which lets it burn more fat, more rapidly.

The effect has been noticeable. Not only to I feel thinner, and look thinner, it is also much easier to breathe. Activities that were quickly tiring me out before I easily power through now. I also feel a lot more alert during the day, and sleep better during the night.

During this first month and half I have lost twenty pounds!!!

Here is a before and after shot. The side view looks similar in the photos, but in real life it is quite different.

My wife asked me what is next, and I told her I am going to keep on the IF bandwagon! I am making a couple changes however. I enjoy the time together with my family during breakfast and have designated Saturday as a day that does not have strict IF, so I can enjoy the time with them. I am also experimenting with OMAD, or One Meal A Day. After 19.5 hours of fasting, I have something to eat and a couple hours later is dinner time. I have naturally seen a shift to OMAD for several days now already.

My conclusion- Intermittent Fasting is a great way to diet and lose weight. There is no food tracking, no food prep, no extra money spent, in fact you save money by not eating! Perhaps biggest of all, since you are not eating, there is no temptation to “cheat” and add that extra scoop of whatever your diet restricts you on.

If you are looking for a weight loss diet, I highly recommend checking out IF. To start, watch Dr. Jason Fung’s video. From there, do the research you need to understand the process.

And as always, I am not a doctor, nor a medially trained person. What I have shared here is my experience, which may not be typical. Consult your doctor before making any life changes that may affect your health.

Unchained developer

The Unchained Developer- Free Your Workflow and Become Device Agnostic

Back in 2011, I was getting frustrated with my aging development machine. It could barely keep up with me, though I resisted getting a new machine because it can be so frustratingly time-consuming to set up a new machine. As I pondered what to do a thought struck me, “you are a WEB developer Ben…. DUH!!” Right, thanks self. The web does not care what device is connected to it. Why couldn’t I also be device agnostic? 

With that in mind, I set off to see if I could truly unchain my development and work from a specific device, and operate from anywhere. Not only was I successful, but I have also been using the same setup for nine years. I have even created patches from my iPhone while riding a city bus to meet a friend for coffee!

If you’ve been pondering the same, I  would like to share how, with a little effort and very little cash, you too can become an unchained developer.

I started out with some strict criteria in mind:

  • Cheap
  • Accessible from anywhere
  • Simple file management
  • Strong security
  • FAST
  • Flexible
  • Ability to tap into other systems
  • Smooth editing experience

Step One – Decouple the development environment

Like many developers, I was running a (M/L)AMP stack on my machine. That meant installing Nginx or Apache, MySQL, PHP, and all other necessary packages directly onto my machine, but what is a web server? Generally, for my work, Nginx or Apache, MySQL, and PHP. It was easy enough to transition those components to a remote machine.

After some research, I selected Digital Ocean as my host of choice. Digital Ocean has been very good to me, over the years. Their offerings are easy to understand and their cost is super cheap. I started with the $5/mo server, and, if your criteria are similar to mine, I recommend you do the same.

When I need more horsepower for running data migrations and other intense processes I simply tell Digital Ocean to temporarily upgrade the machine. In a matter of minutes, I can go from a small, single-core machine to 32 cores and 3,840 gigabytes of RAM! Because Digital Ocean charges by the hour, I can run hefty scripts and only spend a couple of dollars when temporarily upsizing, vs sometimes days of processing data on the smaller machine size. 

The primary limitation I have had to contend with is storage space. Digital Ocean to the rescue again!  They offer a service called “Volumes” that mount directly to the machine. The volume interacts just like an attached hard drive, and you only pay for what you use. Volumes scale up to terabytes in size. I started with a 50 gigabyte volume, at a cost of another $5 per month.

At this point, the hosting cost is $10 per month. For the cost of a coffee and a pastry, I successfully removed my local machine as a barrier for hosting development sites!

Server security

When my laptop was the development environment, the sites and databases were, by default, kept out of the eye of the general public. With the move to the Digital Ocean server came a new concern, security of my client’s data. An unauthorized person stumbling upon one of these sites could have dire legal consequences for both me and the client. 

Digital Ocean provides free firewalls; easy to provision and with a simple UI for management. Using this firewall, I blocked all ports except the web (http, https) and ssh. I went one step further and limited access to only an IP whitelist. This list is manually managed. It does make accessing the server a bit more onerous while traveling, but adding and removing IPs by hand provides a visual indicator that security is tight, and only those machines that need it have access.

Safe on dropped connections

When running a long script locally, it is no big deal to pop open a terminal, start the script, and walk away, trusting it will continue. When running a script via ssh on a remote server you enter a whole new ball game. I needed to have the same confidence that scripts would continue to run whether my connection dropped or not. Enter tmux.

Tmux is an incredibly powerful tool. At its heart, tmux is a terminal multiplexer. Meaning, from a single terminal session, you can create splits into multiple shells, each running its own commands, and different panes. The most important feature to me, however, is that tmux keeps its terminal session running even if you are no longer connected via ssh. That means I can run a command and walk away with confidence it will continue to run. Heck, if I am on a laptop I can turn the laptop off and tmux keeps that command running. 

With tmux, I can even connect from a different device to that same session. That is, in fact, how I was coding from my iPhone while riding a city bus. I had the files open on my laptop in tmux and vim from before I turned off the laptop. I reconnected the ssh session from my phone and BAM, instantly back in the editor, right where I left off.

Another great benefit of running commands on the server is that it consumes zero local resources. That means whether I start the command from my MacBook Pro or my iPhone, it will run without creating a burden on my local device. 

Docker for simplicity

I did not want to get locked into a difficult to manage web server solution and I desired the flexibility to utilize different versions of software, and different types of servers, such as Nginx, Node, and Apache. Docker is a natural fit. It allows me to run client projects in complete isolation of each other.

My preferred way to structure a client project with Docker is:

  • Nginx reverse proxy – Takes care of domain lookups and routing to the proper client site
  • MySQL – I run a new MySQL instance for each client, to prevent information spillage between private client databases.
  • Service 1 (Such as Elasticsearch)
  • Service 2 (Such as Redis)
  • Service N (Whatever else is needed!)
  • Webserver

File management

So far, I have solved the web server side of things. Now I need to get files to the server to develop on. There are three methods typically used:

  • sftp/scp
  • Github/git
  • Direct download

sftp/scp

Both sftp and scp allow you to connect to a remote server to send files. I prefer scp as it is simple and comes with all ssh clients, meaning it is available out of the box on Linux and MacOS. This is the method that I typically use to get local files to the server.

Using scp to transfer a local project to the server is as simple as:

$ scp -r local_project_folder server:/path/to/projects

As a bonus, scp can work in both directions. Call the server first to retrieve files from the remote machine.

Github/git

My preferred method of assessing project code is via a git repository, such as Github. A simple git clone and your files are available on the server. I typically do this via an ssh cli, in fact, I really enjoy the cli so most of my work is done via cli. 

Once the project is pulled from git and all the build tools are installed, you will be able to run composer, npm, grunt, etc., just like you would locally.

Direct download

At times, I may need to download a file directly. Prior to working on a remote server, I would be at the mercy of my internet connection. Let me tell you this, I lived on a boat for nearly four years and the internet was slooooow. If a client sent me a database, it would take all day to download. The Digital Ocean, server has a crazy fast connection and the same download now takes minutes, if that. This saved a ton of time and angst over dropped downloads. The file needed to be on the server anyway, so downloading direct prevented two days’ worth of file transfers!

The wget tool is my go-to tool for downloading due to its simplicity. Curl is also a great option, though. Downloading a file with wget is as simple as:

$ wget https://example.com/file.zip

Smooth editing experience

When it comes down to it, editing text is the primary job of a web developer, therefore, having a smooth editing experience is crucial.

Being a long time Linux guy, and lover of the cli, I naturally turned to vim as my defacto editor. 

Now wait a minute, before you go smirking to Sublime, or VS Code, or whatever the current hotness is, recall that vim has been around for ages. It has a robust plugins system integrating every functionality you can imagine. Not only that, using vim directly on the server frees me from any reliance on a local editor or IDE. I have the freedom and flexibility to really program from any device I desire. I have worked from all sorts of devices: MacBooks, iPhone, iPad, Android tablet, multiple flavors of Windows, and Linux with complete freedom to open a file,  edit, and then reconnect, exactly where I left off from another machine.

A few years back, a buddy scoffed at my “cute little [vim] editor”. He was proud of his Sublime setup. It really was rather nifty. I mocked him right back saying, “vim can do anything Sublime can do, better and faster- and you call yourself a Linux guy….” He laughed it off and we carried on with our projects. The next morning he called, sounding a bit off. “Remember when you made fun of me yesterday for being a ‘Linux guy’ and using Sublime instead of vim?” “Yeeesssssss,” came my hesitant reply, not sure where this was going. “Well,” he angrily spat , “That comment bugged me all day. I decided to pull up vim and prove you wrong! I stayed up all night, trying to prove you wrong and you know what happened? I have a really cool vim setup that is identical to the Sublime setup! I deleted Sublime.”

True story, I swear!

All joking aside though, most editors and IDEs these days do support ssh. It is likely that whatever editor you prefer to use will still be compatible with remote development. Check out the editor support articles for guidance.

That’s it!

And that is really all it took to unchain my development workflow from a single machine and free me up to work anywhere, on anything. I no longer worry about a laptop dying on me. If it goes up in smoke, I can grab my iPad and be back up and running as fast as ssh reconnects. 

Bonus Round – Mobility

I wanted to see how far I could take the unchained approach and continued to push the envelope. To this day, there is nothing I run that requires a specific machine. The “move to the cloud” movement has only made things easier. 

Here are some of the other things that allowed me to become 100% unchained from a single machine:

Communication

  • Webmail, or IMAP connections, via an app
  • Slack facilitates instant team communication. There are apps for everything and a web UI as a fallback
  • IRC. Yes, IRC. The first chat groups I was ever part of were via IRC on the Freenode network, where I am still active today
  • Zoom. Great video conferencing software that requires very little bandwidth to operate

Connectivity

  • In-home wifi
  • On the go, the cell hotspot hits the spot
  • Most coffee shops and many public spaces have free wifi now

Secure connections

  • Use a VPN to prevent traffic snooping
  • SSH tunnels can also be used to route traffic directly to the server

I hope this article has inspired you to become an unchained developer and saved you some time in the process. I love the freedom and stress reduction it has afforded me. If you have a low powered machine that struggles under the weight of your development environment, this could save you big $$$ on an upgrade!

Are you already an unchained developer? What tips and tricks can you share in the comments?

Questions or need help designing your unchained server? I am happy to help you find an answer. Drop me a line on my contact page

Ecco Pro filtered tank

Eheim Ecco Pro Canister Filter Review

This post may contain affiliate links. If you buy something through a link I will receive a small commission from the seller, at no additional cost to you.


With the upcoming build of my 90 gallon aquarium, I have been using my 30 gallon tank as a bit of a testbed for exploring different filtration methods. Thus far I have implemented an under gravel and a homemade sump.  Both have worked quite well. In this article, I will share the results of using the Eheim Ecco Pro canister filter. 

Ecco Pro

For three decades I have turned to under gravel filters as my filtration method of choice. Though incredibly simple, I will always contend that, when properly set up, the under gravel filter is a fantastic choice.

The sump was not your traditional sump, it was made from a 5 gallon bucket. I posted details on it in this article. It took some fiddling to get it, but in the end, it did the job it was supposed to do and kept the water a lot more clean than the under gravel filter. However, the wife was not a fan of the running water noise it produced, so back to the drawing board. 

While visiting my parents, I took a look at my father’s fish gear cabinet. There are things in there that have not been made in decades! It is a treasure trove, and in the corner of that pile, I spotted an Eheim Ecco Pro canister filter. I had found my next filter to test!

The hoses were missing and it was covered in thick, crusty, dust. My father did not know if it worked. I brought it home, disassembled it, and cleaned it up. When I first popped it open I was pleased to find it had three media compartments, which still contained Eheim’s glass beads. The Eheim Ecco Pro is a small canister, which gave me pause, 30 gallons is not a big tank, would this provide enough filtration?

Ecco Pro Media Baskets

The Ecco Pro is an outside-in filter, meaning that water comes into the canister around the outside of the media baskets. It is then sucked up from the bottom and through the middle of the media baskets. Water then gets pushed out the top via a return pump, and back into the tank. 

With filtration, there are three components that go into every system: mechanical, biological, and chemical. Unless you are an advanced fish keeper, they should also go in that order. When I looked at the order in the Ecco Pro baskets, I noticed the biological filtration was before the mechanical. Not only that, but Eheim’s own manual also shows it that way! For an otherwise great product, this misinformation disappointed me. Not to worry though, the baskets are highly configurable. I simply swapped in some of my own filter floss and moved the biological filtration later in the stack. 

Ecco Pro Sink Test

The Ecco Pro has been running on the 30 gallon for a couple months (as of the writing of this article). The numbers on my water test kit are consistently on target. The pump is nearly silent and there is no water flow noise, a big plus for my wife. I was able to use some common hose that I picked up at the local hardware store for cheap. 

Ecco Pro filtered tank

Would I use a canister filter on the 90 gallon tank? Yes, but not an Ecco Pro. 30 gallons is the max I would consider using it on. 

Do I recommend the Eheim Ecco Pro canister filter? Absolutely! It is a great unit, quiet and compact. The Eheim glass bio-media works well. Just make sure you put the mechanical filter in front of the biological or the biological media will gum up real fast and become ineffective. 

Link to manual

Check prices on amazon. 

Photo by Marcus Cramer on Unsplash

How to Stay Calm Amidst a Crisis

This post may contain affiliate links. If you buy something through a link I will receive a small commission from the seller, at no additional cost to you.


COVID-19 has thrown our world into crisis mode. A few weeks ago, most of us had never heard of a coronavirus, but today it is all we hear about. Our friends and family talk about it, and the media drones on incessantly, adding more fuel to the fear.

How do we combat that fear? How do we get back to a calm, cool, and collected existence?

Managing a crisis well comes down to where your focus is.

Your emotional state follows where your focus is.

A buddy, let’s call him Billy, and his wife have been on edge since the government’s social distancing guidelines came out. Their TV has been constantly on and fixed to various news channels. All they hear is doom and gloom. They are a younger couple, solidly in the age group that is less likely to be affected by the virus, and yet they are terrified to leave their house.

Meanwhile, across town I have another friend, let’s call him James. While taking precautions, James and his wife have largely continued about their life. While James’ wife is out taking care of family, James has been working hard, preparing their boat for a summer cruise. In the evening, after their dinner meal, they listen to the latest updates in the virus. Though they can cite the stats, and are in the most vulnerable age group, they are unafraid.

They are both experiencing the same crisis and choosing to approach it from different angles.

Though Billy is in the safer group, he focuses on the negative. The fear being hurled at him through the airwaves is a never-ending torrent, reinforcing his fear and blinding him to the good around him.

James, on the other hand, has chosen to stay informed on the crisis, but focuses his attention on the good things, his family, and the vacation they will soon be enjoying.

What you choose to focus on defines your state of mind.

Focus on the negative and fear will overwhelm you. Focus on the positive and you can still experience joy in the midst of a crisis.

That can be easier said than done though! Here are a few battle-tested tips that have helped me weather many storms and come out stronger on the other side.

Assess the situation

Pause to carefully assess the situation. How big is it really? How long is it likely to last?

In his book Vision Blockers, my friend and mentor, Eric Scroggins presents fear as the acronym:

False
Evidence
Appearing
Real

Fear often causes situations to seem much worse than they actually are.

Carefully monitor external influences

Our emotions are highly susceptible to outside influences. What is influencing you? Take control of external influences and be sure they do not have a negative impact on your life.

Tim Ferris, in his book The 4-Hour Work Week, writes about the negative effect that consuming too much news media can have on your mental health. He advocates for a dramatic reduction in intake. I was skeptical, but tried his method and noticed a quick uptick in mental well-being.

Trust yourself

Your skill and experience has not left you! You are still the same talented and intellectual person that you were before this crisis happened. Nothing can take that away from you.

When all else seems to be spinning out of control around you, trust in yourself.

Find the silver lining

I have often been told that I am a “silver lining guy”. Meaning that I can find something good in every situation, no matter how difficult that situation may seem. I carry that title with honor, as it has helped me, my teams, and my family carry on in some rather trying times.

Finding the silver lining provides hope and a promise that there is still good in the world.

If everything looks dark and no silver lining seems to be found don’t despair! I believe in you and would like to help you find that silver lining. Get in touch with me and let’s discover your silver lining together.

Photo by Marcus Cramer on Unsplash

Page 4 of 168

Powered by WordPress & Beards