Writing Source Code in WordPress December 13, 2009
Posted by vyolian in development.1 comment so far
I always find myself looking this up and the search results being really bad. This is for easy access for myself. From http://en.support.wordpress.com/code/posting-source-code/.
[sourcecode language="<language from below>"]
...your code here...
[//sourcecode] <- except only single slash.
And languages that I actually care about:
- bash
- cpp
- csharp
- css
- java
- javascript
- bash
- ruby
- sql
- xml
Postgres 8.4 with Ubuntu 9.10 December 7, 2009
Posted by vyolian in database, development.1 comment so far
I just upgraded my distribution from 9.04 to 9.10 and I was very confused when postgres suddenly decided not to work. Short story is that Postgres 8.4 configured itself to use port 5433 instead of 5432 probably because 8.3 is still using that port.
So before you think you’re crazy and jump into resetting your postgres password or changing listen_address to ‘*’, make sure you take a good look at the port number. The relevant files are in /etc/postgresql/8.4/main. Then do a restart with sudo /etc/init.d/postgresql-8.4 restart.
Ubuntu Jaunty, VirtualBox, and IE6/7/8 September 11, 2009
Posted by vyolian in development.Tags: ie6, IE7, ie8, jaunty, ubuntu, virtualbox
2 comments
There are lots of sources on this already (see bottom) but I must have been an uber-noob for none of them to exactly work for me. This is just for myself to document how to test on IE6/7/8 with VirtualBox on Ubuntu Jaunty:
1. sudo apt-get install virtualbox-3.0 wine
2. Download one of the exe files from Internet Explorer Application Compatibility VPC Image page.
- The download takes about 30-40 minutes.
- For the Vista ones, you have to download the exe and the rar files.
- You’ll be repeating this process starting from this step for each IE version / Windows OS you want to test with.
3. wine [IE_number-OS_name].exe
- Go through the installation with defaults.
- At the end, you should have a .vhd file.
4. Create new VM
- VirtualBox
- New -> Give it a name (“WinXP”) and select the appropriate operating system -> Choose RAM (512 for me).
- At the Virtual Hard Disk screen, Existing -> Add -> Select .vhd from earlier.
- At the end, you should see your new VM in the list.
5. Install Guest Additions
- Select your new VM -> Start.
- Cancel all the prompts when Windows starts up.
- Devices (in the outermost VM window) -> Install Guest Additions.
- Restart windows when you’re done.
6. Back on Linux, Download PCnet Driver
- Download the latest AMD PCnet driver
- sudo apt-get install brasero
- brasero
- Project -> New Project -> New Data Project
- Add -> Browse to the zipped driver -> Burn
7. Back in Windows, Install PCnet Driver
- Devices -> Mount CD/DVD-ROM -> CD/DVD-ROM image
- Add -> The ISO you got from the previous step
- Open the drive -> Move and unzip the file into a folder
- Start -> Administrative Tools -> Computer Management -> Device Manager
- Right click on the batteries and disable them.
- Right click AMD PCNET adapter -> Update Driver -> Select the driver you unzipped if it can’t find it on its own.
8. IE should work now.
9. Configuring your “localhost”
- On ubuntu, use ifconfig and copy your ip address (something like 192.168.0.101)
- On windows, open up C:\WINDOWS\system32\drivers\etc\hosts in notepad
- Modify the line “127.0.0.1 localhost” to “192.168.0.101 localhost”
Resources
http://ubuntuforums.org/showthread.php?t=1097080
http://primeval-soup.blogspot.com/2009/02/ie8-in-ubuntu-intrepid-with-virtual-box.html
tinyMCE Multiple Instances with AJAX (Ruby on Rails) July 23, 2009
Posted by vyolian in development.Tags: execCommand, mceAddControl, mceRemoveControl, tinyMCE
4 comments
I had a problem where I had multiple textboxes on a page but only certain ones needed to be tinyMCE WYSIWYGs. I also needed it to work with Ajax and allow for multiple submissions. Here are the gotchas for making it work (I was using Ruby on Rails).
1) Make sure your init mode is set to ‘none’: I also made a mistake of initializing tinyMCE multiple times, once in each partial.
tinyMCE.init({
mode : "none",
theme : "advanced",
inline_styles : "true",
plugins : "",
2) Add control for each interested textarea: something like…
3) TriggerSave before; Clean Up Afterwards
my_url,
:before=>"tinyMCE.triggerSave(true, true);",
:update=>{:success=>'succes_id', :failure=>'failure_id'},
:success=>"tinyMCE.execCommand('mceRemoveControl', false, 'my_textarea_id');" do |f| %>
Resources
http://stackoverflow.com/questions/699615/cant-post-twice-from-the-same-ajax-tinymce-textarea
http://www.elevatedrails.com/articles/2007/08/08/using-rails-tinymce-and-ajax/
http://hamisageek.blogspot.com/2007/11/multiple-tinymce-3-instances-on-one.html
Machine Learning for Beginners July 19, 2009
Posted by vyolian in development.Tags: beginners, learning, lecture, machine, video
8 comments
Lately, I got huge cravings to learn about machine learning seriously. I don’t get these curious attacks often but when they do, they’re quite extreme. I touched on basic machine learning algorithms at the end of my A.I course at UW. I ended up auditing a graduate machine learning course while I started Eggsprout. Those somehow left me wanting more… a lot more.
For some reason though, there aren’t as many learning resources on it than I’d like. Maybe it’s because I’m only a wanna-be right now and the topic is geared more towards advanced graduate-level scholars. Is there a beginner machine learning community out there? There must be others like me…
EDIT: I’ve started a home for machine learning folks powered by Eggsprout at http://machine-learning.eggsprout.com. Please join me and bring others like us together. Don’t be alarmed if the site is a little empty now, all communities have to start somewhere
.
If you’re that kind of person and you somehow came across this blog, here’s what I’ve found useful so far:
Stanford CS229 Machine Learning Course on Youtube: Probably the most useful and relevant resource for a beginner. I somewhat enjoy Andrew Ng’s teaching style. I bet he’d be a great mentor to have for research. The way the course is organized is very different from how professor Pedro Domingos taught us though. Not far enough in the series to say whether I like it more or not.
CS229 Lecture Notes: Lecture notes that accompany the Youtube videos.
UW Part-time Masters Lectures: Taught by professor Pedro Domingos, awesome teacher and incredibly genius.
VideoLectures.net: These look like they’d be more advanced but interesting nonetheless. So much to watch… so little time.
ResearchChannel.org: I love this resource for just about any topic. I’ve spent hours on this studying neurobiology back when I first entered college. Hopefully the machine learning topics here are just as interesting.
Machine Learning Data Repository: Nice repository of data for when you’re ready to practice using an algorithm. One of my homework assignments from college was from here.
Ruby A.I Plugins: A few ruby machine learning libraries. I’m a rubyist and it’d be nice to see more of these. Maybe I’ll contribute to these some day
.
Tegu: A machine learning system in Ruby developed by David Richards. He looks like an interesting character and I’m keeping an eye on him and his projects. I like his dedication to ruby and machine learning.
Aside: Why do Google searches on “Machine Learning” always turn up results about sewing machines?
Ruby on Rails ImageMagick and RMagick on Cygwin May 14, 2009
Posted by vyolian in development.Tags: cygwin, imagemagick, rails, rmagick, ruby
add a comment
I previously wrote an article about setting up ImageMagick and RMagick from source. I’ve since converted all my ruby on rails development onto Cygwin. Here’s a more specific setup for ImageMagick and RMagick for this environment.
Packages
You need to install quite a bit of packages in order for ImageMagick to work correctly. The list below looks like overkill to me but I haven’t isolated each one to see which ones actually matter and which ones can be left out.
You can (re)install Cygwin to get to the package UI to find most of these under the graphics category. I find that method extremely slow preferring apt-cyg instead, which I’ve documented here.
I like to use Cygwin’s package list for reference. The packages you need are:
- ImageMagick
- libMagick-devel
- XFree86-lib-compat
- xorg-x11-devel
- libbz2-devel
RMagick
Installing the gem should now be as easy as…
gem install rmagick
Problem?
When you finally use ImageMagick, you may get the error…
unable to read font `/usr/lib/ImageMagick-6.4.0/config//usr/share/fonts/corefonts/arial.ttf': `(null)'
You may have noticed that the path looks a bit silly with “…/config//user/…” To fix this, help Cygwin along by pointing it to the actual location of Window’s fonts.
ln -s /cygdrive/c/Windows/Fonts /usr/share/fonts/corefonts
Resources
http://xiaoboonrails.blogspot.com/2008/02/run-ruby-gems-rails-and-mysql-on-cygwin.html
http://chihungchan.blogspot.com/2008_12_01_archive.html
Ruby on Rails respond_to bug on IE7 May 6, 2009
Posted by vyolian in development.Tags: bug, IE7, rails, respond_to, ruby
1 comment so far
Bug
- Clicking on a link pops up a download dialog instead of redirecting you to a page.
- Clicking on a link opens up the xml feed instead of showing the actual page.
Order matters in respond_to
The order of format in respond_to matters. The two below are different.
respond_to do |format|
format.html { }
format.js { }
end
respond_to do |format|
format.js{ }
format.html { }
end
Reason
Due to how IE7 builds its request accept header, format.html needs to be first. IE accepts any MIME types so the order you put it in is the priority that IE7 takes. Firefox doesn’t have this problem because it asks for a particular format.
Resources
- http://www.danielcadenas.com/2008/10/internet-explorer-7-accept-header-and.html
- http://tore.darell.no/posts?page=4
- http://paul.stadig.name
- http://apidock.com/rails/ActionController/MimeResponds/InstanceMethods/respond_to
Ruby on Rails Disabling Submit Button May 1, 2009
Posted by vyolian in development.Tags: disable, disable_with, double-click, form, rails, ruby, submit
1 comment so far
You’ve seen sites with disclaimers, especially with credit card transactions, warning the user not to click twice or they may be charged double. Fortunately again, Ruby on Rails provides a very simple solution to that by disabling the submit button while the form is being processed. Here’s how:
Post
This slipped me every time I’ve looked into this, but there’s actually a documented option in submit_tag that does this automatically
# :disable_with - Value of this parameter will be used as the value for a disabled version of the submit button when the form is submitted.
"Processing..." %>
Ajax
For ajax forms, you’ll have to do something a little different but just as easy.
form_remote_tag
:url=>{:action=>'my_action'},
:loading=>"Form.Element.disable('submit_id')",
:complete=>"Form.Element.enable('submit_id')"
Resources
http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M001707
http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001616
Custom Logging in Ruby on Rails April 8, 2009
Posted by vyolian in development.Tags: debug, logger, ruby on rails
4 comments
I’m one of those developers that likes to abuse standard output in development. In my rails development, I would use ‘puts variable’ everywhere. But sometimes, my debug print statements get clobbered with rail’s default logging of requests and SQL queries.
I’m aware there’s a debugger… but I find using puts quicker. This is especially the case when I just want to see a pattern within an execution or loop rather than tracing variables at each step.
Anyway, here’s how to build a console window that’s devoted solely for debug print statements. You may also find this useful for devoting a log file just to search, auditing, etc. Here are the very basics:
Create Your Custom Logger
#custom_logger.rb
class CustomLogger < Logger
def format_message(severity, timestamp, progname, msg)
"#{msg}\n"
end
end
logfile = File.open(RAILS_ROOT + '/log/custom.log', 'a') #create log file
logfile.sync = true #automatically flushes data to file
CUSTOM_LOGGER = CustomLogger.new(logfile) #constant accessible anywhere
Load CustomLogger From Environment
#in development.rb require "custom_logger"
Use CustomLogger
#in any controller, view or model
CUSTOM_LOGGER.info("info from custom logger")
Finally, create your debug console using
tail -f log/custom.log
Resources
http://maintainable.com/articles/rails_logging_tips (very thorough rails logging article)
http://www.themomorohoax.com/2009/02/09/use-debugger (rails debugger)
http://log4r.sourceforge.net/manual.html (log4r)
Embracing Cygwin on Windows XP April 5, 2009
Posted by vyolian in development.Tags: apt-get, clear, console2, cygwin, vim
2 comments
Vim in Cygwin – Backspace Doesn’t Delete
In ~/.vimrc, add
set backspace=2
Cygwin Doesn’t Have A Clear Command
Install ncurses package
Apt-get for Cygwin
svn checkout http://apt-cyg.googlecode.com/svn/trunk/ apt-cyg
mv apt-cyg/apt-cyg ~/bin/apt-cyg
chmod +x ~/bin/apt-cyg
In .bash_profile, add below and restart shell
PATH=~/bin:$PATH
Now you can just do
apt-cyg install package_name
Console2 on top of Cygwin
Console2 is a Windows console enhancement that sits on top of any shell like Cygwin. Download the latest beta build from SourceForge.
Open Console.exe. Edit –> Settings –> Tabs. Add a new Tab and make sure the shell arguments say
c:\cygwin\bin\bash --login -i
Resources
http://people.etango.com/~markm/archives/2006/02/28/cygwin_vi_backspace_key.html
http://rubenlaguna.com/wp/2007/09/26/bash-clear-command-not-found/
http://stephenjungels.com/jungels.net/projects/apt-cyg/
http://phaseshiftllc.com/archives/2008/10/02/setting-up-rails-on-windows-with-cygwin