Shortcut to Restart Firefox on Linux using I3wm

First off if you’re a developer and not using i3wm you should really think about giving it a try, it’s like vim for the desktop. It’s a tiled window manager, but you don’t need to use the tiles, I prefer tabbed layout actually, but the brilliance is things like pressing Shift + mod (window key) + # will move an app to the workspace or window with that number easily. mod + right moves to the next tab over, Shift + mod + right moves the current window to the tab to the right, etc…

However, the BIGGEST feature is the ease of creating tons of customized scenarios for instance I have a custom hotkey in my i3 config that opens firefox, Hubstaff (time tracker), Wavebox (multi-slack app), and Thunderbird from one hotkey that I just use on restarting. You can even have windows and programs load automagically on reboot as well.

One thing I noticed with Firefox using 58 beta is that if I go away for awhile and come back after my pc has been sleeping I’ll sometimes have js popup warnings and my whole computer is basically frozen but not completely frozen. To deal with this at first I created a bash script:

Add this to ~/.bash_aliases and then nt firefox will basically force kill anything with firefox in the name, useful when you know what script to kill and you have access to shell. However, sometimes you don’t really have access to shell, or the computer is so bogged down it won’t let you switch windows or type very easily. So I moved this into my i3 config file as such:

That line is firefox specific and it also restarts firefox-beta, you can edit it however you like if you don’t want to restart just remove that part. 99% of the time firefox is the problem, and the only reason I don’t switch back to chrome is that I have tons of nginx sites using .dev and they fucked everything up by forcing https on .dev and I don’t want to rewrite all my server configs.

So fuck google chrome, I’ll use Firefox. I also prefer sidebar tabs vs horizontal just personal preference I’m hoping performance issues improve with firefox, but till then I got it covered.

FreeCodeCamp Bonfire Challenge Solutions

In order to help land that coding job I’ve been dreaming of, and since I’m currently unemployed, I thought I’d use spare time where I’m not coding on something cool, or applying for dev jobs to work on my craft.

Beginner Algorithm Scripting

Here are gists from the Bonfire Challenges:

Free Code Camp :: Bonfires

1. Bonfire: Meet Bonfire

2. Bonfire: Reverse a String

3. Bonfire: Factorialize a Number

4. Bonfire: Check for Palindromes

5. Bonfire: Find the Longest Word in a String

6. Bonfire: Title Case a Sentence

7. Bonfire: Return Largest Numbers in Arrays

8. Bonfire: Confirm the Ending

9. Bonfire: Repeat a string repeat a string

10. Bonfire: Truncate a string

11. Bonfire: Chunky Monkey

12. Bonfire: Slasher Flick

13. Bonfire: Mutations

14. Bonfire: Falsy Bouncer

15. Bonfire: Seek and Destroy

16. Bonfire: Where do I belong

Intermediate Algorithm Scripting

1. Bonfire: Sum All Numbers in a Range

2. Bonfire: Diff Two Arrays

3. Bonfire: Roman Numeral Converter

4. Bonfire: Where art thou

5. Bonfire: Search and Replace

6. Bonfire: Pig Latin

7. Bonfire: DNA Pairing

8. Bonfire: Missing letters

9. Bonfire: Boo Who

10. Bonfire: Sorted Union

11. Bonfire: Convert HTML Entities

12. Bonfire: SpinalTap Case

13. Bonfire: Sum All Odd Fibonacci Numbers

14. Bonfire: Sum All Primes

How to keep tables uncluttered by using profiles for each user type in Ruby on Rails

This is a continuation of my STI / Single Table Inheritance article: “How to use multiple User types with the same model in Rails aka STI or Single Table Inheritance

To keep your tables less cluttered and better normalized, I do recommend creating profile tables for each user type. What I did is this for my student’s example:

I have a student_profiles table with things like skype_username, birthdate, etc. To set this up You’ll want to do your migration.

Then we edit the Student model like so:

