Gl.ib.ly

(glibly); Just another techie blog.

Fixing binary merge conflicts in git

Posted by Tariq • Thursday, September 3. 2009 • Category: Tidbits
Git is an awesome tool for managing your code. However, it does take a while to get used to doing things in git. One question I get asked a bit too often is "how do I resolve binary merge conflicts"? Thankfully this is is pretty easy. I usually run the git mergetool command to allow me to resolve merge conflicts using a graphical interface and then manipulate the resultant files on the command line.

You can specify which editor to use in your ~/.gitconfig file. Favourites are kdiff3, vimdiff, xxdiff, and opendiff. If your on Mac OSX then you may be used to FileMerge, in which case you should be using opendiff in your .gitconfig; see below.

...
[merge]
tool = opendiff
...



So, when you are using mergetool option you will something like:
Normal merge conflict for 'lib/yui/assets/skins/sam/editor-sprite.gif':
{local}: created
{remote}: created
Hit return to start merge resolution tool (opendiff):


I just hit return so the editor opens, it will probably warn you the file is binary. In a separate terminal window navigate to the directory where the file is in and do an ls; you'll see something like what is below:
editor-sprite.gif
editor-sprite.gif.BACKUP.41930.gif
editor-sprite.gif.LOCAL.41930.gif
editor-sprite.gif.REMOTE.41930.gif


In this case editor-sprite.gif.REMOTE.41930.gif is the new file and editor-sprite.gif is the original file. To resolve the conflict just copy the REMOTE file over the original file. In my case it would be cp editor-sprite.gif.REMOTE.41930.gif editor-sprite.gif. However, I use the following one liner to resolve these conflicts more generically.


ls *.REMOTE.* | sed "s/\(\(.*\).REMOTE.*\)/cp \1 \2/g" | sh
 


I have it in shell script in my path so I just run it when I need to resolve these types of conflicts. It just finds files with REMOTE in them and then issues a cp command to copy that file over the original.

Hope this helps!

Outside of git mergetool you can just add the binary files using git add file1 file2 ....
Defined tags for this entry: , , , , , , , ,

Encoding audio and removing file extensions from files

Posted by Tariq • Friday, July 24. 2009 • Category: One liners, Tidbits
Earlier today I got a massive SCORM object that contained lots of mp3 files. They were all high quality files, so I wanted to cut them down in size for web use. For this purpose I am using ffmpeg which you can easily get for Windows, Linux or Mac. I tried the following on a Mac, but it should also work on Linux (paths permitting) and on Windows if you are using something like cygwin.

I highly recommend you get familiar with ffmpeg as it is amazingly useful. Just check out the man pages; swf to avi, avi to something that works on ipods, all a breeze!

Continue reading "Encoding audio and removing file extensions from files"

Defined tags for this entry: , , , , , , , ,

All configuration variables in Moodle code - Part two?

Posted by Tariq • Wednesday, June 24. 2009 • Category: Moodle
Earlier we looked at how you can extract a list of all the $CFG variables in your Moodle code. Now that's not of much use! We need to know where in the code all these variables hide. I feel some spooky awk a coming on.

Continue reading "All configuration variables in Moodle code - Part two?"

Defined tags for this entry: , , , , , ,

Searching compressed Apache logs

Posted by Tariq • Tuesday, June 23. 2009 • Category: One liners, Tidbits
From time to time things tend to go wrong and systems tend to go crazy. Sometimes these errors are more of nuisance than anything else, an intermittent annoyance you'd prefer not to investigate -- trawling through logs is a pain in the backside. Now you need to take a peak at those compressed Apache error log files, ugh! Well before you look for suitable places to hang some rope try running some expressions across a certain number of files. Normally you'd only want to look at logs for the last 7 days, so lets give that a go.

Continue reading "Searching compressed Apache logs"

Defined tags for this entry: , , , , , , , , ,

Common translation errors in Moodle language packs

Posted by Tariq • Friday, February 6. 2009 • Category: Moodle
If you have ever had to deal with language packs you will know how much of a pain they can be. I regularly interact with 9 Moodle language packs and I don't like doing that much. For some reason, can't remember why now, we gave people the raw language string files (PHP code files) to translate and they translated these files and sent them back. Only these people are not PHP coders and they make mistakes. Here is my list of what goes wrong and how to solve.

Continue reading "Common translation errors in Moodle language packs"

Defined tags for this entry: , , , ,

The command prompt has been disabled by your administrator?

Posted by Tariq • Thursday, February 5. 2009 • Category: One liners, Security
I came across an old enough post on Didier's blog about Group policies that have disabled cmd.exe from running. Didier mentions a few ways to get cmd.exe to run. The suggestion I like the most is to find the DisableCMD string in cmd.exe and change it to DisableAMD using a hex editor. Thankfully there is a tool which will allow us to patch cmd.exe in one tiny line.

Continue reading "The command prompt has been disabled by your administrator?"

Defined tags for this entry: , , , , , , , ,

Deleting specific emails from the postfix mail queue

Posted by Tariq • Thursday, January 8. 2009 • Category: Computers, One liners
A week ago a development database server lost power, which is usually no big deal only that I have some reporting scripts that run every 5 minutes for each database. When these databases became unavailable they (the scripts) like to send me a quick mail telling me what went wrong. The network switch also was out of action so there was no route to the outside world from this small development network. The server lost power for three days and a massive amount of mail built up in the mail queue. When power was restored the SPAM started pouring in.

Continue reading "Deleting specific emails from the postfix mail queue"

Defined tags for this entry: , , , , , , ,

All configuration variables in Moodle code?

Posted by Tariq • Monday, December 15. 2008 • Category: Moodle, One liners
Sometimes Moodle introduces some nice new configuration variables and I like to make sure that I know what they are and where they are. So to begin my investigation without heading off to the web I use the following command to get me a sorted list of the $CFG variables.

Continue reading "All configuration variables in Moodle code?"

Defined tags for this entry: , , , , , , ,

Creating an HTML file with white space traces

Posted by Tariq • Tuesday, December 9. 2008 • Category: One liners
Once upon a time I was comparing some Java files. Now one way to find plagiarism among students who share program code is to look at the white space traces in a file. Students typically try and edit the source code: changing variable names and function names; however, they usually fail to conceal the original author's white space patterns. White space consists of characters which don't appear on screen such as spaces, tabs, and new line characters. Anyway you can catch lots of cheaters by looking at the white space patterns in files ... maybe that's another blog entry, so back to this one.


Continue reading "Creating an HTML file with white space traces"

Defined tags for this entry: , , , ,

Getting logins per day in Moodle

Posted by Tariq • Tuesday, December 2. 2008 • Category: Moodle, One liners
Today I got the urge to see how many logins we had on some of our Apache servers in November. We host more than one moodle site on one server and so I wanted the total number of logins we handled. As usual this ended up becoming an awkward but useful one liner.

Continue reading "Getting logins per day in Moodle"

Defined tags for this entry: , , , , , , ,