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

Michael Baumgarten http://www.minofare.com

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

Manually Starting & Stopping MySQL in Leopard

This is for software built from source according to:
http://hivelogic.com/articles/installing-mysql-on-mac-os-x/

Start MySQL
sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist


Stop MySQL
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist


MySQL 5 macports setup

You have to symlink mysql to the location on osx

first find out where mysql has put the socket:
mysql_config5 --socket

Next symlink /tmp/mysql.sock to the right location of the socket
sudo ln -s path-of-mysql.sock-from-above /tmp/mysql.sock


Start MySQL
sudo /opt/local/share/mysql5/mysql/mysql.server start

or
/opt/local/bin/mysqld_safe5


Stop MySQL
sudo /opt/local/share/mysql5/mysql/mysql.server stop

Install plugin on rails app

script/plugin install [name of plugin, or the url to the desired plugin]

HTML stripper

// description of your code here

str = <<HTML_TEXT



  

Application error

Change this error message for exceptions thrown outside of an action (like in Dispatcher setups or broken Ruby code) in public/500.html

HTML_TEXT puts str.gsub(/<\/?[^>]*>/, "")

Setup LAMP on Ubuntu with MyODBC support.

Go to terminal:

sudo apt-get install apache2 mysql-server php5 php5-odbc libapache2-mod-php5 php5-xsl php5-gd php-pear libapache2-mod-auth-mysql php5-mysql libmyodbc


Now hand edit (or create, if it does not exist already) /etc/odbc.ini

Here's an example odbc.ini:

[ODBC Data Sources]
odbcname     = MyODBC 3.51 Driver DSN

[odbcname]
Driver       = /usr/lib/odbc/libmyodbc.so
Description  = MyODBC 3.51 Driver DSN
SERVER       = my.database.server.com
PORT         =
USER         = USER
Password     = XXXXXX
Database     = DBNAME
OPTION       = 3
SOCKET       =

[Default]
Driver       = /usr/local/lib/libmyodbc3.so
Description  = MyODBC 3.51 Driver DSN
SERVER       = localhost
PORT         =
USER         = root
Password     =
Database     = test
OPTION       = 3
SOCKET       =


Remember to start and stop mysql and apache:

sudo /etc/init.d/mysql start
sudo /etc/init.d/apache2 start

sudo /etc/init.d/mysql stop
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/mysql restart
sudo /etc/init.d/apache2 restart

Give remote access to mysql

mysql -u root -p (your password)


then write the following

GRANT ALL PRIVILEGES ON *.* TO user@'%' IDENTIFIED BY 'PASSWORD';


then

FLUSH PRIVILEGES;

Run Apache in 32bit mode on Leopard

There is currently an issue resulting from the fact that Apache on Mac OS X 10.5 is built as a 64 bit application. On Macs that support 64 bits (all current Mac models), Apache will run in 64 bit mode. This is incompatible with most ODBC drivers, including those currently available from Actual Technologies.
Until we can make 64 bit versions of our drivers available, we recommend a workaround to force Apache to run in 32 bit mode. Using the Terminal prompt, enter the following commands (this is for ppc machines, for intel switch ppc7400 to i386):
sudo mv /usr/sbin/httpd /usr/sbin/httpd.ub

sudo lipo -thin ppc7400 /usr/sbin/httpd.ub -output /usr/sbin/httpd.ppc7400

sudo ln -s /usr/sbin/httpd.ppc7400 /usr/sbin/httpd 

Now restart Web Sharing in the System Preferences, and continue with the instructions for "Invoking ODBC Functions from ODBC" below.
NOTE: if you ever need to restore Apache to 64 bit mode, just enter the following command:
sudo mv /usr/sbin/httpd.ub /usr/sbin/httpd

Remove Existing MySQL Installations

If you already have MySQL installed and used the package installer from MySQL to install it, you need to remove a single file (actually a symlink) to disable it:

sudo rm /usr/local/mysql


If you also installed the StartupItem package, you’ll want to remove it as well. Keep in mind that if you ever want to auto-start the old version of MySQL later on, you’ll need to re-download the package installer and reinstall the StartupItem.

sudo rm -rf /Library/StartupItems/MySQLCOM/

Change Root user password



mysql -h localhost -u root
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('root-pwd') WHERE user='root';
mysql> FLUSH PRIVILEGES;
mysql> EXIT

MySQL add user

mysql> GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost'
    ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;

MySQL 4 macports setup

If this is a new install
If you did not choose the server variant you may add a mysql user and you will need to change the ownership to that user:
sudo chown mysql /opt/local/var/db/mysql
sudo chown mysql /opt/local/var/run/mysqld
sudo chown mysql /opt/local/var/log/mysql


You might want to run
sudo -u mysql mysql_install_db


You have to symlink mysql to the location on osx

first find out where mysql has put the socket:
mysql_config --socket

Next symlink /tmp/mysql.sock to the right location of the socket
sudo ln -s path-of-mysql.sock-from-above /tmp/mysql.sock


Start MySQL
sudo /opt/local/share/mysql/mysql.server start


Stop MySQL
sudo /opt/local/share/mysql/mysql.server stop

Macports MySQL 5 startup on launch

A startup item has been generated that will aid in starting mysql5 with launchd. It is disabled by default. Execute the following command to start it, and to cause it to launch at startup:
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist


Common macports commands

Installs a package
port install package

uninstalls a package
port uninstall package

shows all ports currently installed
port installed

shows all ports not currently installed, you may want to pipe the output of this command to grep to limit the output
port uninstalled

search for a port whose name matches the regex
port search regex

shows meta information on a package
port info package

shows the latest version of all available ports
port list

Restart Rails on Dreamhost

script/process/reaper --dispatcher=dispatch.fcg

Freezing Rails

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

Starting and stopping MySQL on leopard.

#starting SQL:
sudo /usr/local/mysql/support-files/mysql.server start

Stoping SQL:
sudo /usr/local/mysql/support-files/mysql.server stop

Check DNS lookup in Tiger

lookupd -configuration

Look for the following in the output:
LookupOrder: Cache FF DNS NI DS
_config_name: Host Configuration


The FF (flat file) refers to your hosts file (/etc/hosts), and Tiger does check its contents before going to DNS and Netinfo. Just a little FYI for those who may not have realized that 10.4 fixed things.


Calculate the number of working days between two dates

Function
   # wdays is an array with the days of the week
   # to exclude days (eg: wdays = [0,6] for sunday and saturday )

   def calculate_working_days(d1,d2,wdays)
        diff = d2 - d1
        holidays = 0
        ret = (d2-d1).divmod(7)
        holidays =  ret[0].truncate * wdays.length
        d1 = d2 - ret[1]
        while(d1 <= d2)
                if wdays.include?(d1.wday)
                        holidays += 1
                end
                d1 += 1
        end
        diff - holidays
   end


Iterates over date range.
d1 = Date.new( 2006, 12, 1 ) 

d2 = Date.new( 2007, 1, 15 )

weekdays = (d1..d2).reject { |d| [0,6].include? d.wday } 

weekdays.length

Burn ISO osx

Open Terminal and type:
hdiutil burn image.iso
« Newer Snippets
Older Snippets »
22 total  XML / RSS feed