Now you can keep your user table and class more minimal and separate everything out into their own model. I also recommend putting all of these folders in models/users folder. To do that though you will need to edit config/application.rb and add the following line:

Thinking ahead you may want to group more models together, especially if you have a large number of models and tables, to do that you’ll just need to add a new line the same thing as above, just change the last part of the path to match the path to the folder with your models, and you should be good to go!


How to Use Multiple User Types (STI or Single Table Inheritance) with the Same Model in Ruby on Rails

Lately, I’ve been building a complex CRM for music teachers to manage students, invoicing, etc… It’s gotten a bit complicated, and I myself have learned a lot from this side project. One important thing I’ve learned is STI, or Single Table Inheritance. Basically, this lets you easily have sub models with their own intricacies, relationships, etc so you don’t clog up the main user class, but they all use the same table, and are easier to modify on their own.

I have admin.rb, student.rb, parent.rb, and teacher.rb files with classes to go with them…

I’ve built this all using Sorcery for the backend, but you can use devise, or whatever else floats your boat.

The first step is creating a “type” attribute on the users table. This is required by STI to know which type of user we’re dealing with. I’m going to assume you already have your user authentication system all setup.

Next you’ll want to create a subclass. For this example we’re just going to use Student.

When we create this, we also need to make sure that when the “type” attribute is set it’s always titleized. You’ll get errors and have issues if for instance the user.type was set to “student” and not “Student”. Case matters in this case.




Now, just make sure each user has a type, or perhaps have some sort of fallback, or default type as well. Then whenever you query Student.all or Teacher.all you’ll be pulling data out of the users table, but only get back Student and Teachers.

Next you may want to checkout my article on: How to keep tables uncluttered by using profiles for each user type.

More good articles on Single Table Inheritance / STI:



Why the Singularity proves Time Travel Impossible


time travel possible

The fact is that Ray Kurzweil is a mad genius, he is definitely mad, and he’s definitely a genius, and some of his predictions are quite scary.

Nothing is more scary, and exhilarating as the thought of a technological singularity – the point in time where we–mankind become unecessary. For millenia, since the dawn of history WE humans have propelled ALL scientific discoveries, all progress has been a result of human intellect, and that intellect is what separates us from all other creatures in the world, and maybe even the universe(until proven wrong).

We have the ability to build, change, and disrupt the world around us, and even the universe in great and profound ways. Yet, it is predicted that there is an 80% chance that by 2040 we will have entered the post-human era. What is this? When a super-intelligent AI computer/robot eclipses the intellect and brain processing abilities of a human.

This sounds amazing, fascinating, and like science fiction, but let me ask you does warp drives, wormholes, time travel, blackholes(in a lab), cold fusion, lasers in warfare, space elevators sound like science fiction? What about a brain chip that can control a robot exoskeleton as an extension of the brain, –or a prosthetic device w/ the ability to send REAL touch back to the brain of the user — or printable kidneys? — YET many of these are not only being researched, but some are now a reality!

We are living in an AMAZING era where science fiction ceases to be fiction, and becomes part of reality. This gives me a huge noody™ (nerd woody), and scares the shit out of me at the same time. When we arrive at the point in history where a machine can do everything a human can, and do it better, we become the animal – a nuisance that takes up space, and no longer will we give way to advances in technology, because technology will be able to create new technology faster than we can conceive, research, and develop said technology. In other words, there is no point in us developing or building anything new after this point, as machines will be able to do it at a much faster speed, meaning we may probably not put as much value on education -what is the point when we don’t need to know anything because machines know it all?

Which brings me to time travel, IF time travel were possible it is postulated that we would be surrounded by time travellers, but they would mostly be disguised probably to avoid detection and possible paradoxes, BUT we are closer to AI than time travel, and if time travel is possible at all – it will be an yAI that discovers it, meaning that it will be robot’s that come back in time, and they would surely bring future technology backwards in time, in order to propel future growth even faster. Imagine giving a smartphone to someone in 1890 and all the engineering manuals upto 2010 – then repeating with even more data, and so forth.. .. or if time travel were possible wouldn’t there be a high likely-hood that something like the terminator would have already played out?

