Monday, December 10, 2012

Todoist : Solving cross domain security policy


From https://todoist.com/API/help

Solving cross domain security policy [top]

You cannot use AJAX to directly communicate with Todoist, this is due to browser security policy. You can solve this by communicating with Todoist using a script tag:
var script = document.createElement('script');
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);
The response data will look like this (callbackFunction will be called):
callbackFunction({ JSON data here });

Sunday, December 2, 2012

GNU Screen Cheat-Sheet

Taken from http://neophob.com/2007/04/gnu-screen-cheat-sheet/
Basics:
–ctrl a c           -> cre­ate new win­dow
–ctrl a A           -> set win­dow name
–ctrl a w           -> show all win­dow
–ctrl a 1|2|3|…   -> switch to win­dow n
–ctrl a ”           -> choose win­dow
–ctrl a ctrl a      -> switch between win­dow
–ctrl a d           -> detach win­dow
–ctrl a ?           -> help
–ctrl a [           -> start copy, move cur­sor to the copy loca­tion, press ENTER, select the chars, press ENTER to copy the selected char­ac­ters to the buffer
–ctrl a ]           -> paste from buffer
How to start screen:

–screen –DR            -> list of detached screen
–screen –r PID         -> attach detached screen ses­sion
–screen –dmS MySes­sion -> start a detached screen ses­sion
–screen –r MySes­sion   -> attach screen ses­sion with name MySession
Advanced:

–ctrl a S       -> cre­ate split screen
–ctrl a TAB     -> switch between split screens
If you cre­ated a new split screen, the cur­rent win­dow is empty. either select an exist­ing win­dow (ctrl a ”) or cre­ate a new split screen (ctrl a n).

–ctrl a Q       -> Kill all regions but the cur­rent one.
–ctrl a X       -> remove active win­dow from split screen
–ctrl a O       -> logout active win­dow (dis­able out­put)
–ctrl a I       -> login active win­dow (enable output)

Thursday, November 29, 2012

Sphinx fails to start with rake ts:start or rake ts:rebuild

$ rake ts:start
Failed to start searchd daemon. Check ../log/searchd.log.
Failed to start searchd daemon. Check ../log/searchd.log
Be sure to run thinking_sphinx:index before thinking_sphinx:start
Almost always is the case for me that searchd is already running / orphaned and needs to be killed. Run
$ps -ax | grep searchd
shows that its already running
49630 ttys000    0:00.06 searchd --pidfile --config ../config/development.sphinx.conf
49644 ttys001    0:00.00 perl /usr/local/bin/grep searchd
and kill it
$kill -9 49630
Voila!

Friday, November 2, 2012

Is there a way through which I see which mysql queries are fired from ActiveRecord in rails console?

http://stackoverflow.com/questions/4667316/how-to-see-mysql-queries-in-rails-console

Yes, this can be achieved through redirecting rails log to standard output.

Write these at your console prompt:

ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.connection_pool.clear_reloadable_connections!
Furthermore, you can put these lines in ~/.irbrc file, so that each time you don't need to manually write these 2 lines:

require 'rubygems'

if ENV.include?('RAILS_ENV') && ENV["RAILS_ENV"] == 'development'
    ActiveRecord::Base.logger = Logger.new(STDOUT)
    ActiveRecord::Base.connection_pool.clear_reloadable_connections!
end

Friday, August 10, 2012

VIM: Search And Replace Text In Multiple Files

