Stop Nano from adding newline character to end-of-file

I use Nano for all of my cli text file editing and I had always noticed that it puts a newline at the bottom of the file, but this has never bothered me much. Well today it caused me quite a headache at work, so I had to figure out how to MAKE IT STOP.

My googling turned up this post at Ask Ubuntu. It has the answer for many linux editors, not just Nano.

The solution for Nano was simply to launch it with the -L option.
nano -L myfile.txt

Posted in Googling for Answers, Linux Tagged ,

Debian: show a list of all packages that are to be upgraded with apt

This is a super easy one, and can easily be found in the man page, but I’ve googled it enough times that I think it’s worth including here. To see packages with available upgrades, without installing them, use the -u option: apt-get upgrade -u

Posted in Googling for Answers, Linux Tagged , ,

jQuery: Execute a callback once, after a class based animation completes

I was developing some web recently and ran into a jQuery problem that was new to me. I was using a class selector to fade a group of elements, and using a callback function which would fire after the fade was complete. Something like this:

[note color=#DDD] [/note]

The problem is that I only wanted to the callback function to execute once, but it was executing for each element in the class. Now, this is expected behavior, but it’s not what I wanted, so I had to find a way to get it to only execute one time, after all the animations were finished.

I asked my good friend google about it, and sure enough, he had an answer.

The trick is to use the last() function to target the last item in the group, then use the queue() function to add a callback to the end of that element’s animation. Finally, dequeue() is used to remove the callback once it’s been run.

[note color=#DDD] [/note]

Brilliant! And I take absolutely no credit for this, all praise goes to happymango.me.uk.

Posted in Googling for Answers, Web Development Tagged

Stop truncating your output you jerk!

The jerk in this scenario is the linux command ‘ps’. I was using it recently in a script that checks to make sure a certain process is running. Whenever I would run the command directly, I would get the desired response, a 1, indicating that the process was found. However, when I would run my script, I would always get a 0.

Here is the command in question: ps aux | grep -v grep | grep -c myprocess

While troubleshooting the issue, I had my script email me the entire output of ‘ps aux’ and you know what? That shit was truncated! WTF!? I understand it being truncated on the command line, depending on the size of your terminal, but why in a script? Regardless, I now knew why it was returning 0. The particular process name that I was looking for wasn’t part of the truncated output. I googled around a bit and found the answer:
ps auxww | grep -v grep | grep -c myprocess

From the man page:

[note color=”#DDD”]w
Wide output. Use this option twice for unlimited width.[/note]

Posted in Googling for Answers, Linux Tagged , ,

LEMP Site Setup Script, including SFTP

Setting up a LEMP server on Debian 6 was the first post I ever wrote. The impetus for that post (and this blog) was to chronicle all the steps I took, so that I could go back later and find my answers here, instead of googling them up all over again. After I got that server up and running, I decided to automate the process of setting up a new site. I googled around until I found a shell script that was close to what I needed, then with some more googling I managed to modify it for my needs. This script is very specific to my setup, so I doubt anyone would be able to simply download it and use it, but it should provide the groundwork for someone to craft a similar script, suited to their own server.

Here is what the script does:

  1. Asks for a domain, user and password.
  2. Creates the needed directories.
  3. Builds a simple index page (or downloads WordPress, but more on that later)
  4. Copies my nginx vhost template to the sites-available directory.
  5. Creates the symlink to sites-enabled.
  6. Does a find and replace on the vhost config to insert the correct domain name.
  7. Copies my php pool config template to PHP’s pool.d directory.
  8. Does a find and replace on the pool config to insert the correct domain name and user.
  9. Creates the user. This user will have no home directory and no shell access besides SFTP.
  10. Changes the owner of the public_html directory to the new user.
  11. Restarts Nginx and PHP
  12. Copies my SFTP template to a temp directory, does a find and replace to insert the correct file path and user, then appends the contents of that file to the sshd_config.
  13. Restarts ssh

There are two optional arguments you can pass the script when you execute it. The first is “wp”, which stands for WordPress, and if you pass that argument there are two changes in the execution of the script:

  1. Instead of creating a simple index file, WordPress is downloaded and unpacked.
  2. A WordPress specific vhost config template is used.

The second argument is “i”, which stands for “import”. If I’m importing an existing WordPress site, then I don’t want it to download and unpack a new WordPress installation, but I do still want it to use the WordPress specific vhost template, and that’s what this argument will accomplish.

[note color=”#DDD”]newsite.sh
[/note]

Posted in Googling for Answers, Linux, Nginx Tagged , , , , ,

Crayon Syntax Highlighter (and its studly author)

You may have noticed the syntax highlighter that I use on almost every post (except this one, oddly enough). It’s called Crayon Syntax Highlighter and it’s badassery at it’s finest. I’ve tried a half dozen syntax highlighters for WordPress, but Crayon remains my number one pick.

Story Time!!! When I setup this blog a few weeks ago and began writing posts, I ran into a problem with my excerpt plugin not working. I tried changing options, googling for answers, swearing at it, etc, but nothing worked. I finally ended trying another excerpt plugin… and another… and another, but none of them worked. At that point I knew that there had to be a conflict between one of my other plugins and the excerpt plugins, so I disabled them all and sure enough, the excerpt plugins began working. I starting enabling my other plugins one-at-a-time until I found the culprit: Crayon.

I started a thread about it at the WordPress forums and the plugin’s author starting assisting me almost immediately. Within 24 hours he had tracked down the problem and provided me with an updated file which fixed it. Within another 48 hours he had worked that fix into his next version of Crayon. In a word: AWESOME

Many thanks to Aram Kocharyan and his great plugin.   :)

Posted in Wordpress Tagged , ,

Display All Errors and Warnings in PHP

I find myself googling this up waaaaaaay too often, but there’s nothing unusual about that. I usually put this at the top of my code during development.

[note color=”#DDD”] [/note]

Here’s another handy tip I picked up somewhere: If you’ve got a parse error on your page, then you might be left staring at a white screen wondering what the hell is going on. Where are the errors I just told it to show me?! The solution is is to create a simple php page with no errors, then include your real file into that page. This way you’ll always see the error message which will hopefully help you track down that stray semi-colon.   :)

[note color=”#DDD”]show_errors.php
[/note]

Posted in Googling for Answers, Web Development Tagged ,

Colored Output for ls as root

I feel like a total nubbins for this one. I’ve been messing around with linux for many years now and I’ve always wondered why my regular users had pretty color coded files and directories when using ls, but root never did. It always bothered me, and I knew there was probably a way to fix it, but I was too lazy to google it. Besides, having a plain black and white terminal was always a reminder that I was running as root and needed to be careful.   :)

Anyway, one day I happened to look at the default aliases for a normal user and noticed this one:
alias ls='ls --color=auto'

Talk about a light bulb moment! There it was, the answer to that little thing that had been bugging me all those years. Helpful reminders be damned! That alias has now made its way into root’s profile.

Have I mentioned that I also didn’t know about aliases until recently? Sometimes I think my willful ignorance goes too far.

 

 

Nah.

Posted in Googling for Answers, Linux Tagged ,

Linux Command Line Aliases

Ok, you have to promise not to make fun of me if you’re going to continue reading. You promise? Pinky swear?

Alright then, here we go. Somehow or another, I managed to avoid knowledge of command aliases in Linux for over 13 years! I’m gonna give you a moment to let that sink in.

That’s comparable to using a web browser for years, but not knowing about bookmarks. Yes, I know those people exist, but I am not one of them. I have cursed their kind more times than I can count. (I DO NOT miss tech support)

I cringe to think of all the wasted keystrokes over the years. If I could get those back I could…… well I don’t know what, but it’s probably awesome.

If I can save just one person from typing “ls -la” over and over and over again, then this post has earned it’s keep. Here is what I’ve learned:

  • To show all aliases, just type alias
  • To create an alias, use this format alias name='command'
  • For example: alias la='ls -la' would allow you to simply type “la” instead of “ls -la”.

F-A-N-T-A-S-T-I-C!!!

Now imagine my surprise the next day when all of my aliases were gone. Here’s a picture of me when it happened:
Sad Panda

I googled up the answer for Debian, which was to add the aliases to my .bashrc file in my home directory. However, when I went to do that, I found this:
[note color=”#DDD”]/home/user/.bashrc

[/note]

I did as it suggested and created the file .bash_alises, and put my aliases there. After logging out and back in again, they took effect.

Happy Panda

Posted in Googling for Answers, Linux Tagged ,

Nginx: 502 Bad Gateway

I just recently switched from Apache to Nginx and everything seemed to be going well. However, while testing a PunBB site that I brought over, I got a 502 Bad Gateway error when trying to make a post. The strange thing was, the behavior was inconsistent. I could post in some threads, but not others. A bit of googling turned up this page and the suggestion there worked for me.

Looks like the default header limits on Nginx were too small for my site, so I added these two lines to my nginx.conf:

[note color=”#DDD”]/etc/nginx/nginx.conf
[/note]

I could have just added them to that site’s config, but it’s not the only forum site I run, so I figured I’d just make it a global setting.

Posted in Googling for Answers, Linux, Nginx Tagged ,