Archive

Posts Tagged ‘OS X’

TextMate Sql Formatter Command

October 27th, 2009

Recently, I am doing some heavy database migrations, so I spend a lot of time on playing with SQL again. It’s fun as always. But there are some SQL files are quite long and messy. There is no problem on running, but it’s really painful to look at and do any changes.

So I went out and tried to find any SQL Formatters. There are quite a few and I’ve tasted them as many as I can.

At the end, I found myself really enjoy using Instant SQL Formatter from Gudu Software. It has a free online sql tidy tool and it’s very powerful:

Instant SQL Formatter is a free online sql tidy tool, actually, it not only can beautify your sql but also can turn your formatted sql into html code, so you can post coloured sql code in your blog, forum,wiki and any website easily. In addition to beautifying SQL code, this sql tool can translate SQL code into C#, Java, PHP, DELPHI and other program languages. Another useful feature is find out all database objects such as table, column, function in sql by selecting output format to list database object.

Here is the Free online Tool and here are some examples you can see. Quite impressive! To format your SQL, you just need paste the sql in the textarea, choose the database and output format then press “Format SQL”, you’ll get the result right away.

Every SQL file looks great now. But after tens of copy & paste and copy & paste between TextMate and browser, it feels not as smooth as I want. I think I should find a better way.

Gudu software does provide some desktop version even add-ins, sadly there are all Windows based. It’s not a option for me.

After reading the page source of their free online tool, here is the result:

#!/usr/bin/env ruby

require 'net/http'

url = 'http://www.dpriver.com/cgi-bin/ppserver'
url = URI.parse(url)
http = Net::HTTP.new(url.host, url.port)

query = "<sqlpp_request><dbvendor>mysql</dbvendor><outputfmt>SQL</outputfmt><inputsql>#{ENV['TM_SELECTED_TEXT']}</inputsql><formatoptions><keywordcs>Uppercase</keywordcs><identifiercs>Lowercase</identifiercs><functioncs>InitCap</functioncs><lnbrwithcomma>after</lnbrwithcomma><liststyle>stack</liststyle><salign>sleft</salign><quotechar>\"</quotechar></formatoptions></sqlpp_request>"

header = {
  'Referer' => 'http://www.dpriver.com/pp/sqlformat.htm',
  'User-Agent' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.1) Firefox/3.0.1'
}

resp, data = http.post(url.path, query, header)

puts resp.error! unless data
formatted_sql = data[/<formattedsql>.*<\/formattedsql>/m].gsub(/<\/?.*>/, '')

puts formatted_sql

Download TextMate SqlFormatter Command

How to install?

After save to your own disk, unzip it, just open those tmCommand files and add them into your TextMate. The shortcut key has been set to Command+Shift+F for now.

As you can see there are two tmCommand files. The “SQL Formatter – Stack” will format you sql with every fields has its own line, the “No Stack” one will put all the fields into one line. Try them and you’ll see the difference.

How to use it?

Open TextMate,  select the SQL query you want to format and press Command+Shift+F. The beautiful formatted SQL will replace the selected SQL “instantly”!

Requirement?

The command is using free online Instant SQL Formatter, so the internet is required.

What’s next?

As I said before, SQL Pretty Printer is really powerful. I really should create a complete TextMate Bundle instead of just one command. But before doing this, I should get the permission from them now.

Any update will be posted here, hopefully soon.

Enjoy the SQL Formatter Command and stay tuned for more.

Database, English, Mac, OS X, Ruby, TextMate , , , , ,

TextMate Shortcuts Desktop

August 23rd, 2009

I’ve been using this TextMate shortcuts Desktop Wallpaper for two years already, it’s really helpful, no matter how long have you used TextMate. And, did we missed anything new about TextMate in the past two or three years? I don’t think so.

Snow Leopard is here already, but we still know nothing about TextMate 2.

Download ↓

