Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

« Newer Snippets
Older Snippets »
8 total  XML / RSS feed 

export certain revision of file from svn

Easier to just cat the revision you want and copy it over rather than try to check out a certain revision.

svn cat -r [REV] mydir/myfile > mydir/myfile

import data into mysql

Things to note:
Mysql may not have access to the directory you've put the datafile. Use /tmp to overcome this problem.
Datafile name must be the same as the mysql table you're importing to.

mysqlimport -u username -p --columns=column_1,column_2 --fields-terminated-by=',' databasename /tmp/data_file_same_as_mysql_table_name

Start Subversion Repository with Initial Import

// description of your code here

On the server (cannot be done remotely)
svnadmin create /var/svn/repository_name


On the client with the files to check in
svn import svn+ssh://myserver.com/var/svn/repository_name

You MUST use full path if using svn+ssh. If using HTTP, full path is not necessary.

Then erase the entire directory, and checkout the files from Subversion in order to make the current directory a working copy. Be careful and copy the directory to a backup directory before deleting all files and checking out a working copy.
cd ..
mkdir bak_directory
cp -R my_directory bak_directory
cd my_directory
rm -rf *
svn co svn+ssh://myserver.com/var/svn/repository_name .

Don't forget that period at the end of the checkout (co) statement. It will create the directory if you forget the . (current directory) optional parameter which will result in my_directory/my_directory/[your files]

writing destructive string methods in Ruby

Use string class' method "replace" to overwrite its "self" value.

Example:

  def decapitalize!
    replace (self.reverse.chop + self.reverse.last.downcase).reverse
  end
  
  def decapitalize
    dup.decapitalize!
  end

Two or more parameters in RESTful route

Regardless of whether this is RESTful, to add multiple parameters to a normally RESTful route use the following

myresource_path(:id => myId, :extra_param => extraId, :extra_param2 => blah)


Results in
myresource/myId?extra_param=extraId&extra_param2=blah


See this Google Rails Group thread from Jeremy Kemper.

SOAP4R Rails NameError FIX

// description of your code here

Update /Library/Ruby/Gems/1.8/gems/soap4r-1.5.8/lib/soap
  # KNOWN_TAG = XSD::NS::KNOWN_TAG.dup.update(
  #   SOAP::EnvelopeNamespace => 'env'
  # ) # Replaced with code from http://dev.ctor.org/soap4r/ticket/433
  KNOWN_TAG = {
      XSD::Namespace => 'xsd', XSD::InstanceNamespace => 'xsi', SOAP::EnvelopeNamespace => 'env'
  }

Freeze rails

Freeze rails 1.2.3 to a project through rubyonrails.org TRAC.

rake rails:freeze:edge TAG=rel_1-2-3

install rubygems on ubuntu

When compiling and installing rubygems it required the zlib module that wasn't installed in Ruby by default. To add in that functionality, go to the source Ruby directory, the ext directory, the zlib directory, then create the make file, then install it.

Make sure you have the proper library files before doing this (i.e. on Ubuntu its zlib1g-dev, installed via apt-get)

apt-get zlib1g-dev
cd /usr/local/src/ruby-1.8.6/ext/zlib
ruby extconf.rb --with-zlib-include=/usr/include --with-zlib-lib=/usr/lib
make
make install


The 'make' command should have all output lines NOT '...no'
If it does, then zlib1g-dev is NOT installed. Get it via the packages and redo this to create the makefile

After this return to the rubygems source directory and run:
ruby setup.rb
« Newer Snippets
Older Snippets »
8 total  XML / RSS feed