Wednesday, January 06, 2016

MacOSX Sed: extra characters at the end of

if your sed is throwing something like extra characters at the end of p command


then do

sed -i '' 'regex' filename

Remember  to add the '' before regex.

Wednesday, August 19, 2015

Tip: Elasticsearch OSX ConnectException

If you downloaded the latest Elasticsearch installation and you are getting the following exception:

org.elasticsearch.common.netty.channel.ConnectTimeoutException: connection timed out:/xyz.def.zzzz:9300
at org.elasticsearch.common.netty.channel.socket.nio.NioClientBoss.processConnectTimeout(NioClientBoss.java:139)
at org.elasticsearch.common.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:83)
at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337)
at org.elasticsearch.common.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:42)
at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)



Solution

go to config/elasticsearch.yml

Uncomment the following line
discovery.zen.ping.multicast.enabled: false

Restart Elasticsearch

Tuesday, July 14, 2015

Git Tip: Repository not found

If you get any of the following errors:
GitLab: The project you were looking for could not be found.
Git The Repository not found
Please make sure you have the correct access rights

and the repository exists.

when you do operations such as git clone or git push,
it is possible that your ssh key has not been added with ssh-agent

$ ssh-add
Enter passphrase for /home/name/.ssh/id_rsa: [] Identity added: /home/name/.ssh/id_rsa 

After this, it should hopefully work

Tuesday, September 16, 2014

JSONP: Escape JSON String

Assume you have a JSON string that you are going to send as result value back to Javascript, then you need to do the following:

        String dataString = stringWriter.toString();
        dataString = dataString.replaceAll("\\u2028","\\\\u2028");
        dataString = dataString.replaceAll("\\u2029","\\\\u2029");

Basically, you need to escape the unicode characters.

Monday, July 21, 2014

Tip: Apache Kafka

If you get the following exception:
$ ./zookeeper-server-start.sh  ../config/zookeeper.properties
Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain

then you will have to do the following:
$ ./gradlew  jar

to build the Kafka distribution and get the dependencies.

Friday, May 02, 2014

Tip: Linux Determine File Sizes in your home directory


anil@localhost:~$ du -sh * > largefiles

You can then look inside the file largefiles.

Wednesday, April 30, 2014

Tip: IntelliJ IDEA : Do not want unlimited whitespace at the end of each line

File menu -> Settings -> Editor -> Virtual Space and uncheck 'Allow placement of caret after end of line'. 

Also uncheck the other options in the Virtual Space panel.

If you want to remove trailing whitespaces, you can do
File menu-->Settings --> Editor --> Strip Whitespaces on Save   to either "All" or "ModifiedLines".

Tuesday, January 07, 2014

Clean Up Root Partition on Fedora

If you have the following problems:
  • Root partition / is using 100% of allocated disk space
  • Root partition / is close to using 100% of allocated disk space

Then,

$>  sudo yum install bleachbit
$>   su - -c "bleachbit"

Use bleachbit to clean up unwanted files.

Tuesday, December 24, 2013

Copy Video on iPhone without iTunes

If you are in need of copying a home video on to your iPhone and you have lost the computer which has the original iTunes sync, do not despair.

VLC app on ios is there for the rescue.

Official Documentation: https://wiki.videolan.org/Documentation:IOS

Steps


  1. Temporarily turn off the lock feature of your iPhone. You can bring it back after the video upload.
  2. Download VLC player from the App Store. Ensure that the vendor is VideoLan.
  3. Ensure your iphone and computer are connected to the same WIFI.
  4. Open VLC app.
  5. On the top left hand corner, is the hat symbol. Click on hat.
  6. Go to Wiki Upload. Enable the server.  Note down the IP address it provides.
  7. Go to your browser and type in the IP address:  something starting with http:
  8. You will see Fig 1
  9. Click upload files button and choose the video file.
  10. Once the file is uploaded, enjoy the home video. Remember VLC can play many formats : mp3, mp4, m4u etc.
  11. Remember to turn back the locking feature on your iphone.
  12. Fig1: Browser Interface

Wednesday, October 16, 2013

Tips for FitBit


Picked up from http://www.sparkpeople.com/mypage_public_journal_individual.asp?blog_id=2471667

Reset your FitBit:

Dock it, turn the dock over, and hit the button underneath with a pen or paperclip. The FitBit will reboot, displaying the current firmware version and the battery level, then will continue charging. This will not delete any of the tracker data.

Completely erase all information on your FitBit:

