tag:blogger.com,1999:blog-47772431483233918132024-03-13T11:28:16.134-07:00justinhj's coding blogThis site is now archived. My new coding posts are here <a href="http://justinhj.github.io" rel="nofollow noopener">http://justinhj.github.io</a>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.comBlogger77125tag:blogger.com,1999:blog-4777243148323391813.post-7725133707691345132016-05-26T11:20:00.000-07:002016-05-26T11:20:02.427-07:00New blog location<br />
<br />
Hi!
I've moved this technical blog to github. Here's the link:<br />
<br />
<a href="http://justinhj.github.io/">justinhj.github.io</a>
<br />
<br />
<br />
<br />
<br />
<br />Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com3tag:blogger.com,1999:blog-4777243148323391813.post-14403501527715578102015-04-22T10:18:00.000-07:002015-04-22T11:47:36.458-07:00Including equations in a blogger postThis is a test of following the guide here <a href="http://www.codecogs.com/latex/integration/htmlequations.php">http://www.codecogs.com/latex/integration/htmlequations.php</a><br />
A sample equation using latex: <br>
<br>
<div lang="latex">
\frac{1+sin(x)}{y}
</div>
<script type="text/javascript" src="http://latex.codecogs.com/latexit.js"></script>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com3tag:blogger.com,1999:blog-4777243148323391813.post-48572841409903728282015-04-17T10:12:00.000-07:002015-04-17T10:12:02.144-07:00Installing RPostgreSQL for R on Max OS YosemiteI went through a painful period of digesting wrong answers to this question on Google. In fact most of the answers are just of the type "this is somebody else's problem so we can't help"<br />
<br />
Anyway this is the eventual sequence of steps I found to install this that works:<br />
<br />
<pre>brew install postgresql
svn checkout http://rpostgresql.googlecode.com/svn/trunk/ rpostgresql-read-only
cd rpostgresql-read-only
R CMD INSTALL --preclean RPostgreSQL
</pre>
<br />
then in R just type library('RPostgreSQL') and you're good to go<br />
<br />
<br />
<br />
<br />
<br />Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com1tag:blogger.com,1999:blog-4777243148323391813.post-70754209616106125072014-06-29T09:47:00.001-07:002014-06-29T09:49:50.617-07:00Easy find<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-H9jPbJaEsBY/U7BDjzQ-8-I/AAAAAAAAIcc/Y9Q9v41pGps/s1600/Screen+Shot+2014-06-29+at+9.48.52+AM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="" border="0" src="http://3.bp.blogspot.com/-H9jPbJaEsBY/U7BDjzQ-8-I/AAAAAAAAIcc/Y9Q9v41pGps/s1600/Screen+Shot+2014-06-29+at+9.48.52+AM.png" height="200" title="" width="180" /></a></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">I found myself typing <span style="background-color: #2c67c8; color: white; font-size: 14px;">find . -name "*.java" | xargs -iHn "something"</span><span style="background-color: #2c67c8; color: white; font-size: 14px;"> </span><span style="background-color: white; color: white; font-size: 14px;"> </span><span style="background-color: white;"><span style="font-size: 14px;">so often I decided to make it into a bash script and put it in a new ~/Dropbox/bin folder so that I never have to do it again. Worse I never use the print0 option which let's you search files that have spaces in the filename, as it's too hard to remember. So, here's the script.</span></span></span><br />
<br />
<div>
<script src="https://gist.github.com/justinhj/f4cca62abf809eb49622.js"></script>
</div>
<div>
<br /></div>
<div>
<br /></div>
Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com0tag:blogger.com,1999:blog-4777243148323391813.post-40721035692810199902014-05-26T10:09:00.000-07:002014-05-26T10:09:23.331-07:00Sending notifications from Emacs (Mac OS X)<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-yDgeaniNYCE/U4NvhCtk5aI/AAAAAAAAIaQ/Z4cS2A8GCto/s1600/notify.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-yDgeaniNYCE/U4NvhCtk5aI/AAAAAAAAIaQ/Z4cS2A8GCto/s1600/notify.png" /></a></div>
<br />
Sending notifications from emacs is something I find useful. In an earlier blog post I talked about how to use Growl to do so. <a href="http://justinsboringpage.blogspot.com/2009/09/making-emacs-growl.html">http://justinsboringpage.blogspot.com/2009/09/making-emacs-growl.html</a><br />
<br />
Well now you don't need Growl any longer. There's a neat github project called terminal notifier <a href="https://github.com/alloy/terminal-notifier">https://github.com/alloy/terminal-notifier</a> which let's you send notifications from the terminal.<br />
<br />
You can install it simply, via Homebrew or Rubygems as follows:<br />
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-bottom: 15px; margin-top: 15px; overflow: auto; padding: 6px 10px; word-wrap: normal;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; box-sizing: border-box; display: inline; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: inherit; margin: 0px; padding: 0px; word-wrap: normal;">$ [sudo] gem install terminal-notifier</code></pre>
OR<br />
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-bottom: 15px; margin-top: 15px; overflow: auto; padding: 6px 10px; word-wrap: normal;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; box-sizing: border-box; display: inline; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: inherit; margin: 0px; padding: 0px; word-wrap: normal;">brew install terminal-notifier</code></pre>
Then you can send notifications using a command like this:<br />
<br />
<div style="background-color: #2c67c8; color: white; font-family: Menlo; font-size: 11px;">
terminal-notifier -message "hello"</div>
<br />
Finally in order to send the notification from emacs we need to write a little Emacs lisp.<br />
<br />
Check out this gist for the code I use:<br />
<br />
<a href="https://gist.github.com/justinhj/eb2d354d06631076566f#file-gistfile1-el">https://gist.github.com/justinhj/eb2d354d06631076566f#file-gistfile1-el</a><br />
<br />
This lets you send a notification in the future using M-x timed-notification<br />
<br />
You are prompted for a time, and the format of that time can be given in a human readable way such as "2 seconds" or "5 minutes" (If you're curious for the allowed options look at the info page in emacs for the function timer-duration )<br />
<br />
Then you are prompted for the message "Go to the store", and the message will be sent.<br />
<br />
The code is very simple, it simply uses run-at-time to run the terminal command in the future. A useful command is find-executable, which given a name will find that executable in your path and run it. This makes configuring tools like this less effort.<br />
<br />
<h3>
Troubleshooting</h3>
Hey if it doesn't work first time what can you do?<br />
<br />
<br />
<ol>
<li>Check if terminal notify is installed correctly by running at terminal</li>
<li>If that succeeds and you don't get a message check if you have enabled do not disturb mode</li>
<li>Otherwise if that succeeds and yet emacs isn't sending messages you likely don't have the executable on the path. M-x customize-variable exec-path</li>
</ol>
<div>
<br /></div>
<div>
<br /></div>
<br />
<br />
<br />
<br />
<br />
<br />Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com4tag:blogger.com,1999:blog-4777243148323391813.post-22316485546760101642014-04-01T09:22:00.002-07:002014-04-01T09:22:35.899-07:00WatchSo this is pretty cool.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-bbGiSRw-5TA/Uzrm2HdtDVI/AAAAAAAAIRA/TmnCE6bvOPQ/s1600/Screen+Shot+2014-04-01+at+9.18.14+AM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-bbGiSRw-5TA/Uzrm2HdtDVI/AAAAAAAAIRA/TmnCE6bvOPQ/s1600/Screen+Shot+2014-04-01+at+9.18.14+AM.png" height="113" width="640" /></a></div>
<br />
The watch command (available linux and on Mac via brew) will run a program every n seconds and display the results in a terminal.<br />
<br />
For example, the following common will show the display above with human readable disk free space on your system. But since the command can be anything you want this is a pretty powerful tool.<br />
<br />
<div style="background-color: #fef49c; font-family: Menlo; font-size: 11px;">
watch -n 3 df -h</div>
<div>
<br /></div>
Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com0tag:blogger.com,1999:blog-4777243148323391813.post-21347898517646258282014-03-12T14:03:00.001-07:002014-03-12T14:03:50.880-07:00Checkout out your DB tablesI was doing some DB work today and wanted to be able to sort all DB tables based on the date they were created. Turns out you can do some neat stuff by looking in the information_schema.tables. For example this shows all the InnoDB tables.<br />
<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>select `table_schema`, `table_name`, `create_time` FROM information_schema.tables where engine = 'InnoDB' order by create_time desc ;
</code></pre>
Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com1tag:blogger.com,1999:blog-4777243148323391813.post-17205612748464485652013-02-06T02:33:00.001-08:002013-06-02T19:06:23.160-07:00Configuring emacs to send iCloud mail on Mac OS X<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://farm6.staticflickr.com/5230/5807619643_392d857dfe_m.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="http://farm6.staticflickr.com/5230/5807619643_392d857dfe_m.jpg" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Pic from ajc1 on Flikr</td></tr>
</tbody></table>
It's handy to be able to send emails from emacs, and this guide will show how to set up SMTP via an iCloud email account.<br />
<div>
<br /></div>
<div>
<b>Step 1. Install gnutls</b></div>
<div>
<b><br /></b></div>
<div>
iCloud requires you to send emails over secure channel, and emacs supports sending email with starttls or gnutls. gnutls is available through <a href="http://mxcl.github.com/homebrew/">brew</a></div>
<div>
<br /></div>
<div>
To install it is easy:</div>
<div>
<br /></div>
<blockquote class="tr_bq">
brew install gnutls</blockquote>
<br />
Wait a few minutes while your Mac gets hot downloading and compiling!<br />
<br />
<b>Step 2. Create an authinfo file</b><br />
<br />
emacs can look in a file ~/.authinfo to find your login credentials, so create that file and fill in the blanks.<br />
<br />
<blockquote class="tr_bq">
touch ~/.authinfo</blockquote>
<blockquote class="tr_bq">
chmod 600 ~/.authinfo</blockquote>
<br />
The contents of the file should read:<br />
<br />
<blockquote class="tr_bq">
machine smtp.mail.me.com port 587 login YOURNAME@icloud.com password YOURPASSWORD</blockquote>
<b>Step 3. Configure emacs</b><br />
<b><br /></b>
Add the following to your .emacs file:<br />
<br />
<br />
(setq<br />
send-mail-function 'smtpmail-send-it<br />
message-send-mail-function 'smtpmail-send-it<br />
user-mail-address "YOURNAME@icloud.com"<br />
user-full-name "YOUR FULLNAME"<br />
smtpmail-starttls-credentials '(("smtp.mail.me.com" 587 nil nil))<br />
smtpmail-auth-credentials (expand-file-name "~/.authinfo")<br />
smtpmail-default-smtp-server "smtp.mail.me.com"<br />
smtpmail-smtp-server "smtp.mail.me.com"<br />
smtpmail-smtp-service 587<br />
smtpmail-debug-info t<br />
starttls-extra-arguments nil<br />
starttls-gnutls-program (executable-find "gnutls-cli")<br />
smtpmail-warn-about-unknown-extensions t<br />
starttls-use-gnutls t)<br />
<br />
Note that your gnutls program may be in a different spot. Find it with:<br />
<br />
<blockquote class="tr_bq">
mdfind -name gnutls-cli </blockquote>
<b>Step 4. Testing</b><br />
<b><br /></b>
To compose an email C-x m<br />
<br />
Enter an email and hit C-c c to send it.<br />
<br />
If it works, great! If not switch to the *Messages* buffer for hints on what may have gone wrong.<br />
<br />
<b>Step 5. Sending emails from elisp code</b><br />
<b><br /></b>
<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>(message-mail recipient subject)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>(message-send-and-exit)))))<br />
<div>
<br /></div>
<br />
<blockquote class="tr_bq">
</blockquote>
<blockquote class="tr_bq">
</blockquote>
Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com8tag:blogger.com,1999:blog-4777243148323391813.post-4282796817996022252012-04-29T12:24:00.001-07:002012-10-14T20:09:05.907-07:00find grep on Mac OS XOn linux machines I search files using find, egrep and xargs as follows:<br />
<br />
find . -name "*.cpp" | xargs -i egrep -iHn "some search string" {}<br />
<br />
this outputs any matches with the filename and number and also disables case dependency.<br />
<br />
On my Mac it doesn't work. I tried reverting to egrep -r (to search recursively) instead, but that doesn't work. It just fails silently too. I tried installing findutils with brew to see if that helped, as often gnu tools are more up to date in brew than in the Apple version, but that didn't help.<br />
<br />
So after some fiddling I found that the syntax below works:<br />
<br />
<br />
find . -name "*.cpp" | xargs egrep -iHn "some search string"<br />
<br />
Only subtly different!<br />
<br />
Actually, hold up, this does not work for filenames that have spaces in them. :(<br />
<br />
Try this instead:<br />
<br />
find . -type f -print0 | xargs -0 egrep -iHn "some search string"<br />
<br />
J.<br />
<div>
<br /></div>
Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com1tag:blogger.com,1999:blog-4777243148323391813.post-40915406497099160142012-03-22T12:18:00.002-07:002012-03-22T12:22:14.015-07:00Starting a program to run in the background from a DOS prompt<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-I2g1lbJiOyA/T2t64XLipRI/AAAAAAAAGZY/ayVTdlwkiVI/s1600/6840890854_6035c7d55d_n.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-I2g1lbJiOyA/T2t64XLipRI/AAAAAAAAGZY/ayVTdlwkiVI/s1600/6840890854_6035c7d55d_n.jpg" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<i>Picture by ro_buk on Flickr</i></div>
<br />
<br />
From a bash shell you can run a command in the background by adding an "&" to the end of the command, but how do you do the same thing in Windows?<br />
<br />
Using the START command lets you run a task in the background (maximised or minimised), or in the foreground.<br />
<br />
For example the following would run memcached in the background minimized.<br />
<br />
C:\>start /min D:\platform\memcached.exe<br />
<br />
Microsoft's documentation is below, but it seems the options have changed. /m does not work but /min does.<br />
<br />
<a href="http://support.microsoft.com/kb/126410">Microsoft's documentation on START</a><br />
<br />Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com1tag:blogger.com,1999:blog-4777243148323391813.post-32204721872045083662011-12-26T10:32:00.001-08:002011-12-26T10:43:48.011-08:00Making a emacs lisp expression expand itself to XML<div><span>My response to the blog article <a href="http://irreal.org/blog/?p=403" style="background-color: rgb(255, 255, 255); font-family: 'Helvetica Neue', Arial, Helvetica, 'Nimbus Sans L', sans-serif; line-height: 1.3em; text-align: -webkit-auto; ">An Emacs Programming Challenge</a></span></div><div><br /></div><div>The goal is to make the emacs lisp record below execute itself and produce XML. My lisp has gotten rusty so it took me a couple of hours to get this working, but I think I got there...</div><div><br /></div><div>You can see it properly formatted and coloured <a href="http://paste.lisp.org/display/126697">here</a><br /><br /></div>It's fairly straightforward. The only complexity is the use of lexical-let. emacs lisp is dynamically scoped, so in the function I create for each keyword, where it prints the symbol name is a free variable at runtime. So if sym-name is not defined you'll get an error, otherwise you'll get whatever it is defined as instead of the value you wanted.<div><br /></div><div>By using lexical-let any variables are bound lexically, that is stored in an environment that stays with the function we create when it is executed (a closure).<br /><pre>(require 'cl) ;; uses lexical-let<br /><br />(defun make-xml-izer(name)<br /> "Given a symbol NAME this makes a function that outputs an xml string for that<br />symbol and using fset binds it to the same symbol so it becomes executable.<br />This pollutes the global function namespace so be careful with which names you<br />pass in"<br /> (lexical-let ((sym-name name))<br /> (fset (intern name)<br /> (lambda(&rest input)<br /> "returns a string representing the xml encoding of the input sexp"<br /> (let ((res (format "<%s>" sym-name)))<br /> (dolist (item input)<br /> (if (listp item)<br /> (setf res (concat res (eval item)))<br /> (setf res (format "%s%s" res item))))<br /> (setf res (format "%s<!--%s-->" res sym-name))<br /> res)))))<br /><br />;; executing this makes all the symbols in the list below executable <br />(mapcar (lambda(s)<br /> (make-xml-izer<br /> (symbol-name s)))<br /> '(record date millis sequence logger level class method thread emessage exception frame line))<br /><br />;; the sample record<br />(record<br /> (date "2005-02-21T18:57:39")<br /> (millis 1109041059800)<br /> (sequence 1)<br /> (logger nil)<br /> (level 'SEVERE)<br /> (class "java.util.logging.LogManager$RootLogger")<br /> (method 'log)<br /> (thread 10)<br /> (emessage "A very very bad thing has happened!")<br /> (exception<br /> (emessage "java.lang.Exception")<br /> (frame<br /> (class "logtest")<br /> (method 'main)<br /> (line 30))))<br /><br /></pre></div>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com0tag:blogger.com,1999:blog-4777243148323391813.post-13107832750016282992011-07-30T00:03:00.001-07:002011-07-30T00:09:08.545-07:00eredis updateI've been busy on my emacs redis client <a href="http://code.google.com/p/eredis/">eredis</a> and it now supports the entire API. It still needs a bit more polish but it should be a workable Redis client now, and I will continue to play with the org-mode table integration which I think has a lot of potential uses: for example making a gui to edit server parameters in just a few seconds. <div><br /></div><div>Also made a new video showing some of the new org table creating commands and the monitor mode that shows the Redis commands as they are run on the server:</div><div><br /></div><div><iframe width="560" height="349" src="http://www.youtube.com/embed/zm9obhWkTdE" frameborder="0" allowfullscreen=""></iframe><br /></div>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com0tag:blogger.com,1999:blog-4777243148323391813.post-46417058609915422062011-07-25T01:06:00.000-07:002011-07-25T01:24:31.059-07:00eredis: a Redis client in emacs lisp<a href="http://4.bp.blogspot.com/-vgnyCCDQNKA/Ti0npIdQ6YI/AAAAAAAAFvQ/iYAfeenzv68/s1600/exampleeredis.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="cursor:pointer; cursor:hand;width: 320px; height: 100px;" src="http://4.bp.blogspot.com/-vgnyCCDQNKA/Ti0npIdQ6YI/AAAAAAAAFvQ/iYAfeenzv68/s320/exampleeredis.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5633202296508705154" /></a><br /><div><br /></div>I set up a google code project today for <a href="http://bit.ly/noZp92"><span class="blsp-spelling-error" id="SPELLING_ERROR_0">eredis</span></a>. A <a href="http://redis.io/"><span class="blsp-spelling-error" id="SPELLING_ERROR_1">Redis</span></a> client in <span class="blsp-spelling-error" id="SPELLING_ERROR_2">emacs</span> lisp. <div><br /></div><div>The program consists of a single <span class="blsp-spelling-error" id="SPELLING_ERROR_3">emacs</span> lisp file<a href="http://code.google.com/p/eredis/source/browse/trunk/eredis.el"> <span class="blsp-spelling-error" id="SPELLING_ERROR_4">eredis</span>.<span class="blsp-spelling-error" id="SPELLING_ERROR_5">el</span> </a> </div><div><br /></div><div><span class="blsp-spelling-error" id="SPELLING_ERROR_6">emacs</span> lisp includes facilities for writing network applications. In my code I use `make-network-process' to open a connection to a specified redis server. Then the Redis api is exposed. </div><div><br /></div><div>One nice feature of emacs I have used is org-table-mode. This lets you edit and manage the data in a Redis server in an org table. For example, you can grab all keys matching a pattern and create an org table from the key value pairs, then edit that table. You can then send it back to Redis with interactive commands that send either the whole table, or just the current row back to Redis using mset or set.</div><div><br /></div><div>This work flow is not safe when working with multiple users, if you care about overwriting each others data. For example, I could store the last values you got from Redis in addition to your edited values. When you go to set a new value I first grab it from Redis, check if it has changed since you got it, and if so warn you (showing you the new value). For many work flows this would work well. For example the use case of a group of users editing a shared DB of configuration data. </div><div><br /></div><div> </div><div><br /></div><div><br /></div>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com2tag:blogger.com,1999:blog-4777243148323391813.post-29212684865088740042011-06-14T15:12:00.000-07:002011-06-14T15:37:32.516-07:00Emacs progress indication<div><div>When programming in emacs lisp, there is an easy way to show progress feedback to the user when a task will take some time. Here's a block of code from the elisp manual showing how to do it.</div><div><br /></div><div>(let ((progress-reporter</div><div> (make-progress-reporter "Collecting mana for Emacs..."</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> 0 500)))<span class="Apple-tab-span" style="white-space:pre"> </span></div><div> (dotimes (k 500)</div><div> (sit-for 0.01)</div><div> (progress-reporter-update progress-reporter k))</div><div> (progress-reporter-done progress-reporter))</div></div><div><br /></div><div>I've incorporated this into my duplicate files code, linked below...</div><div><br /></div><a href="http://code.google.com/p/justinhj-emacs-utils/source/browse/trunk/duplicates.el">http://code.google.com/p/justinhj-emacs-utils/source/browse/trunk/duplicates.el</a><div><br /></div><div><br /></div>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com2tag:blogger.com,1999:blog-4777243148323391813.post-6350361056159801852011-06-05T20:41:00.000-07:002011-06-06T09:47:33.196-07:00More on duplicate file handling in emacs diredI had some good feedback on my last post, that it would be useful to be leave just the superfluous duplicate files marked in the dired buffer. After doing that you can then copy them to another folder, or delete them.<div><br /></div><div>I've added a function to do this `dired-mark-duplicate-files', and updated the google code site with the <a href="http://code.google.com/p/justinhj-emacs-utils/source/browse/trunk/duplicates.el">changes</a>. </div><div><br /></div><div>To copy to another folder use R and select a folder to move the dupes to. In order to delete them hit D. </div><div><br /></div><div><br /></div><div><br /></div>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com3tag:blogger.com,1999:blog-4777243148323391813.post-57383078750961751252011-06-01T21:31:00.000-07:002011-06-01T22:40:49.421-07:00Finding duplicate files in a dired buffer<a href="http://3.bp.blogspot.com/-FpO96rrdz0E/TecTVZCglII/AAAAAAAAFg0/3PT00loebT4/s1600/twins.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="cursor:pointer; cursor:hand;width: 320px; height: 244px;" src="http://3.bp.blogspot.com/-FpO96rrdz0E/TecTVZCglII/AAAAAAAAFg0/3PT00loebT4/s320/twins.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5613476718760203394" /></a><br /><div><br /></div><div>picture by <a href="http://www.flickr.com/photos/donaldmacleod/3439612846/">Donald MacLeod</a></div><div><br /></div><div>This is a an example of programming emacs in emacs-lisp just to give an idea of what you can put together in an hour or two. I was looking at a dired buffer with a bunch of photos in, and some were the same photo that I'd downloaded twice. So I started thinking about writing a utility in emacs to automatically find and remove the duplicate files. In this post I'll just show the code for finding the files and display their filenames in a buffer. </div><div><br /></div><div>I've put the <a href="http://code.google.com/p/justinhj-emacs-utils/source/browse/trunk/duplicates.el">source</a> on google code.</div><div><br /></div><div>After downloading you can load the source into emacs and call `eval-buffer', then open up a dired buffer to try it out. For this to be useful you need some duplicated files, so make some if you need to. </div><div><br /></div><div>Mark the files you want to check for duplicates. For example to mark all jpg files you would type %m to mark files matching a regexp and type .*\.jpg</div><div><br /></div><div>Now execute the command `dired-show-marked-duplicate-files' and after a short delay (in my test 80 jpg photos took about 5 seconds) you'll see a buffer called 'Duplicated files' which contains a list of the files which have the same contents. </div><div><br /></div><div>Next steps for this little project will be to give you an interactive way to delete the duplicated files. I haven't decided quite how I'd like that to work, drop me an email if you have an idea. I've been thinking about perhaps resetting which files are marked so that only the duplicates are marked. At that point you can then hit R to move them to another spot, or delete them with x.</div><div><br /></div><div>Now some comments about the code involved...</div><div><br /></div><div>Most of the work is done in the function dired-show-marked-duplicate-files. First line " (interactive)" makes it an interactive function, meaning the user of emacs can invoke it. </div><div><br /></div><div> "(if (eq major-mode 'dired-mode)" will check that we're in the right kind of buffer, because it makes no sense to run this in another mode. </div><div><br /></div><div>In order to find the duplicate files I just need to walk the list of marked files, generate the md5 value of the contents of each one and add it to hash table. The keys in the hash table will be the md5, and the values will be a list of files with that md5. Once we've done that, finding duplicates is a simple matter of walking the hash table keys and displaying any where the value has multiple entries.</div><div><br /></div><div>"(let ((md5-map (make-hash-table :test 'equal :size 40)))" Creates the hash table, making sure we use 'equal to match our filenames.</div><div><br /></div><div><div>"(let ((filenames (dired-get-marked-files)))" this gets the marked files as a list of filenames</div><div><br /></div><div>The next little bit of code is just to store the item in the hash table after getting the md5. There's no function in emacs to get the md5 of a file, but you can get the md5 of a string, so I wrote a helper function for getting the contents of a file into a temporary buffer first. </div></div><div><br /></div><div><div>(defun md5-file(filename)</div><div> "Open FILENAME, load it into a buffer and generate the md5 of its contents"</div><div> (interactive "f")</div><div> (with-temp-buffer </div><div> (insert-file-contents filename)</div><div> (md5 (current-buffer))))</div></div><div><br /></div><div>Finally I want to display the results, so I create a buffer and then use maphash (walks the keys of a hash table executing a function on each) with a helper function `show-duplicate' which simply writes the values of the hash table entry into that buffer. </div>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com9tag:blogger.com,1999:blog-4777243148323391813.post-35625747884500261752011-04-26T15:12:00.000-07:002011-04-26T15:41:20.982-07:00Programmer tips for Mac OSXSome tips for programmers on the Mac.<div><br /></div><div>emacs: the best place to get emacs for Mac seems to be here <a href="http://emacsformacosx.com/">http://emacsformacosx.com/</a> which is also the most no nonsense website design ever</div><div><br /></div><div>Not really a Mac tip, but I stick my .emacs configuration file in a Dropbox folder, along with any emacs libraries and emacs lisp code I write. Then where-ever I install emacs I make a simple .emacs that points to the one in the Dropbox folder. This also forces me to make sure any platform specific emacs stuff is properly handled. </div><div><br /></div><div>Clipboard: copy and paste between the terminal and other apps can be done with pbcopy and pbpaste. For example a long complicated command line you want to email to yourself, just do:</div><div><br /></div><div>echo "long complicated bash command line you don't want to retype" | pbcopy </div><div><br /></div><div>And then you can Command-V that into your email window. Going the other way is just as simple; Command-C the text you want and pop it into the terminal window with pbpaste.</div><div><br /></div><div>Open: If you want open an application from the command line you can do it like this:</div><div><br /></div><div><div>open -a SomeApp /Users/yourname/SomeFile.hai</div></div><div><br /></div><div>You can open a folder in finder </div><div><br /></div><div>open /Folder/</div><div><br /></div><div>or </div><div><br /></div><div>open /Folder/SomeFile.hai</div><div><br /></div><div>to open that file with it's default application.</div><div><br /></div><div>Check out the help 'man open', to see other stuff like how you pipe stdout into an application. </div><div><br /></div><div>Finally check out this guys OpenTerminalHere script. This pops an icon in finder that lets you open a terminal window in the highlighted folder. </div><div><br /></div><div><a href="http://www.entropy.ch/software/applescript/">http://www.entropy.ch/software/applescript/</a></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div> </div>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com0tag:blogger.com,1999:blog-4777243148323391813.post-22338557473991645162011-04-26T15:00:00.000-07:002011-04-26T15:04:57.269-07:00MovieRatingsA little side project I did when learning about Clojure was to grab movie ratings from Rotten Tomatoes, which I did a post about here:<div><br /></div><div><a href="http://justinsboringpage.blogspot.com/2011/01/grabbing-rotten-tomatoes-movie-ratings.html">http://justinsboringpage.blogspot.com/2011/01/grabbing-rotten-tomatoes-movie-ratings.html</a></div><div><br /></div><div>This is just an update that I've posted the whole leiningen project onto github </div><div><br /></div><div><a href="https://github.com/justinhj/movieratings">https://github.com/justinhj/movieratings</a></div><div><br /></div><div><br /></div><div><br /></div>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com0tag:blogger.com,1999:blog-4777243148323391813.post-91748749713681093112011-04-25T17:40:00.000-07:002011-04-25T19:56:15.010-07:00Talking to mysql from Python on Mac OS X 10.6<a href="http://2.bp.blogspot.com/-NKqwp2W_YmM/TbY0OvSTHsI/AAAAAAAAFSk/CIPn706RWrU/s1600/2923859802_c8a8dc9f5a_z.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="cursor:pointer; cursor:hand;width: 379px; height: 400px;" src="http://2.bp.blogspot.com/-NKqwp2W_YmM/TbY0OvSTHsI/AAAAAAAAFSk/CIPn706RWrU/s400/2923859802_c8a8dc9f5a_z.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5599720614497820354" /></a><br /><div><span class="Apple-style-span" ><br /></span></div><div><span class="Apple-style-span" ><br /></span></div><div><span class="Apple-style-span" >image by <a href="http://www.flickr.com/photos/spullara/2923859802/">Sam Pullara</a></span></div><div><br /></div><div>Here's a problem I couldn't solve with Google, although it seems to be a moving target so YMMV. </div><div><br /></div><div>I wanted to do some work driving a MySQL database with Python. On Windows and Linux I've used MySQLdb so I decided to do the same on Mac. </div><div><br /></div><div>For reference I got mysql (client and server) through mac ports.</div><div><br /></div><div><div>mysql5 --version</div><div>mysql5 Ver 14.14 Distrib 5.1.45, for apple-darwin10.4.0 (i386) using readline 6.1</div></div><div><br /></div><div>and Python is the stock version:</div><div><br /></div><div><div>Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) </div><div>[GCC 4.2.1 (Apple Inc. build 5646)] on darwin</div></div><div><br /></div><div>First download from here <a href="http://sourceforge.net/projects/mysql-python/">http://sourceforge.net/projects/mysql-python/</a> and extract the file somewhere...</div><div><br /></div><div>mkdir ~/pythondb</div><div>cd ~/pythondb</div><div>tar -vxf ~/Downloads/MySQL-python-1.2.3.tar.gz </div><div><br /></div><div>Then you need open up the site.cfg file and make a change as below. Your mysql_config5 maybe in a different spot. You can find out with the command 'which mysql_config5'.</div><div><br /></div><div></div><blockquote><div># The path to mysql_config.</div><div># Only use this if mysql_config is not on your PATH, or you have some weird</div><div># setup that requires it.</div><div>mysql_config = /opt/local/bin/mysql_config5</div></blockquote><div></div><div>Now execute the following:</div><div><br /></div><div>python setup.py build</div><div>python setup.py install</div><div><br /></div><div>If everything works you can now import MySQLdb in your python program and start interacting with mysql. </div>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com0tag:blogger.com,1999:blog-4777243148323391813.post-18794810655950426162011-01-15T10:22:00.001-08:002011-01-15T10:58:02.133-08:00Grabbing Rotten Tomatoes movie ratings with Clojure<a href="http://www.flickr.com/photos/chocolateforest/3237898945/" title="Untitled by Gammelmark, on Flickr"><img src="http://farm4.static.flickr.com/3129/3237898945_9402ea242d.jpg" width="500" height="333" alt="" /></a><div><br /></div><div><a href="http://www.flickr.com/photos/chocolateforest/3237898945/" title="Untitled by Gammelmark, on Flickr"></a>flikr pic by <a href="http://flic.kr/p/5W85xT">Gammelmark</a><br /><br />Currently I'm teaching myself Clojure from Stuart Halloway's excellent book <a href="http://www.amazon.com/Programming-Clojure-Pragmatic-Programmers-Halloway/dp/1934356336/ref=sr_1_1?ie=UTF8&s=books&qid=1295117421&sr=8-1">Programming Clojure</a>. Here's my first program that does something; a simple web page scraper to get the critics and audience ratings for movies off Rotten Tomatoes. Here's how it looks at the REPL:</div><div><br /><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>rottentomatoes.core> (pmap-get-movie-ratings "lord of the rings")<br />movie url: http://www.rottentomatoes.com/m/lord_of_the_rings_the_return_of_the_king/<br />Audience 83<br />Critics 94<br />movie url: http://www.rottentomatoes.com/m/lord_of_the_rings_the_fellowship_of_the_ring/<br />Audience 92<br />Critics 92<br />movie url: http://www.rottentomatoes.com/m/lord_of_the_rings_the_two_towers/<br />Audience 92<br />Critics 96<br />movie url: http://www.rottentomatoes.com/m/lord_of_the_rings/<br />Audience 74<br />Critics 50<br />movie url: http://www.rottentomatoes.com/m/master_of_the_rings_the_unauthorized_story_behind_jrr_tolkiens_the_lord_of_the_rings/<br />Audience 34<br />Critics null<br />movie url: http://www.rottentomatoes.com/m/jrr-tolkien-and-the-birth-of-the-lord-of-the-rings/<br />Audience 93<br />Critics null<br />movie url: http://www.rottentomatoes.com/m/jrr_tolkien_and_the_birth_of_the_lord_of_the_rings/<br />Audience 32<br />Critics null<br />movie url: http://www.rottentomatoes.com/m/more_at_imdbpro_creating_the_lord_of_the_rings_symphony_a_composers_journey_through_middle_earth/<br />Audience 100<br />Critics null<br />nil<br /><br /></code></pre><br />I use <a href="http://bit.ly/dV7g6y">leiningen</a> to develop with Clojure (it's like Maven for Java), so if you want to build the project here's my project configuration that includes the dependencies used. I'm using swank-clojure which enables the REPL to function with emacs slime. http.async.client is a clojure API that builds on Netty and I use that for the GET requests to the Rotten Tomatoes server.<div><br /></div><div><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code><br />(defproject rottentomatoes "1.0.0-SNAPSHOT"<br />:description "Clojure code to grab movie ratings from Rotten Tomatoes"<br />:dependencies [<br /> [org.clojure/clojure "1.2.0"]<br /> [org.clojure/clojure-contrib "1.2.0"]<br /> [http.async.client "0.2.1"]<br /> ]<br />:main rottentomatoes.core<br />:dev-dependencies [<br /> [swank-clojure "1.2.1"]<br /> ]<br />)<br /><br /></code></pre></div><div>And here's the code:</div><div><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code><br />(ns rottentomatoes.core<br />(:gen-class)<br />(:require<br />[clojure.contrib.str-utils2 :as s]<br />[http.async.client :as c]))<br /><br />(import [java.net URLEncoder]<br /> [java.lang.Character])<br /><br />(def *base-url* "http://www.rottentomatoes.com")<br />(def *search-end-point* "/search/full_search.php?search=")<br /><br />(defn first-match-after [re1 re2 seq]<br />"Splits the sequence SEQ using RE1 then searches after the first match and before the next match for the first occurence of RE2"<br />(let [[_ _ after] (s/partition seq re1)]<br /> (re-find re2 after)))<br /><br />(defn response-status-code [resp]<br />(:code (c/status resp)))<br /><br />(defn scoop-url [url]<br />"Use the http client to do a GET on the url"<br />(let [resp (c/GET url)]<br /> (c/await resp)<br /> [(response-status-code resp) (c/string resp)]))<br /><br />;; Get movie urls<br />;; Does a search of Rotten Tomatoes for the search text, then scrapes the results<br />;; for the page for each movie. Returns a collection of the movie urls<br /><br />(defn get-movie-urls [search-text]<br />(let [encoded-search-text (URLEncoder/encode search-text)<br /> [code body] (scoop-url (str *base-url* *search-end-point* encoded-search-text))<br /> ]<br /> (when (= code 200)<br /> (let [[_ _ after] (s/partition body #"<span>Title</span>")]<br /> (let [[_ & results] (s/partition after #"\"(/m/.*/)\"")]<br /> (map #(str *base-url* (second %)) (take-nth 2 results)))))))<br /><br />;; Given a movie url GET the page then scrape it for the citic and audience rating<br /><br />(defn get-movie-rating [movie-url]<br />(let [[code body] (scoop-url movie-url)]<br /> (if (= code 200)<br /> {:critics (second<br /> (first-match-after #"class=\"critic_side_container" #">([0-9]+)<" body))<br /> :audience (second<br /> (first-match-after #"class=\"fan_side" #">([0-9]+)<" body))}))) <br /><br />;; Finds the ratings for all Rotten Tomatoes movies that match the search string and prints them out<br /><br />(defn get-movie-ratings [search-str]<br />(let [urls (get-movie-urls search-str)]<br /> (when (> (count urls) 0)<br /> (doseq [url urls]<br /> (let [ratings (get-movie-rating url)]<br /> (printf "movie url: %s\n\tAudience %s\n\tCritics %s\n" url (:audience ratings) (:critics ratings)))))))<br /><br />;; Slight variant on above that uses pmap so that the requests are done in parallel<br /><br />(defn pmap-get-movie-ratings [search-str]<br />(let [urls (get-movie-urls search-str)]<br /> (when (> (count urls) 0)<br /> (let [ratings (pmap #(get-movie-rating %) urls)<br /> url-and-ratings (map vector urls ratings)]<br /> (doseq [[url ratings] url-and-ratings]<br /> (printf "movie url: %s\n\tAudience %s\n\tCritics %s\n" url (:audience ratings) (:critics ratings)))))))<br /></code></pre></div><div>I'm using the str-utils2 module for it's regex function partition, which will split a sequence up by regex matches. This made it easy to write the function `first-match-after', which finds a regex then finds the first occurrence of some text after that regex. </div><div><br /></div><div>It was so easy to parallelize the requests. My first attempt at get-movie-ratings retrieved each movie page synchronously. By using pmap I was able to make it do the requests via thread pools, and thus return in a few seconds for many movie matches. </div><div><br /></div>The code is much shorter than it would have been in Common Lisp, at least the way I program. I love the destructuring syntax, and that maps, vectors and lists can be returned from functions and manipulated without much effort. <div><br /></div><div>I'm still new to Clojure so if you feel you can improve the code or have any feedback please let me know.<br /><div><br /></div></div></div>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com4tag:blogger.com,1999:blog-4777243148323391813.post-21520060067124199992011-01-11T11:09:00.000-08:002011-01-15T10:07:37.719-08:00View Data from the Clojure REPLHere's a nice debugging feature in Clojure. The inspect module lets you look at variables in a popup JFrame. The two examples below show how you quickly view data in a table or tree format. This is really handy to quickly view data from the REPL.<br /><br />(require 'clojure.inspector)<br /><br />(clojure.inspector/inspect-tree '(1 (a b) 2 (c d) 3 (e f )))<br /><br /><div><a href="http://4.bp.blogspot.com/_nkGbjVeC3i4/TTHh9yXhqbI/AAAAAAAAFIc/TENgl2G5uzI/s1600/inspect_tree.png"><img src="http://4.bp.blogspot.com/_nkGbjVeC3i4/TTHh9yXhqbI/AAAAAAAAFIc/TENgl2G5uzI/s320/inspect_tree.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5562475466387990962" style="cursor: pointer; width: 320px; height: 273px; " /></a></div><div>(clojure.inspector/inspect-table '((1 2 3) (a b c) (e f g)))<br /><br /><a href="http://4.bp.blogspot.com/_nkGbjVeC3i4/TTHh5GiErVI/AAAAAAAAFIU/yOK5Eudd5Ng/s1600/inspect_table.png"><img src="http://4.bp.blogspot.com/_nkGbjVeC3i4/TTHh5GiErVI/AAAAAAAAFIU/yOK5Eudd5Ng/s320/inspect_table.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5562475385901591890" style="cursor: pointer; width: 320px; height: 156px; " /></a><br /></div>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com1tag:blogger.com,1999:blog-4777243148323391813.post-28612240124249000212010-12-15T10:26:00.000-08:002010-12-15T12:29:00.447-08:00F# vs C#<div>Nice article comparing directly some code written in C# vs one in F#</div><div><br /></div><a href="http://sharp-gamedev.blogspot.com/2010/12/on-performance-of-f-on-xbox-360.html">http://sharp-gamedev.blogspot.com/2010/12/on-performance-of-f-on-xbox-360.html</a><div><br /></div><div><a href="http://sharp-gamedev.blogspot.com/2010/12/on-performance-of-f-on-xbox-360.html"></a>What's interesting is that now that VM's are starting to become the new platforms, we are starting to be less restricted by language choice. When it's native code with hand crafted memory management you want, it has to be C++. </div><div><br /></div><div>But when you start to look at the JDK and the .Net VM's, the language choice has far less impact on performance... after all you're using the same garbage collector, same base libraries and so on. </div><div><br /></div><div>This is great news for those of us with more peculiar tastes in language (I like Clojure and Common Lisp for example).</div><div><br /></div><div>Although I think it will be a few years until AAA console games run on VM's, if ever, due to the nature of that business. Memory is always at a premium, and the goal is to choke every last hz of CPU performance. </div><div><br /></div><div><br /></div><div><div><br /></div><div><br /></div></div>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com0tag:blogger.com,1999:blog-4777243148323391813.post-16763734773298371062010-11-02T11:04:00.000-07:002010-11-02T11:11:07.168-07:00Just browsingIt's handy in emacs to be able to go straight to your browser to view a page, and you can do fancy stuff with `webjump' as I mentioned in a <a href="http://justinsboringpage.blogspot.com/2009/05/emacs-searching-programming-apis-with.html">previous post</a>.<br /><br /><div>Another handy function is `browse-url' which will prompt for the url but default to whatever your point is at. </div><div><br /></div><div>If you're in a html file and you'd like to open that with your browser then `browse-url-of-file' will open it up.</div><div><br /></div><div>Finally, and I just found this today, if you have some html code in a buffer that isn't even a file, you can open that in your browser to using `browse-url-of-buffer' and emacs will write it to a temporary file and open that in the browser for you. </div><div><br /></div><div><br /></div>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com3tag:blogger.com,1999:blog-4777243148323391813.post-39500189876801566582010-10-19T16:14:00.000-07:002010-10-19T16:15:05.318-07:00rgrep on windows 7 for emacsI lost an hour configuring this, so seems worthy of a blog post.<br /><br />A fresh install of <a href="http://ftp.gnu.org/gnu/emacs/windows/">emacs for windows</a> will have functionality that does not work because it depends on unix style utilities.<br /><br />One very useful example is the command rgrep, which searches files recursively through subfolders looking for a regular expression in those files.<br /><br />Under the hood it uses the unix command line tools find, and egrep. Unfortunately the windows version of find takes entirely different parameters and will not function. In fact you will get an error that looks like this:<br /><br />FIND: Wrong parameter format<br /><br />Using the set of native ports of Unix command line tools <a href="http://sourceforge.net/projects/unxutils/">UnxUtils </a>you can easily fix this:<br /><br /><ol><li>Download the zip file and extract it to c:\unxutils</li><li>Add the following path to the very front of your path by editing your system environment variables C:\unxutils\usr\local\wbin\;</li></ol><div>That's it. You can run rgrep now and hopefully you're up and running. </div><div><br /></div><div>If not make sure you have restarted emacs so it picks up the new setting of PATH. Open a shell in emacs and type 'find --version'. You should see something like this if your path is configured correctly:</div><div><br /></div><div><div>c:\find --version</div><div>find --version</div><div>GNU find version 4.1</div></div><div><br /></div><div>and if not you will see:</div><div><br /></div><div><div>C:\Windows\system32>find --help</div><div>FIND: Parameter format not correct</div></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com4tag:blogger.com,1999:blog-4777243148323391813.post-63323960530219691672010-07-30T14:55:00.000-07:002010-07-30T15:08:46.359-07:00Couple of mysql tips<b>Wondering what the heck is going on on your mysql DB?</b><div><br /></div><div>show processlist ;</div><div><br /></div><div>Shows you all the active threads, which is very handy indeed. It shows what each thread is doing, and how long it has been doing it for.</div><div><br /></div><div><b>Thread safe record insertion</b></div><div><b><br /></b></div><div>When doing a record insert, another thread could be trying to insert a record that would violate any DB contraints, and if it gets there before you, then your insert will fail. </div><div><br /></div><div>There may be cases where you want don't want to have it fail and try again; you may want to take a different action if the record already exists. For example lets say you have some data like this, where the Name is a unique key...</div><div><br /></div><div>Name, Number of products purchase</div><div>Bob, 1, </div><div>Ben, 2,</div><div><br /></div><div>Now if two threads try to insert a user 'Roger' who has just bought an item, then the one that arrives at the server last will fail. </div><div><br /></div><div>INSERT INTO purchase (Name, PurchaseCount) VALUES ('Roger', '1') ON DUPLICATE KEY UPDATE PurchaseCount=PurchaseCount+1;</div><div><br /></div><div>This will handle the key collision and execute the update clause instead, in the event that somebody beat you to it. This makes it much easier to write thread safe code that adds records.</div><div><br /></div><div><br /></div><div><b><br /></b></div><div><b><br /></b></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div>Justinhttp://www.blogger.com/profile/05978765743088322110noreply@blogger.com0