Tuesday, November 22, 2011

adding syntax highlighting on blogger

This of course started because I wanted to add syntax highlighting to this blog. That led me to an excellent post

http://heisencoder.net/2009/01/adding-syntax-highlighting-to-blogger.html

by Matt Ball about the subject; it worked, and all was well. However in a later bash script post, I noticed it was incorrectly treating a variable as a comment because it had a # in it. This led me to the git project of the syntax highlighter Mr Ball had used (and everyone seems to use), the excellent and excellently named SyntaxHighlighter by alexgorbatchev:

https://github.com/alexgorbatchev/SyntaxHighlighter

After playing around with it a bit, I updated the single line comment code for bash syntax highlighting as well as the auto-loader to allow it to take a path to a directory rather than having to specify the URL of every script that can be used. I created a git project on google code to host the files and and all seems well again. The only thing I had to do on blogger was add these lines to the end of the head section of the template


And then whenever you want to add some syntax highlighting to your post, simply edit the html to include the wrapper for the brush


here is my xml

or


console.log('hello javascript syntax highlighted world');

The idea to use google code to host the static files came from this post

http://blogazor.blogspot.com/2011/06/freely-host-css-js-other-static-files.html

by the good people at blogazor. They use svn so if you would like to use svn that howto is a great read.

Monday, November 14, 2011

import sql files

import all files matching *.mysql in current directory into database "db"
for f in *.mysql; do echo $f && mysql -u username -psecretpw db < $f ; done
echos the file name as it goes

Saturday, November 12, 2011

match a word as long as another word doesn't appear before it

match 'haha' as long as 'example' doesn't come first
/^((?:(?!example).)*)(haha.*)$/
excellent post about *not* matching a word: http://stackoverflow.com/questions/406230/regular-expression-to-match-string-not-containing-a-word

recursive file list sorted by mod time

I end up bouncing from one project to another pretty often, and I don't like saving my workspace in my editor so that I can start with a nice, clean, blank slate. But it's nice to know what exactly I've been working on recently, so..
find . -type f | xargs ls -l 2>/dev/null | sort -r -k6,6 -k7,7 | most

Friday, November 4, 2011

hexdump

Quick little one liner for hexdump with some nice, versatile output. 1 byte per line, with
byte #[space]octal value[space]decimal value[space]hex value[space]default character set
hexdump -v -e '"%07_ad" 1/1 " %03o"' -e '1/1 " %03u"' -e '1/1 " %03x"' -e '1/1 " %_c \n"'
And in a bash script taking a file:
#!/bin/bash

hexdump -v -e '"%07_ad" 1/1 " %03o"' -e '1/1 " %03u"' -e '1/1 " %03x"' -e '1/1 " %_c \n"' $1
Example output when called on itself:
0000000 043 035 023 # 
0000001 041 033 021 ! 
0000002 057 047 02f / 
0000003 142 098 062 b 
0000004 151 105 069 i 
0000005 156 110 06e n 
0000006 057 047 02f / 
0000007 142 098 062 b 
0000008 141 097 061 a 
0000009 163 115 073 s 
0000010 150 104 068 h 
0000011 012 010 00a \n 
0000012 012 010 00a \n 
0000013 150 104 068 h 
0000014 145 101 065 e 
0000015 170 120 078 x 
0000016 144 100 064 d 
0000017 165 117 075 u 
0000018 155 109 06d m 
0000019 160 112 070 p 
0000020 040 032 020   
0000021 055 045 02d - 
0000022 166 118 076 v 
0000023 040 032 020   
0000024 055 045 02d - 
0000025 145 101 065 e 
0000026 040 032 020   
0000027 047 039 027 ' 
0000028 042 034 022 " 
0000045 063 051 033 3 
0000046 157 111 06f o 
0000047 042 034 022 " 
0000048 047 039 027 ' 
0000049 040 032 020   
0000050 055 045 02d - 
0000051 145 101 065 e 
0000052 040 032 020   
0000053 047 039 027 ' 
0000054 061 049 031 1 
0000055 057 047 02f / 
0000056 061 049 031 1 
0000057 040 032 020   
0000058 042 034 022 " 
0000059 040 032 020   
0000060 045 037 025 % 
0000061 060 048 030 0 
0000062 063 051 033 3 
0000063 165 117 075 u 
0000064 042 034 022 " 
0000065 047 039 027 ' 
0000066 040 032 020   
0000067 055 045 02d - 
0000068 145 101 065 e 
0000069 040 032 020   
0000070 047 039 027 ' 
0000071 061 049 031 1 
0000072 057 047 02f / 
0000073 061 049 031 1 
0000074 040 032 020   
0000075 042 034 022 " 
0000076 040 032 020   
0000077 045 037 025 % 
0000078 060 048 030 0 
0000079 063 051 033 3 
0000080 170 120 078 x 
0000081 042 034 022 " 
0000082 047 039 027 ' 
0000083 040 032 020   
0000084 055 045 02d - 
0000085 145 101 065 e 
0000086 040 032 020   
0000087 047 039 027 ' 
0000088 061 049 031 1 
0000089 057 047 02f / 
0000090 061 049 031 1 
0000091 040 032 020   
0000092 042 034 022 " 
0000093 040 032 020   
0000094 045 037 025 % 
0000095 137 095 05f _ 
0000096 143 099 063 c 
0000097 040 032 020   
0000098 134 092 05c \ 
0000099 156 110 06e n 
0000100 042 034 022 " 
0000101 047 039 027 ' 
0000102 040 032 020   
0000103 044 036 024 $ 
0000104 061 049 031 1 
0000105 012 010 00a \n