Register |
| Unregistered users click here to register registered users can post their website here |
Science Humor: |
This was a Golden Age, a time of high adventure, rich living, and hard
dying... but nobody thought so. This was a future of fortune and theft,
pillage and rapine, culture and vice... but nobody admitted it.
-- Alfred Bester, "The Stars My Destination"
|
Chuck Norris Humor: |
Chuck Norris doesn't mow his lawn, he stands outside and dares it to grow.
|
|
 |
| Flush the DNS cache in Mac OS X - |
|---|
To flush the DNS cache, launch Terminal and type the following command:
dscacheutil -flushcache
|
| Verify a SHA-1 checksum on Mac OS X - |
|---|
To verify a SHA-1 checksum, launch Terminal and type the following command:
/usr/bin/openssl sha1 filename-to-test
|
| Edit the hosts file in Mac OS X - |
|---|
The hosts file is a text document that maps IP addresses to hostnames. It's similar to, but trumps, DNS. To edit the hosts file in Mac OS X, launch Terminal and type:
sudo vi /etc/hosts
|
| Remove all .svn and dot-underscore files - |
|---|
find . -name ".svn" -prune -o -name "._*" -exec rm -if {} \;
|
| Show/hide hidden files in Mac OS X - |
|---|
To show hidden system files and folders in Finder on Mac OS X, launch Terminal and type:
defaults write com.apple.finder AppleShowAllFiles TRUE killall Finder
If you want to hide the default hidden systems file and folders, replace TRUE with FALSE.
Source: http://www.mactricksandtips.com/2008/04/show-hidden-files.html
|
| Avoid 'stack level too deep' in Ruby - |
|---|
#!/usr/local/bin/ruby
##!/opt/local/bin/ruby1.9
# Update Ruby via MacPorts: # port info ruby19 # sudo port install ruby19 # http://www.macports.org/install.php # http://trac.macports.org/wiki/InstallingMacPorts
# See: # - Tailin' Ruby, http://judofyr.net/posts/tailin-ruby.html # - Re: Ruby and recursion (Ackermann benchmark), http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/145593
class Class # Sweet stuff! def tailcall_optimize( *methods ) methods.each do |meth| org = instance_method( meth ) define_method( meth ) do |*args| if Thread.current[ meth ] throw( :recurse, args ) else Thread.current[ meth ] = org.bind( self ) result = catch( :done ) do loop do args = catch( :recurse ) do throw( :done, Thread.current[ meth ].call( *args ) ) end end end Thread.current[ meth ] = nil result end end end end end
# tail-call optimization test
# example 1
class TCOTest # tail-recursive factorial def fact( n, acc = 1 ) if n <2 then acc else fact( n-1, n*acc ) end end
# length of factorial def fact_size( n ) fact( n ).size rescue $! end end
t = TCOTest.new
# normal method puts t.fact_size( 10000 ) # =>stack level too deep
# enable tail-call optimization class TCOTest tailcall_optimize :fact end
# tail-call optimized method puts t.fact_size( 10000 ) # =>14808
# example 2
class TCOTest2 def addnum(i) p i addnum(i+1) end end
#TCOTest2.new.addnum 0 # stack level too deep (SystemStackError)
# enable tail-call optimization class TCOTest2 tailcall_optimize :addnum end
TCOTest2.new.addnum 0
|
| Open the current Ruby on Rails directory in TextMate without tmp, log and cache - |
|---|
ls -1 | egrep -vi "(log|tmp|cache)" | xargs mate Instead of typing this everytime an alias would be handy. Put this
alias railsmate='ls -1 | egrep -vi "(log|tmp|cache)" | xargs mate'
in your ~/.profileor wherever you put your aliases. |
| How to avoid the ubygems load error - |
|---|
If you install Ruby &RubyGems from scratch (like described hereor here), beginning with:
sudo mv /usr/local/lib/ruby ~/Desktop
and at some point have to execute the command:
sudo /usr/local/bin/ruby setup.rb
... you may see an error message that says:
/usr/local/bin/ruby: no such file to load -- ubygems (LoadError)
This can be avoided by setting the RUBYLIB path variable to include the lib directory of the downloaded RubyGems version:
unset RUBYOPT export GEM_HOME=/usr/local/lib/ruby/gems/1.8 export RUBYLIB=/usr/local/lib/ruby:/path/to/download/dir/rubygems-1.3.1/lib
sudo /usr/local/bin/ruby setup.rb
or
sudo mkdir -p /usr/local/lib/ruby/gems/1.8 sudo mkdir -p /usr/local/lib/ruby/site_ruby/1.8 unset RUBYOPT export GEM_HOME=/usr/local/lib/ruby/gems/1.8 export RUBYLIB=/usr/local/lib/ruby:/usr/local/lib/ruby/site_ruby/1.8 sudo cp -R -p /path/to/download/dir/rubygems-1.3.1/lib/* /usr/local/lib/ruby/site_ruby/1.8
sudo /usr/local/bin/ruby setup.rb
|
| Capture iSight (Macbook) Video with Objective-C QTKit - |
|---|
This is how we can capture video from Macbook iSight. A Sample code from an IBAction button.
- (IBAction)startRecording:(id)sender { // Create a new Capture Session mCaptureSession = [[QTCaptureSession alloc] init];
//Connect inputs and outputs to the session BOOL success = NO; NSError *error;
// Find a video device QTCaptureDevice *device = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeVideo]; if(device) { success = [device open:&error]; if(!success) { // Handle Error! } // Add the video device to the session as device input mCaptureDeviceInput = [[QTCaptureDeviceInput alloc] initWithDevice:device]; success = [mCaptureSession addInput:mCaptureDeviceInput error:&error]; if(!success) { // Handle error }
// Associate the capture view in the UI with the session [mCaptureView setCaptureSession:mCaptureSession];
// Start the capture session runing [mCaptureSession startRunning];
} // End if device }
|
| Compiling Apache2 under Mac OSX Leopard - |
|---|
Insert the following commands into the console after you have downloaded and unziped the Apache2 package. It will configure and install.
sudo ./configure --prefix=/usr/local/apache2 --enable-access --enable-actions --enable-alias --enable-asis --enable-auth --enable-auth_dbm --enable-auth_digest --enable-autoindex --enable-cache --enable-cgi --enable-dav --enable-dav_fs --enable-deflate --enable-dir --enable-disk_cache --enable-dumpio --enable-env --enable-expires --enable-fastcgi --enable-file_cache --enable-headers --enable-imap --enable-include --enable-info --enable-log_config --enable-log_forensic --enable-logio --enable-mem_cache --enable-mime --enable-mime_magic --enable-negotiation --enable-perl --enable-rewrite --enable-setenvif --enable-speling --enable-ssl --enable-status --enable-suexec --enable-unique_id --enable-userdir --enable-usertrack --enable-version --enable-vhost_alias --enable-so --enable-module=all --enable-shared=max
sudo make
sudo make install
Once All that is installed open your ~/.bash_profile and insert the following line to be first in your PATH environment variable.
export APACHE2="/usr/local/apache2/bin" export PATH="${APACHE2}:${PATH}"
once that is complete. You can start your apache server with the following command: sudo httpd -k start sudo httpd -k stop sudo httpd -k restart
| |
|