This is just thoughts and speculation of course, — there’s also the possibility that AI computers do discover time-travel but have a directive NOT to go back in time before the invent of the machine because doing so – and causing some sort of ‘havoc’ on mankind, would essentially wake up mankind to that fact that we’re going to destroy ourselves if we go further, and thus we stop all research on AI, and time travel – – yet, if we live in a multi-verse where that one robot from the future that came back to destroy us before we even discover how to make it — would keep on existing because it comes from a parallel world where it was created even though in this one, that will not happen, but if all time is linear w/out multi-verses or deviations then the question lies – if you remove a piece of history that leads to your creation, and you are currently residing in the history — do you then disappear instantaneously and cease to exist – and if you do cease to exist, how did you remove the piece of history since you weren’t created to do so…. — I guess that’s the nature of a paradox, and would something like this unravel time and space?

Or, what if we are as some scientists are postulating – a scientific computer simulation, at which point –creation of a paradox would not end the universe, but cause the simulation to ‘error out’ and crash. So, to us it will be end game, to the other us – doing the research, it’ll just be a temporary set-back needing further debugging.

The more I think about these topics, the more I feel that you almost need a super-intellect to even understand all the complexities that our future holds, and as I said from the start of this post, I am both exhilarated, and scared shitless at the same time, I say bring it, if we are to be destroyed, let’s just get it out of the way because there’s nothing to stop it – hopefully all generations of AI keep in mind Asimov’s 3 laws of robotics, and maybe we will survive this singularity, or maybe WE will become the machines, and instead of being out-paced by technology actually become the technology that replaces us in the world.

How to Use Local Environment as Default in Laravel Artisan CLI

I have to say, I absolutely LOVE Laravel – everything about it.

One of my favorite features is the ability to separate your app into local/production versions.

I use a lot of packages for development, that I just don’t need on my production version of the app. How do I resolve this? By using two different environments w/ different App.php configs. Read my tutorial on this here.

You might find that this only works for your app when running it in the browser. Here’s how to make sure that the local environment is ALSO set for command-line e.g. Artisan and Tinker.

One option of course is to do:

But who wants to write –env=local after EVERY artisan command? I am a pragmatist and believe in using technology to my advantage. This is great when needing to switch back and forth for a minute, but when doing it all the time you need an alternative.

next add “PatrickPC” to bootstrap/start.php

Now artisan should run w/ local environment as default when on this machine, let’s test it:

Got questions? Leave a comment!

How to setup Local and Production environments on Laravel

One great feature of Laravel is how easy it is to setup local and dev environments.

Why would you want separate environments?

  • Require separate packages for dev, and production.
  • Less bloat / potential for errors on production.
  • Turn off debug on production.
  • Special config options for local vs production.
  • etc…

Next we simply create a new folder at : App/config/local/

If you create a App.php file -this file will override the global App.php in the parent directory while working in the local environment. So you can add different providers/facades to this local version and not mess up the production version.

Gollum Covers Taylor Swift

I absolutely LOVE Gollum, my favorite character on Lord of the Rings, and probably one of the BEST pieces of acting I’ve ever seen. I love the way Andy Serkis does the split personality between Gollum and Shmeagol, it’s quite amazing. He’s a true acting genius. Also loved him as Caesar in Rise of the Planet of the Apes.

Anyhow, today I found this really amazing facebook video Gollum Covering a Taylor Swift Song–it’s freakin’ hillarious… The guy who made this is also a freakin’ genius..

Here watch it and let me know your thoughts, if you like it please share the video on facebook, like, and leave a comment.


Once upon a time
A few mistakes ago
We were in our cave
You got us alone
You found us
You found us
You found us us us us (gollum)

We thought that you were food
You didn’t like that
So we played a game
But when we turned our back
You tricked us
You tricked us
You tricked us us us us us uuuhhhsss