:args **/*.*   // set the pattern of file names to look at
:argdo %s/search_for/replace_with/gecI | update

Wednesday, May 9, 2012

Giganews Mimo Crashes After Splash Screen on Win 7

If you're crashing on the splash screen right after it the RMI initialization message try passing the -noRmi flag to mimo.exe. In the start menu right click on Mimo, select properties, and add the flag to the target. Mine looks like this:
"C:\Program Files (x86)\Mimo\Mimo.exe" -noRmi
You should see an "RMI Disabled" message on the splash screen.

Oracle, Ruby, RVM, and OSX Lion

As of this writing the x64 version of the Oracle Instant Client do NOT work with OSX Lion. I got everything working like so:

Install Oracle Instant Client

Install the 32 bit version of the Oracle Instant Client. Download and install the following packages to /usr/local/oracle/instantclient_10_2
  1. instantclient-basic-10.2.0.4.0-macosx-x86.zip
  2. instantclient-sqlplus-10.2.0.4.0-macosx-x86.zip
  3. instantclient-sdk-10.2.0.4.0-macosx-x86.zip

Install the 32-bit version of Ruby

brew install libyaml
rvm install 1.9.3 -n i386 --with-arch=i386
rvm use ruby-1.9.3-p194-i386

Bash

Add the following to your .bash_profile
export DYLD_LIBRARY_PATH="/usr/local/oracle/instantclient_10_2"
export TNS_ADMIN="/usr/local/oracle/network/admin/"
export SQLPATH="/usr/local/oracle/instantclient_10_2"
export ORACLE_HOME="/usr/local/oracle/instantclient_10_2"
export NLS_LANG="AMERICAN_AMERICA.UTF8"
export PATH="$PATH:/usr/local/bin/"
export PATH="$PATH:/usr/local/oracle/instantclient_10_2"
Open and use a new terminal going forward.

tnsnames.ora

Create a tnsnames.ora file here:
/usr/local/oracle/network/admin/tnsnames.ora
Mine looks like this:
staging_db =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 123.456.789.1)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = FOO)
    )
  )

Try it

ruby -rubygems -e "require 'oci8'; OCI8.new('username','password','staging_db').exec('select * from users where rownum < 2') do |c| puts c.join(','); end;"

Thursday, April 26, 2012

Conditionally load ruby-debug gem

At the time of this post ruby-debug isn't available on rubygems.org for 1.9.3. I can't code ruby without it, well I can but I wont. If not everyone on the team wants to do this ruby-debug-on-ruby-193 to get it working you can conditionally load the gem like so:
# for all you ruby-debug haters out there
begin
  if (Gem::Specification::find_by_name "ruby-debug-base19", ">= 0.11.26")
    gem 'linecache19',       '>= 0.5.13'
    gem 'ruby-debug-base19', '>= 0.11.26'
    gem 'ruby-debug19'
  end
rescue Gem::LoadError
  puts "no debug for you"
end

Monday, April 23, 2012

"No Xcode folder is set" when attempting "brew install macvim"

xcode-select: Error: No Xcode folder is set. Run xcode-select -switch to set the path to the Xcode folder.

This fixed it
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

If you're on a non-upgraded x64 version of Lion don't use Homebrew to install MySQL

At least for me I couldn't get gem install mysql or gem install mysql2 to compile. Kept bitching about missing header files and the like. Instead use this .dmg http://dev.mysql.com/downloads/mysql/

mysqld: Table 'mysql.plugin' doesn't exist

If you installed MySQL 5.5 using Homebrew and you're getting this when trying to execute mysqld you probably just need to run mysql_install_db from your /usr/local directory.

From the instal directory run scripts/mysql_install_db

Solution to clipboard sharing when running Mac OSX 10.7 as a VMWare Workstation Guest OS

Install Synergy on both the guest and host. Stand back and watch it work.

Friday, April 20, 2012

Tuesday, April 17, 2012

http://ninite.com/

I can never remember this url since I only need it about once a year. Great little site for building a custom installer.

Thursday, March 1, 2012

Sunday, February 26, 2012

ruby-debug on ruby 1.9.3

Taken from: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug

First download linecache19-0.5.13.gem and ruby-debug-base19-0.11.26.gem from http://rubyforge.org/frs/?group_id=8883, then …

$ gem install linecache19-0.5.13.gem 
Building native extensions.  This could take a while...
Successfully installed linecache19-0.5.13
1 gem installed
$ gem install ruby-debug-base19-0.11.26.gem -- --with-ruby-include=/Users/rtremaine/.rvm/src/ruby-1.9.3-p194  
Building native extensions.  This could take a while...
Successfully installed ruby-debug-base19-0.11.26
and voilá.

Wednesday, February 15, 2012

Rails: WARN TCPServer Error: Address already in use - bind(2)

Getting this message when trying to start WEBrick. Run
lsof|grep 3000
then
kill -9
the pid you get from the previous command.