Showing posts with label tips. Show all posts
Showing posts with label tips. Show all posts

Wednesday, December 11, 2013

How to edit the hosts file in Mac OS

The hosts file is a text file that maps hostnames to IP addresses. Upon typing a url address on the browser, the system is checking if there is a relevant entry on the hosts file and gets the corresponding IP address, else it resolves the IP via the active connection’s DNS servers.

The hosts file can be edited to block certain hostnames (like ad-serving/malicious hosts), or used for web development purposes, i.e. to redirect domains to local addresses.

Editing the hosts file
Editing the hosts file in Mac OS, is a pretty easy task, especially if you are familiar with the terminal. Just follow these steps:
  1. Open the Terminal
  2. Open the hosts file by typing on the Terminal that you have just opened:
    $ sudo nano /private/etc/hosts
    

    Type your user password when prompted.
  3. Edit the hosts file:
    The hosts file contains some comments (lines starting with the # symbol), as well as some default hostname mappings (e.g. 127.0.0.1 – localhost). Simply append your new mappings underneath the default ones. Or edit one of the default values if you know what you are doing! You can navigate the file using the arrow keys.
  4. Save the hosts file
    When done editing the hosts file, press control-o to save the file. Press enter on the filename prompt, and control-x to exit the editor.
  5. Flush the DNS cache (Optional)
    On Leopard you can issue a simple Terminal command to flush the DNS cache, and have your host file changes to take immediate effect:
    $ dscacheutil -flushcache
    
You can now test your new mapping on the browser!


Friday, November 1, 2013

How to merge (and not replace) folders when copying on the Mac?

Problem:
If I try to copy or move a folder to somewhere it already exists, it asks to replace it. That would result in deleting the target. Rather I want to merge :(


With Windows is really simple, however on Mac, well, it works a little bit different!

Rather than using the GUI I'd rather recommend to use the command line:

$ditto from_folder destination_folder

Infallible!!


This is why

ditto -- copy directory hierarchies, create and extract archives.

If the destination directory does not exist it will be created before the first source is copied. If the destination directory already exists then the source directories are merged with the previous contents of the destination.

Thursday, July 11, 2013

Setting Environment Variables in OS X

Have you ever asked yourself What is the proper way to modify environment variables like PATH in OS X?
You could use:
/etc/paths
~/.profile
~/.tcshrc

OR you can try by playing around with
/etc/launchd.conf

Please note that environment.plist does not work for applications launched via Spotlight. This is documented by Steve Sexton here
  1. Open a terminal prompt
  2. Type sudo vi /etc/launchd.conf (note: this file might not yet exist)
  3. Put contents like the following into the file
    	#setenv JAVA_VERSION 1.6
    	setenv JAVA_HOME /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    
    	setenv ANT_HOME /Applications/java/tools/apache-ant-1.8.2
    	setenv ANT_OPTS -Xmx512M
    
    	setenv MAVEN_OPTS -Xmx1024M
    	setenv M2_HOME /Applications/java/tools/apache-maven-3.0.2
    
    	setenv ATG_HOME /Applications/java/tools/Dynamo5.6.1
    
    	setenv DYNAMO_HOME /Applications/java/tools/Dynamo5.6.1/home
    
    	setenv ORACLE_HOME /opt/app/oracle/product/817 
     
  4. Save your changes in VI and reboot your Mac.
  5. Prove that your variables are working by opening a Terminal window and typing export and you should see your new variables. These will also be available in IntelliJ and other GUI apps you launch via Spotlight.

Friday, June 14, 2013

How to speed up Eclipse on Mac OS X

Or Pimp my Eclipse


If you’ve been experiencing horrendous performance of Eclipse on OS X, or maybe you even did not know that Eclipse actually can run very fast, you’d be surprised to learn that apparently it is very easy to make Eclipse run 4-5 times faster on OS X with proper settings to your eclipse.ini file.

Working with Eclipse on OS X felt horrendously slow! I had already noticed this nuance in the past and I thought that the Eclipse is just not meant to fly on Mac's (oh well…), especially when there are so many different distributions for OS X, it signals that the project is in a shifting phase basically (it is shifting from Carbon to Cocoa) and that you should expect all kinds of problems.

I bet many people not having experience with Eclipse on other platforms would think this is normal. It’s Java, so it is supposed to be slow and they just go and hate it and sing how X-Code is great. The thing is, they probably never experienced the full potential of Eclipse – a pity. Hopefully this post can change your mind and help you experience the wonderful world of Eclipse (ok, I am being a little dramatic here). Ok, let’s dive into that.

Since I am pretty heavy user of Eclipse the slowness of Eclipse quickly grew on me and I started looking for ways to try and do something about it.

In the past while experiencing slowness with Eclipse on Windows, I played with the memory allocation within it to increase the memory cap and this usually helped a bit. Being desperate, I decided to try that and off I went to try that. But, that was not so easy. I wandered a bit around the eclipse folder looking for the location of the eclipse.ini but it was nowhere to be found. So I tried searching for it – nop, no luck there as well.

Apparently eclipse.ini is packaged inside the eclipse app so what you need to do is to get inside the eclipse.app package


OR you can use this command:
vi $ECLIPSE_HOME/Eclipse.app/Contents/MacOS/eclipse.ini

after that edit eclipse.ini which you will find in Contents->MacOS folder and increase the memory limits for the following directives (on my case I used these values):
--launcher.XXMaxPermSize
2048m
...
-vmargs
-Xdock:icon=../Resources/Eclipse.icns
-XstartOnFirstThread
-Dorg.eclipse.swt.internal.carbon.smallFonts
-Dosgi.requiredJavaVersion=1.6
-Xms512m
-Xmx850m
-XX:PermSize=512m
-XX:MaxPermSize=1024m
While this is good, this is NOT what will actually make your Eclipse fly. The most important part here is the:
-Dosgi.requiredJavaVersion=1.5

now, you have to switch that to 1.6 and make it
-Dosgi.requiredJavaVersion=1.6


Now THAT will make your Eclipse really shine! Just make sure you actually HAVE the JDK 1.6 installed. You can validate this by running “java -version” in the terminal. If you got 10.6 – Snow Leopard though, you are most likely covered.

Also I still have two more tricks that might be useful:
-Xverify:none

Which will skip the class verification stage during class loading. Using -Xverify:none disables Java class verification, which can provide a 10-15% improvement in startup time. However corrupted or invalid class data is not detected when this option is specified. If corrupt class data is loaded, the Java Virtual Machine (JVM) might behave in an unexpected manner, or the JVM might fail.
-XX:+UseParallelGC

Which is known as The parallel scavenge collector. Which is just an improved version of the parallel copying collector (Enabled using -XX:+UseParNewGC), but the algorithm is tuned for gigabyte heaps (over 10GB) on multi-CPU machines.

If you already had that in the eclipse.ini file – well, unfortunately this already has been optimized for you and the only thing you can try from there that we know of is to play with the memmory limits.

Also, I've discovered other options, which I'm not 100% sure how they work together (because I haven't researched them too deep :P), however they might help you out:
-XX:CompileThreshold=5
-XX:MaxGCPauseMillis=10
-XX:MaxHeapFreeRatio=70
-XX:+UseFastAccessorMethods
-XX:+CMSIncrementalPacing
-XX:+UseG1GC
-XX:+UseFastAccessorMethods

Just don't mix them with -XX:+UseParallelGC

Saturday, April 13, 2013

Getting column info from Oracle table you don't own (without using describe)

How would one get columns information on table which he doesn't own, but has select granted? This is, without using DESCRIBE table_name

My answer is:

select owner, column_name from all_tab_columns where table_name = 'STUDENT';

Saturday, March 16, 2013

Creating a branch in Perforce with P4V

I recently wanted to create a private branch to experiment with some stuff in a Perforce repository. Coming from a SVN history, I had to figure out what 'branching' means in Perforce.

Perforce uses the word "integrate" for most branching activities. What's a little strange is that you 'integrate' to create the branch, then you 'integrate' to merge the branch later.

I'm still not completely sure what that means

First, create a new branch spec. Use File > New > Branch Mapping. (To edit it later, use View > Branch Mappings). In it, I created "CLOUD_CRAZE" as the name of my branch, then gave it a branch spec of
//depot/kaptest.com/jboss_apps/kaptest_3.1/DEV/... //depot/kaptest.com/jboss_apps/kaptest_3.1/branches/CLOUD_CRAZE/DEV/...

Next, you need to actually execute the branch creation, which is done with "Integrate..."

Choose the "CLOUD_CRAZE" entry in the Workspace that I currently have sync'd. Context Menu > Integrate ... "Use Branch Specification"

Select my branch mapping "CLOUD_CRAZE"

Use "Preview" to indicate that it seems to have the right mapping together

Use "Integrate" to actually start the branch/copy.

It churns for a while and appears to be creating my copy. NOTE: It appears that P4 does client-side copying and branching, so this takes a LOOOOONG time if you have big files.

When finished, I know have files in ~/MyCodeProjects/juan_rtcap/kaptest.com/jboss_apps/kaptest_3.1/branches/CLOUD_CRAZE/DEV

Finally, you must submit this into perforce in order to see it in your Depot and Voila!!!

You're all set!


Friday, January 4, 2013

How to recursively remove .DS_Store files on Mac OS X

The following command will remove all .DS_Store files in a directory where it is executed as well as that particular directory’s subdirectories:
find . -name '*.DS_Store' -type f -delete

Why would you want to remove .DS_Store files? The .DS_Store files store Finder-specific preferences concerning the display of each of your folders. Removing these files is an easy way to reset your display preferences. Also, if you’re moving files between your Mac and another operating system such as Windows or Linux these files can cause unexpected problems and should be removed prior to transfer.
This command works on Mac OS X (both 10.4 Tiger and 10.5 Leopard) and Unix-type operating systems such as Linux. What follows is a step-by-step guide on how to properly use this command on Mac OS X.

Directions on how to recursively remove .DS_Store files on Mac OS X
  1. Open up the Terminal application (/Applications/Utilities/Terminal.app).
  2. Find the directory/folder that you wish to recursively delete the .DS_Store files from. For this tutorial let’s pretend you want to delete all the .DS_Store files in your Pictures folder and every folder inside that folder. Type this command into Terminal (without pressing the return key):
    cd
  3. Then drag and drop your Pictures folder onto the Terminal window. The cd command should now look something like this–where ariadoss is your Mac’s “short name” (i.e. your username):
     cd /Users/jcruz/Pictures
  4. Press the return/enter key on your keyboard.
  5. Type the following command into Terminal and press return to execute it:
    find . -name '*.DS_Store' -type f -delete

Congratulations the .DS_Store files have been deleted! Please note that this command will just delete existing .DS_Store files; your Mac will continue to create them

If you wish to disable the creation of .DS_Store files on external volumes type the following command into Terminal and hit enter (you may need to logout or restart your computer after executing this command):
defaults write com.apple.desktopservices DSDontWriteNetworkStores true


Saturday, September 15, 2012

Keep parameter in session with Injection and Outjection

This time something kind of weird happened to me.

To be honest, each time I have to work with Jboss Seam, I always say to myself: "I wonder what kind of surprise waits for me this time". Because I'm a Spring Framework dude, and JBoss Seam documentation, well, is not really clear at all.

This is my case:
I have a page that receives a parameter from an external source, the page is displayed, user pays around with it, page gets refreshed a lot of times. And then, user submits page and everything and goes away, then is when I need that parameter received at the beginning. Because after the submit I have to pass it to another page which need it

The solution will be something like: come on dude! that's Servlets 101. Just set the parameter in the session the first time and that's it! Now the question is, what happens to that value set into the session? Because I want to use it on my pages.xml file to redirect the request to another page though!
And, very important, I want to write as less code as possible (by using Seam Annotations)

But better if we see some code:

The param received (passed by an external caller) is:
By doing this I'm keeping in Session this variable:
Very important to keep the parameter stored in session only once during page Creation!

This is my pages.xml, where I'm passing as param resume the value of my In/Outjected variable resumePersistentParam


Monday, August 6, 2012

Delegated vs. Federated ID

It is important to understand that there are two different kind of single-sign-on solutions: delegated and federated. All the recent comparisons between OpenID and Facebook Connect failed to appreciate this fundamental difference. Facebook Connect is a delegated authentication service, while OpenID is a federated authentication service. They might offer very similar features, but they are very different.

A delegated solution means that one site is simply outsourcing its authentication needs to another pre-selected site. If your site uses Facebook Connect, you are delegating your authentication facilities to Facebook. Visitors to your site cannot use any other accounts, only accounts from the vendors you have pre-selected.

A federated solution means that visitors to your site can use any account they have, as long as it is compatible. It makes no difference to the site which account is being used, as long as it can interoperate. At its core, OpenID is a federated solution because its most important feature is the ability to use any OpenID account with any OpenID-enabled service.

Delegated authentication has a few drawbacks with respect to federated authentication. First, delegated authentication is inherently less secure than federated authentication. Even if encrypted, delegated authentication still sends the username and password (possibly even your network password) over the internet.

More Information...





Sunday, June 3, 2012

How to determine remote host on a RESTful Web Service

This is your Restfull service (At least one method):


As you can see, we don't have available the popular Request object, now what we can do is just to add another parameter to our method, and Listo!
@Context javax.servlet.http.HttpServletRequest request

Thursday, September 29, 2011

Tip: How to type Ʊ in a Mac

If you’re composing an invitation to a piƱata party and you’re wondering how to type that Ʊ, here’s how:


Press and hold Option
option.png
…while pressing n
n.png
…then release and press n again, alone…
n-alone.png
…to type this:
tilde.png
Also:
Option + E, then E again → Ć©
Option + U, then E → Ć«
Option + C → Ć§