Now it’s long gone
We were stupid to trust
And we realize
The blame is on uuussss

Cause we knew you had precious when you walked in
So shame on us now
Our cries echo through the Misty Mountains
Since you came around
Cause we knew you had precious when you walked in
So shame on us now
Our cries echo through the Misty Mountains

Now we’re lying in the cold hard cave
Black Riders chased us down
They never saw us cry
Okay maybe we cried

But we had to stay alive
For the Precious
The Precious
The Preciou ou ou ou ou ouusssss

We heard you moved on
From birdses in the trees
They saw you with the Hobbits
Somewhere to the East
So we eats those birds
We eats those birds
We eats those birds birds birds birds birdseeeess

It was long gone
We were stupid to trust
And we realize
The blame is on uuussss
Cause we knew you had precious when you walked in
So shame on us now
Our cries echo through the Misty Mountains
Since he came around
Cause we knew you had precious when you walked in
So shame on us now
Our cries echo through the Misty Mountains

Now we’re lying in the cold hard cave
Then the saddest fear comes creeping in
That you never loved us, or him, or anyone
Or anything


We knew you had precious when you walked in
So shame on us now
Our cries echo through the Misty Mountains
Since he came around
Cause we knew you had precious when you walked in
So shame on us now
Our cries echo through the Misty Mountains

Now we’re lying in the cold hard cave
We knew you had precious when you walked in
Precious, Precious, Precious
We knew you had precious when you walked in
Precious, Precious, Precious

Planet of the Apes meets Terminator.

Cliffnotes version : Monkey gets rewarded for playing video game and hitting targets with controller. Switch to brain interface with robotic arm and he continues to be rewarded – interestingly the 3rd arm is like he really has a 3rd arm, he can now scratch with one arm, eat a banana with another, while using his 3rd arm to hit the target.

Fast forward almost 10 years and the monkey can now control a robot all the way across the planet in Japan. Most importantly the time it takes for the signal to travel from his brain to the robot is 20 milliseconds LESS than it takes to control his REAL body/legs.

Potential uses: The main goal of this project is to give arms and legs back spinal cord injury patients. Other uses though I’m sure will include military (think of an army of robotic avatars that cannot die!), gaming – imagine controlling the characters in Halo using your mind.

Personally, I see stuff like this, and I think I’ve somehow woken up on Star Trek, minus the warp-drive of course (sad, that this will probably not be realized in my life-time, if ever).

Here’s a video presentation that’s pretty awesome:

Source: VentureBeat

How to: Change Swappiness or Adjust Swap File Use in Ubuntu 12.10

A few weeks ago, I made the switch to Ubuntu, and I’m enjoying it tremendously (Currently Ubuntu 12.10). Some drawbacks though have been performance related, it locks up a lot and I have to reboot using ubuntu ctrl + alt + printscreen, REISUB –which is apparently a safer way to reboot and a good way to stretch out your fingers.

One things I read up about regarding PC performance is that the swap file use in Ubuntu is setup for servers, not for home use out of the box. This tweakable setting provided by the Linux Kernal is call swappiness.

With swappiness at zero it will not use the hard disk at all for memory swaping unless emergency situations (e.g. you run out of memory), a swappiness of 100 means that programs will be swapped immediately.

The default setting on Ubuntu is a swappiness of 60, you can find your swappiness by typing in the terminal:
cat /proc/sys/vm/swappiness

When I initally did this I got “60” returned to me. This means that the swap file will be used often if memory usage is about half of my Ram.

The first article I found this on said that the way to change this is to open a terminal and run:
sudo gedit /etc/sysctl.conf

Then modify the swappiness setting, except for one problem, my file didn’t have that particular setting for one reason or another… So I had to look for a different method, and luckily there is one, which is even easier.

sudo sysctl vm.swappiness=10

Then when I re-check my swappiness level, it shows 10, and I know I’m good to go!