learn how to | Learn for Master
  • Run multiple tor instances

    Suppose we want to create three tor instances, with each having its specific ip. 

    Create three torrc files, say /etc/tor/torrc.1 to .3.

    In each file, edit the lines:

    to use different resources for each torrc file, e.g. for for torrc.1:

    for torrc.2,

    and so on.

    DataDirectory can also be relative to the current directory where tor is launched, e.g.:

    Then start tor like this:

    This will create three different Socks5 servers on the three ports.

    [Read More...]
  • Five ways to implement Singleton pattern in Java

    In this post, I will describe five ways to implement the Singleton pattern in Java. They are Synchronization the getInstane() method,static final variable, using double checking lock with volatile keyword, using SingletonHolder, and Enum.

    1. Classic Java Singleton pattern

    The following code is the simplest implementation of Singleton Pattern in Java. However it is not multiple thread-safe. 

    The singleton pattern implemented in the above example is easy to understand. We maintain a static reference to the singleton instance and returns that reference from the static getInstance() method. We also make the Constructor private,

    [Read More...]
  • How to install Mysql database

    In this post, we describe the steps of Installing and Starting MySQL

    How to Install Mysql On linux

    Install Mysql on Ubuntu:

    sudo apt-get install mysql-server

    Install Mysql on Centos:

    sudo yum install mysql-server
    /etc/init.d/mysqld start

    How to install Mysql on Widows

    To install Mysql on Microsoft Windows.  The recommended way is to use the MySQL Installer.

    1. Download MySQL Installer from http://dev.mysql.com/downloads/installer/ and execute it.
    2. Choose the appropriate Setup Type for your system. Typically you will choose Developer Default to install MySQL server and other MySQL tools related to MySQL development,
    [Read More...]
  • How to create plugins for wordpress

    Screen Shot 2015-03-18 at 9.41.47 pm

    Here are two good examples to show how to add buttons to wordpress editor by build wordpress plugins. 

    WordPress has two different editors: TinyMCE editor(i.e., visual editor) and Text editor(i.e., HTML editor).

    WordPress also lets us create custom buttons to both of the visual and text(or HTML) editor. To add a button for Text editor we need to use Quicktags API and to add buttons to the TinyMCE editor we have to use JavaScript APIs provided by the TinyMCE library. Here are two articles that will help you to learn these APIs.

    Add Buttons to WordPress Text Editor

    Here is an example code snippet which adds a button to the WordPress code editor and wraps the selected text using [code][/code] tags.

    [Read More...]
  • How to play Pokémon Go

    Pokemon go

    Pokémon Go is the hottest game right now. Everyone talks about it, and spends around 44 minutes to play it. As this new game gains popularity, its company Nintendo‘s stock skyrocketed 33 percent on July 11, 2016.  Nintendo’s shares have climbed 60 percent year to date.

    The company is now valued at 2.87 trillion yen, or $28 billion, a 63.7% jump from its $17.1 billion closing valuation on Wednesday (July 6). (Pokemon Go was released in Australia and New Zealand on July 6, and then in the United States the following day.

    What is Pokemon Go?

    [Read More...]
  • How to use memcached in WordPress

    What is Memcached?

    Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

    Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches. Its API is available for most popular languages.

    You can get more information of memecached from this link: https://github.com/memcached/memcached/wiki

    Why do you use Memcached?

    By using memcached (properly), you limit the number of queries to the database (because they’ll read the results from memcached instead).

    [Read More...]
  • How to package a Scala project to a Jar file with SBT

    When you develop a Spark project using Scala language, you have to package your project into a jar file. This tutorial describes how to use SBT
    to compile and run a Scala project, and package the project as a Jar file. This will be helpful for you to create a spark project and package it to a jar file.

    The directory structure of a typical SBT project

    Here is an example to show a typical SBT project, which has the following directory structures. 

    .
    |-- build.sbt
    |-- lib
    |-- project
    |-- src
    |   |-- main
    |   |   |-- java (store main java files)
    |   |   |-- resources (store include in main jar)
    |   |   |-- scala (store main Scala source files)
    |   |-- test
    |       |-- java (store test java files)
    |       |-- resources (store files include in test jar)
    |       |-- scala (store test scala source files)
    |-- target

    You can use the following command to create this directory structures:

    #!/bin/sh
    cd ~/hello_world
    mkdir -p src/{main,test}/{java,resources,scala}
    mkdir lib project target
    
    # create an initial build.sbt file
    echo 'name := "MyProject"
    version := "1.0"
    scalaVersion := "2.10.0"' >
    [Read More...]
  • How to get hive table delimiter or schema

    When you have a hive table, you may want to check its delimiter or detailed information such as Schema. There are two solutions:

    Get the delimiter of a Hive Table

    To get the field delimiter of a hive table, we can use the following command:

    Here is an example:

    Get the schema of Hive Table

    Another solution is to use: 

    This will generate a competed information about the table. 

    [Read More...]
  • How to load data from a text file to Hive table

    In this post, I describe how to insert data from a text file to a hive table. 

    Suppose you have tab delimited file::

    Create a Hive table stored as a text file.

    Load the text file (stored locally) into the Hive table:

    Create a Hive table stored as sequence file.

    Now you can load into the sequence table from the text table:

     

    [Read More...]
  • How to setup ipython notebook server to run spark in local or yarn model

    Ipython notebook is a powerful tool to learn python programming. In this post, I demonstrate how to setup a ipython notebook to to spark program in python.

    1. Install spark
      suppose spark is install at directory ~/spark, then execute:
    2. Install anaconda at ~/anaconda

      This will compress all the anaconda files to a zip file

      Run ipython notebook for pyspark using local model

    3. Now you can start a ipython notebook server in local model: WORKSPACE_DIR is the space where you want to save your codes.
      CONFIG_FILE is the location of the jupyter_notebook_config file.
    [Read More...]
Page 1 of 212