Category: OS


find text within a bunch of files within a folder simply by typing this:

grep -nr 'whatever' .

Where r is recursive, and n gives you the line number. 🙂

Advertisements

Devving on Windows is a PITA.

Anyway, ever seen a message like this?

warning: LF will be replaced by CRLF in tests/unit/Del/Console/CommandTest.php.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in tests/unit/Del/Console/CommandTest.php.
The file will have its original line endings in your working directory.

We only want LF. To squelch this crap, run the following:

git config core.autocrlf false

Yay.

DATE

“Seriously, I can’t get anything done in this office thanks to their draconian proxy configuration, everything is blocked!”

Sound familiar? If you are a web developer, you need unrestricted access, right? So let’s sort that out. I’m assuming you have a linux web server that isn’t locked down outwith the network that you can putty into.

Open Putty! Choose SSH > Tunnels. Add a dynamic port 7777 (or whatever) (ignore the 10139, that’s my debugger port) and save the settings.

putty

Now go into Chrome settings, click advanced, Change Proxy Settings, LAN Settings, Advanced.
Then in Socks, enter localhost and your port (7777).

chrome

You can now browse every web site again! 😀

Need IRC too? same deal. I use Pidgin. Open Pidgin, then click the Accounts menu, Manage Accounts, click on your account, click modify, click Proxy, choose SOCKS5 as the proxy type, then enter localhost and 7777, as below:

pidgin

You are now on IRC again!

Now, Git. All that is required to get git working is to add the socks5 proxy:

git config --global http.proxy 'socks5://127.0.0.1:7777'

And now you can clone repositories with no problem!

UPDATE:
Okay, I finally got everything unrestricted in the CLI too, by using a piece of software called ProxyCap. Check it out:

proxy

proxy2

 connection works

Just a quick note here, if you are running out of space on your Linux machine and need to find the files taking up the most room, try this command!

du -hsx * | sort -rh | head -10

3.9G    logs
85M     vendor
79M     utils
71M     sales
43M     products
27M     src
23M     classes
15M     images
14M     forms
12M     yui

Now that my VM is completely configured through puPHPet’s puphpet/files/exec-once shell scripts, I had to change PHP settings for the legacy 5.3 install. At first I echoed the setting out and concatenated it onto the end of the string, however the setting was already uncommented above.

The answer is to use sed to find and replace the line of text, like this!

cat /etc/php.ini | sed -e "s/short_open_tag = Off/short_open_tag = On/" >> /etc/php.ini

cat ~/.ssh/id_rsa.pub | ssh user@host ‘cat >> .ssh/authorized_keys’

Installing Ansible

Ansible is a bit like puPHPet, in that it provisions Vagrant boxes etc. My latest project is using PPI Framework 2, and provisions with Ansible, so I had to get everything installed.

Essentially we just clone from the Github repo and install a few python things:

$ git clone git://github.com/ansible/ansible.git --recursive
$ cd ansible
$ source hacking/env-setup
$ sudo easy_install pip
$ sudo pip install paramiko PyYAML Jinja2 httplib2 six

And that should be you. Run ansible from the terminal in ay folder now and you should get all the available options etc. Have fun!

puPHPet Box MySQL backup

As you all know by now, I love puPHPet. And I like tinkering with things. Which of course leads to the occasional breaking of things. And then I realised, okay, your sites files are being mounted into this virtual machine, what about the databases though?

The great thing about puPHPet and Vagrant is you can build a full server up from scratch in minutes. The one downside is that it cant be smart enough to uninstall things. If you add lines to your config.yaml it will install something, but removing those lines means puPHPet won’t even know it was there, so how would it know to uninstall it? The exceptions of course being the ones which have their own config.yaml entry, with an install: ‘1’ or install: ‘0’

Anyway, I generated me a new config and was about to blitz my old VM when the usual gut instinct checks kicked in, and the DB sprung to mind immediately. So I made a quick backupdbs.sh shell script (courtesy of a StackOverflow post) which makes individual sql files for each of your DB’s. I decided I would keep the script in my mounted sites folder in a bin directory. So hence it lives in /var/www/bin/backupdbs.sh

#!/bin/bash

USER="root"
PASSWORD="YOURPASSWORDHERE"

databases=`mysql -u $USER -p$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`

for db in $databases; do
    if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then
        echo "Dumping database: $db"
        mysqldump -u $USER -p$PASSWORD --databases $db > `date +%Y%m%d`.$db.sql
    fi
done

To back everything up, vagrant ssh into the machine, then (you’ll probably need to switch user to www-data) do the following:

sudo su www-data
cd /var/www/bin
./backupdbs.sh

Now you’ll find all your DB’s SQL files date stamped in the folder! You can continue to break, tweak, fix, and run your VM to your hearts content 😀

Upgrade your Terminal!

If you are using the Bash terminal, or the Mac OSX Terminal, time to get rid of it! You need Zsh! (pronounced zoosh). From the Github page:

Oh My Zsh is an open source, community-driven framework for managing your zsh configuration. That sounds boring. Let's try this again.
Oh My Zsh is a way of life! Once installed, your terminal prompt will become the talk of the town or your money back! Each time you interface with your command prompt, you'll be able take advantage of the hundreds of bundled plugins and pretty themes. Strangers will come up to you in cafés and ask you, "that is amazing. are you some sort of genius?" Finally, you'll begin to get the sort of attention that you always felt that you deserved. ...or maybe you'll just use the time that you saved to start flossing more often.

So, what are you waiting for? Give it a spin!

curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh

Or using wget:

wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh

Well worth a try! https://github.com/robbyrussell/oh-my-zsh

PHP CLI commands in Debian

This problem was infuriating. After having upgraded my Vagrant Box to run PHP 5.6, I was looking forward to trying out phpdbg, the new built in debugger that ships with PHP 5.6.

It turns out that Debian use their own moronic naming system for their PHP package commands. I was typing in phpdbg into the shell, and all I got in return was ‘command not found’.

I tried sudo apt-get install php5-phpdbg, yet it told me that it was already the latest version!

I eventually found it in the /usr/bin folder, under the name php5dbg. Why?

For reference, you can run this command to help find it: (if dpkg is installed)

dpkg -L <pkgname> | grep '/bin/'

What a waste of time, I hope this helps someone.