Three Good Things

Three Good Things: Building and deploying a project with Laravel

David Nash laravel, linux, mysql, php 0 Comments

What do developers do in their spare time? Code! Three Good Things is a little app that I started over the holidays, and have been working on in my spare time. During the Christmas/New Year holiday period I read Flourish: A Visionary New Understanding of Happiness and Well-being, by Dr Martin Seligman. In it he describes an exercise called “What-Went-Well” (or “Three Blessings”). The idea is, every night you write three good things that happened in the last 24 hours, and why they happened. I thought it would be a good idea for an app, so I set to work. It was a …

Git: How to create a repository on a web server

David Nash bash, linux 0 Comments

I’m writing this mainly for my own reference. I found it very difficult to find instructions on using git for what I wanted. The scenario: I have a web server (example.com), which I can ssh into. It has a website running on /var/www/website/. I want to create a git repo for it, and then from my development machine (devmachine) clone that repo, make changes, and when I’m happy push them to the web server. I already have ssh keys installed so I can ssh from devmachine to example.com. On both example.com and devmachine I have a user david who is …

Delete links across multiple HTML files in bash

David Nash bash, linux, vim 0 Comments

Or any type of file, really. I needed to quickly remove links from an old website that was using flat HTML files. In my linux command line, I found I could do:

To replace all instances of SEARCH with REPLACE in *.html. Except I needed to do a fair bit of escaping, because HTML is full of characters that mean something else on the command line. So let’s say the string I needed to remove was: [sourcecode]<a title="Search Engine Optimisation" href="http://superspammyseocompany.com/" target="_self"><span>Search Engine Optimisation</span></a> by <a title="Super Spammy SEO Company" href="http://superspammyseocompany.com/" target="_self">Super Spammy SEO Company</a>[/sourcecode] I copy + pasted …

Hostmonster 500 Internal Server Error (SHTML Wrapper)

David Nash linux, php 1 Comment

A client using Hostmonster was doing some hair-pulling over what appeared to be a .htaccess problem while installing a Symphony site I developed. We thought it might be related to the fact it was running on a subdomain. The server would give a blank page, and on the HTML source would show something like “500 SHTML wrapper”. It turns out this happens when group write permissions are set on the script. Via the Hostmonster Cpanel File Manager, you can right-click the file, click permissions and uncheck “write” and the script should run. The way I worked this out was: first, …

Batch reduce resolution of images in Ubuntu Linux

David Nash bash, linux 4 Comments

Open a terminal window or shell (who needs a GUI!?) sudo apt-get install imagemagick cd image_folder mkdir resized for f in *jpg do convert -resize 30% $f resized/$f done Easier than Photoshop, I reckon! I needed this today for some photos I was uploading. Photos from recent cameras are huge and Australian bandwidth doesn’t cut it. So this really helps. Obviously you only need to do the first line once. I found this in the Ubuntu forums but it took me a while to find the right combination of keywords in Google. View the original thread. I needed to change …

Fixing Windows File Permissions in Linux

David Nash bash 0 Comments

Find all files (not directories) and remove the eXecutable bit. I don’t know what the characters on the end do: find . -type f -exec chmod a-x {} \; Make all directories executable to user, read/writable to groups others (good for when the web server is in ‘others’): find . -type d -exec chmod 755 {} \; Make all files read/write/executable for user, readable for the group and others: find . -type f -exec chmod 644 {} \;

Unix Time in MySQL and bash

David Nash bash, mysql 0 Comments

A quick one today. I was working on a mysql database that used unix timestamp produced by PHP’s time() function. I needed to be able to quickly convert this time to a human-readable format. In bash, date -d @timestamp is a quick way to convert. In a terminal shell eg: # date -d @1224992980 Sun Oct 26 14:49:40 EST 2008 In a MySQL client, you could also use select date(from_unixtime(column_name)) from table_name; Or if you want a little more flexibility in the output, for example outputting 27/02/09, you could do: select date_format(from_unixtime(column_name), ‘%d/%m/%y’) from table_name; This post is one of …