1. Put the fitbit on the base station
2. Look under base station and you'll see a tiny hole. That's the reset button that you can push with a small pen or paperclip.
3. Press and hold the button on the Fitbit itself and press the reset button
4. Keep the button on the Fitbit pressed for 6 seconds.
5. Take the Fitbit off the base station
6. Press the button on the Fitbit
7. It should say "Testing" and then "Pass"
8. Press and hold the button until it says "Erase"

Power Off Your FitBit:


Unplug the dock. Dock the FitBit on the unplugged dock, then press the reset button on the bottom.

Friday, August 30, 2013

Tip: Mac OSX: Start IntelliJ with sudo permissions

There may be instances where the code you are developing is binding to a particular port that is lower than 1024. So you will not be able to bind to that port.

You will see something like a SocketException : permission denied.

If you are sure that this is temporary and you are developing on your Apple laptop, then do the following in a terminal window:

$>cd IntelliJ\ IDEA\ 12\ CE.app/Contents/MacOS/
$> sudo ./idea

Now IntelliJ is running with sudo permissions.

WARNING: This is a sensitive operation. Do not try it on Apple based servers or production environments.

Netty: UDP based Server Example

An example is the Quote of the Moment Server.

Package is:
https://github.com/netty/netty/blob/master/example/src/main/java/io/netty/example/qotm/

Server is:
https://github.com/netty/netty/blob/master/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServer.java

Server Handler is:
https://github.com/netty/netty/blob/master/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServerHandler.java

Thursday, February 07, 2013

Tip: Hibernate PersistenceException :

If you are seeing the following error "No Persistence provider for EntityManager named" and scratching your brains, ensure that the hibernate-entitymanager.jar is on the classpath.

Also you should have a META-INF/persistence.xml in your jars someplace.

Monday, February 04, 2013

Tuesday, September 11, 2012

Mockito return the value from the response

An example:
private HttpServletRequest request = mock(HttpServletRequest.class);
    private HttpServletResponse response = mock(HttpServletResponse.class);

    @Test
    public void testAuthz() throws Exception {
        AuthorizationEndpoint endpoint = new AuthorizationEndpoint();
        when(request.getParameter("response_type")).thenReturn(ResponseType.CODE.toString());
        when(request.getParameter("client_id")).thenReturn("test_id");
        when(request.getParameter("redirect_uri")).thenReturn("http://localhost");

        final ArrayList values = new ArrayList();
        doAnswer(new Answer() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                String temp = (String) invocation.getArguments()[0];
                values.add(temp);
                return null;
            }
        }).when(response).sendRedirect(anyString());

        httpRequest("GET", "/authorization");

        endpoint.service(request, response);

        String redirectURL = values.get(0);

        URL url = new URL(redirectURL);
        String fragment = url.toURI().getQuery();
        Map map = OAuthUtils.decodeForm(fragment);

        assertNotNull(map.get(OAuth.OAUTH_CODE));
    }

    private void httpRequest(String method, String pathInfo) {
        when(request.getMethod()).thenReturn(method);
        when(request.getPathInfo()).thenReturn(pathInfo);
    }

Monday, September 10, 2012

Fedora: Skype Issue: libXv.so.1: cannot open


If you try to run skype and get the following error
skype: error while loading shared libraries: libXv.so.1: cannot open

$>sudo yum install alsa-lib.i686 libXv.i686 libXScrnSaver.i686 qt.i686 qt-x11.i686

Wednesday, September 05, 2012

Eclipse Heap Settings on Mac

Locating the eclipse.ini is tricky on a mac.

To locate it, right-click on the Eclipse Application icon and select "Show Package Contents", then double-click on the "Contents" folder and then double-click on the "MacOS" folder, the home of eclipse.ini

You can use Applications->Text Edit to change the eclipse.ini file. :)

Usually you want to adjust the heap settings.

Wednesday, August 29, 2012

Fedora: yum-complete-transaction taking forever?

It is possible that it may be in an infinite loop or such. Cleanup your yum transaction as follows:

yum install yum-utils
yum clean all
/usr/sbin/yum-complete-transaction --cleanup-only

Wednesday, August 15, 2012

Fedora: Remove old kernels

Update your system
$ sudo  yum -y update --skip-broken

Now remove old kernels
$ sudo package-cleanup --oldkernels -y

Monday, March 26, 2012

Android Tip: android.view.WindowManager$BadTokenException

If you are using an ActivityGroup to display a series of activities, then you may encounter the infamous BadTokenException.

The location where you are getting the exception, will have a "this" usage for the context.

To get over this error, use "this.getParent()".

Eg:  final ProgressDialog pbarDialog = new ProgressDialog( this.getParent() );