TextMate Keyboard Shortcuts Desktop Wallpaper 1280 x 800

TextMate Keyboard Shortcuts Desktop Wallpaper 1920 x 1200

Source: Scott Boms

Apple, Mac, OS X, Ruby, TextMate , , , ,

Less is better, than tail

July 27th, 2009

I’ve been using tail to watch my log files for years:

tail -f log/production.log

It works great all the time, until you want to search for something, then you have to ctrl+c and open the file in less or vi.

Maybe there is a better way? After some googling, I found less is the answer:

less +F log/production.log

less +F works exactly like tail -f, with more:

  • Simply press ctrl+c to switch to editing model, so you can scroll backward and using any more/vi command, such as /pattern to search
  • Press shift+f again to switch back to tail model

Anyway, just run man less to find some more information.

English, OS X , ,

Coda 1.5 entering limited private beta

July 8th, 2008

One of my favorite editor on Mac is Coda, the most important part for me is in their tagline:

Compare with my another favorite editor, TextMate, every time I open it, I will open three more windows at the same time:

  • Terminal for running application
  • Terminal for mysql
  • Browser for view my pages and documents

Coda has all of these and even more:

Text editor + Transmit + CSS editor + Terminal + Books + More = Whoah.

But, on another side, leaking of version control and no powerful bundles as TextMate keep a lot of Ruby developers out of it.

Things may change:

After a lot of work, we’re finally ready to work with some people to test Coda 1.5 — the next major release of Coda — and prepare it for the general public.

To enter Coda 1.5 limited private beta, go to:
http://www.panic.com/hive/
If registration is still available, the registration link will be in the upper-right corner of the page. (If there’s no link, we’re full.)

So what’s new in Coda 1.5?

  • Better Search and Replace?
  • Source Control Support (SVN or Git)?
  • Custom Books? Add more Ruby Document in it?
  • Better Support for more than one languages mix together in one file?

Stay tuned. :)

* Unless you want to use more than one window. Which is totally cool.

Apple, English, Mac, OS X, Ruby, TextMate , , , ,

iftop – Find out who is eating your bandwidth

July 3rd, 2008

iftop: display bandwidth usage on an interface

How to install?

  • Download and install the Universal Binary from here
  • Or if you already have MacPort installed

sudo port install iftop

How to use it?

  • run “ifconfig -l” or “/Applications/Utilities/Network\ Utility.app” to get your network interface id.

  • In my case is ‘en1′, so I just type into Terminal:

sudo iftop -i en1

Enjoy!
Tales From The Command Line: Where Has My Bandwidth Gone?

Apple, English, Mac, OS X, Software ,

Firefox Keyboard Shortcuts on Mac

June 25th, 2008

Top Ten Firefox Keyboard Shortcuts

1. ⌘ + l = focus address bar
2. ⌘ + d = bookmark current page
3. ⌘ + k = focus google search bar
4. ⌘ + f = find
5. ⌘ + g = find next
6. ⌘ + t = new tab
7. ⌘ + w = close current tab
8. ⌘ + shift + t = reopen accidentally closed tab (Best one ever!)
9. crtl + tab = tab through tabs
10. crtl + shift + tab = tab backwards through tabs

Bonus for Delicious Extension users:

⌘ + Shift + . = pulls delicious page if you have delicious firefox extension installed

Apple, English, Mac, OS X, Software , ,

Mondrianum gets a update!

June 19th, 2008

Mondrianum is one of my favorite color pickers on Mac OS X, as it brings all the goodies from Adobe® kuler, the best color themes sharing community!

The last version of Mondrianum, 1.0b5 had exired on June 14, even it is still a freeware now. So two authors did a quick update and sent an apology out, which I think is great.

You can download the latest version from their site, and this version could be used until Sep. 30, 2008. I believe they will release another before that day.

The most interested part for me is not the post or software itself, it is the comment! One of the visitors left a comment said “I love your product and what you are doing… For the heck of it I slightly edited your statement to make the english flow a little more ‘natively.’”

What a lovely reader! I wish I could have some of them too!

Anyway, before they could update the post, I did a quick diff on them:

So, my dear readers, if you find anything wrong in my posts, please leave a comment. I would love to fix it!

Thanks! :)

English, Mac, OS X , ,

Java SE 6 on Leopard, Officially!

April 29th, 2008

Half a year after Leopard has been released, we finally get an official Java SE 6 from Apple today!

Java for Mac OS X 10.5 Update 1 adds support for Java SE 6

Thanks Apple! Anyway…

As you can see from the description:

This update does not replace the existing installation of J2SE 5.0 or change the default version of Java.

So if you want to make Java SE 6 your default version of Java, there is one thing you need to do:

sudo ln….. OK, no command line this time.

Here is the right way to do:

  1. Launch /Applications/Utilities/Java/Java\ Preferences.app
  2. Drag “Java SE 6 (64-bit)” to the top of the “Java Application runtime Setting”
  3. Save

You could change Java Applet Runtime Version to J2SE 6 too, but please make sure you know you really need it.

Enjoy!

Apple, English, Java, Mac, OS X , , ,

Update RubyGems to new Version on Leopard

April 3rd, 2008

RubyGems just updated to version 1.1.0. Couple of the major changes are “Index updates are much faster now” and “only updates from a latest index by default”. So, time to update.

As Leopard already has Ruby and RubyGems preinstalled (Thanks, Apple!). So the default update way:

$ sudo gem update –system

will NOT work well.

Here is what you should do on Leopard 10.5.2:

$ sudo gem install rubygems-update
$ sudo update_rubygems

Enjoy!

Apple, Mac, OS X, Ruby , , , , ,

Fix New MacBook Pro AirPort problem

April 2nd, 2008

I’ve got my Shinning super cool new MacBook Pro two weeks ago. Everything works fine until recently after some automatic updates.

The MacBook Pro I have is 2.4GHz 15′ version. I am so loving it! But the AirPort problem is really annonying!

For some reason, at the end of the day, pretty much every day, MacBook Pro wireless connection just suddenly stop working with my AirPort Extreme. But at the same time my old MacBook works just fine. Turn MacBook Pro AirPort off and on, and try to connect to my wireless network again and again. Nothing helps. Rebooting AirPort Extreme again and again just helps a little. Some logs on console:

airportd Error: Apple80211Associated() failed -6

_emUIServer Error: airport MIG failed = -6 ((null) port = 45523

Did a google search and found a lot of people do have the same problem and so far there is no good solution yet. Some of them said go back to 10.5.1 actually fix the problem, and this is a suggestion from Apple Genius. Which I think is a solution but it is for away from good. I don’t really want to downgrade as I already installed too much into my Leopard and spent amount of time to make it works smothly as what my MacBook does.

This is really pain!

Spend some more time these two days and did some more tests. Finally have good progress. But couple of the tests is really risky, such as, Leopard told me no AirPort Card installed after rebooting. :D

Anyway, here is the simplest but working solution:

  1. Find your original “MacBook Pro Mac OS X Install Disc 1″, please make sure it is yours, not somebody else’s!
  2. copy /System/Library/Extensions/IO80211Family.kext from “Mac OS X Install Disc 1” overwrite to your Macintosh\ HD/System/Library/Extensions/IO80211Family.kext
  3. After couple of seconds, Leopard will pick up your changes and your MacBook Pro will link back to wireless network again without any problem!

Yes, you don’t even need a reboot! :)

If you couldn’t find your original install disc 1, you still can use someone’s if them have the same model as your MacBook Pro. But make sure do a backup for IO80211Family.kext.

Enjoy!

Maxwell Rocatanski suggested Pacifist for whom aren’t as comfortable using the terminal. Thanks MaxWell!

Apple, Mac, OS X , , , , ,