eTechtips

Tech Tips and Insights

  • Hadoop: Checking for hung jobs

    I was working on my EMR cluster and needed to test some issues with steps of our process but I don’t have access to the web tools to monitor processes. When I ran one of my hadoop processes it just sat at the beginning of the process. It turned out I had some hung processes but needed to use the Hadoop yarn command-line tool to find out what was going on.

    Using the following command shows the queue for processes queued to run:

    > yarn application -list

    If you do find an issue with a hung process, use the following to end the process:

    >yarn application -kill <application-id>
    0 Comments
  • Windows 10 Screen Rotation

    I was recently trying to read a large log file and I needed to rotate my screen to portrait mode in order to read more text. Sadly, I learned that the CTRL+ALT+<LEFT ARROW> and CTRL+ALT+<RIGHT ARROW> key combinations are not implemented by the Windows OS but with each graphic card manufacturer. And sadly many of the more recent drivers no longer support this functionality.

    In order to rotate the screen you need to use the display settings.

    Either : Right-Click the desktop and choose “Display Settings”

    or

    Start > Settings > System > Display

    Next: Select the display you want to rotate and scroll down to “Display Orientation”

    Choose the orientation depending on the rotation of your mount. The options are:

    • Landscape
    • Portrait
    • Landscape (flipped)
    • Portrait (flipped)

    Sadly the quick switching of displays may be gone but at least the ability still exists.

    0 Comments
  • Reset the Autoincrement column in MSSQL

    To reset the identity column in MSSQL use the following:

    DBCC CHECKIDENT (tablename, RESEED, 0)

    Just replace tablename with the table, and change the 0 to the number minus 1 that you want to have as the next row.

    For example, entering 0 (zero) will give the next row identity of 1.

    0 Comments
  • Android Resource files

    When developing an application for Android you will require additional resources. This data is kept in resource files. The resource files live under the /res directory and consist of the following items:

    • Colors
    • Strings
    • Dimensions
    • Drawables (Images and Icons)
    • Sounds
    • Videos
    • Data Files
    • Layout Files

    The Rules for resource files are:

    • Must be lowercase
    • May contain: letters, numbers, underscores and periods
    • Filenames must be unique
    • XML Name attributes must be unique as well

    To reference the resources from a compiled resource you would use something like the following format depending on the type of resource:

    String app_name = getResources().getString(R.string.app_name);
    

    The template for reading resources is either:
    Local

    @[resource type]:/[resource name]
    or
    Android
    @android:[resource type]:[resource name]
    

    or from a layout file:

    @string/app_name
    

    or from the android system resources:

    @android:string/ok
    
    0 Comments
  • Hadoop File System Commands

    When working with Hadoop you might need to move files in and out of the HDFS. The hadoop fs commands can get tedious to type out over and over again, so I came up with some aliases that work to reduce my typing.

    The commands that I have found myself using most often are:

    Listing the directories and files:

    hadoop fs -ls <filename(s)>
    
    hls <filename(s)>
    

    Viewing the contents of files:

    hadoop fs -cat <filename(s)>
    
    hcat <filename(s)>
    

    I usually pipe that into an awk script to verify data.

    Removing Entries from the HDFS:

    hadoop fs -rm <filename(s)>
    
    hrm <filename(s)>
    

    Copying files to HDFS:

    hadoop fs -copyFromLocal <local filename> <target directory or filename>
    
    hcpto <local filename> <target directory or filename>
    

    Copying from HDFS to the local system:

    hadoop fs -copyToLocal <remote file(s)> <target directory or filename>
    
    hcpfrom <remote file(s)> <target directory or filename>
    

    Note: The <filename(s)> should be replaced with whatever files or directories including using the ‘*’ to select multiple files. Only the copy commands should have a singular entry for the target directory.

    Here are the alias entries I use:

    alias h='hadoop fs'
    alias hcat='hadoop fs -cat '
    alias hls='hadoop fs -ls '
    alias hrm='hadoop fs -rm '
    alias hcpto='hadoop fs -copytoLocal'
    alias hcpfrom = 'hadoop fs -copyFromLocal'
    

    0 Comments
  • Hadoop Debugging with Counters

    I have been enjoying learning Hadoop and have had to debug issues within a current process job to enhance it for new data points. It is quite the challenge to debug a distributed system but I have found two ways to get some meaningful input from the system. One way is using Counters and the other is to use MultipleOutputs to capture output from errors(This will be in a later post). This article will show how counters can be used.

    The Counter method allows you to specify a set of enum values to specify the counter name:

    public enum Counters {
      CHOCOLATE,
      VANILLA,
      MINT_CHOCO_CHIP
    }
    

    This will be used as the identifier for the counter that is in use. The same code can be used within the Mapper or the reducer depending on where you are looking for the counts. The difference is where in the final output of the Hadoop process that the counts show up.

    if (flavor.contains("CHOCOLATE")) {
        context.getCounter(Counters.CHOCOLATE).increment(1);
    }
    if (flavor.contains("VANILLA")) {
        context.getCounter(Counters.VANILLA).increment(1);
    }
    if (flavor.contains("MINT_CHOCO_CHIP")) {
        context.getCounter(Counters.MINT_CHOCO_CHIP).increment(1);
    }
    

    This way you will find a line for each counter that was incremented during the Hadoop process.

    I have used it to highlight problems with in the code or just to make sure that a segment of code has been run.

    0 Comments
  • Python Variables

    Variables in Python are declared on first use.
    Variable names in Python must:

    • Start with a letter or an underscore character
    • Not start with a number
    • Only contain alpha-numeric characters and underscores (A-Z,a-z, 0-9 and _)
    • Be case sensitive (ex. name and Name are different variables)

    Good variable names

    apple
    b_funky
    _tester
    

    The underscore as the first character usually indicates that the function is for internal use. This convention is mentioned in PEP 8.

    Bad variable names

    8million
    $dog
    +happy
    

    The scope of a Python variable depends where it is defined.

    If it defined outside of any function or class, then that variable is global. This means that all functions can access that variable.

    some_var= "Eric"
    

    If it is defined within a class or function, than that variable is considered to have local scope.

    def print_name(name):
        greeting = "Good Morning,"
        print(greeting,name)
    

    The variable some_var is global and can be used throughout the program, but the variables name and greeting are local to the function and are not available outside of the function.

    0 Comments
  • Crypto Faucets that pay out

    If you want to get your hands on Crypto Currency but are not willing to put up cash up front, there are a collection of sites out there that are called faucets. These faucets “drip” crypto currencies. This will not make you rich today but it will give you a foothold into the crypto currency domain.

    Site Name Type Description Claim rate Collector Site
    Moon Bitcoin BTC Bitcoin faucet with offers and referral and daily bonuses bonuses to increase your bitcoin holdings. 5 minutes Coinpot
    Moon Litecoin LTC Litecoin faucet with offers and referral and daily bonuses bonuses to increase your litecoin holdings. 5 minutes Coinpot
    Moon Dogecoin DOGE Dogecoin faucet with offers and referral and daily bonuses bonuses to increase your Dogecoin holdings. 5 minutes Coinpot
    Bit Fun BTC Bitcoin faucet with games and offers. 5 minutes Coinpot
    Febbit.com BTC Fun Bitcoin Mining Game with upgrades and referrals 1 hour Wallet Payout
    Freebitcoin BTC Bitcoin faucet with interest and a multiply bitcoin game. 1 hour Any Bitcoin address
    0 Comments
  • Different ways to display Chrome logging entries

    When I develop in the web, there are plenty of times that I want to see information about where I am in the program or what is going on in the Javascript when I load the page. I use the Console to watch updates but it can be difficult to read when you have possibly hundreds of log statements.
    Usually you can just use the standard console.log function:

    > console.log("Some information");
    Some information
    or 
    
    > console.debug("Some information");
    Some information
    
    or 
    
    > console.info("Some information");
    Some information
    
    

    You also get the line number and file that the output comes from in the console.

    But did you know that you can use the following:

    console.clear()
    console.error(object)
    console.table(array)
    console.warn()
    

    Let’s say you want to clear the current console. You can place in your code, or use it within the console itself.

    console.clear();
    

    Or you can get color coded lines with the warn or error functions:

    > console.warn("This is a warning");
    
    ► This is a warning
    > console.error("Error: Danger");
    
    ► Error: Danger
    And if you need to display an array that and want a better layout use console.table():
    > console.table(['a','b','c']);
    (index) Value
    0 “a”
    1 “b”
    2 “c”
    ► Array(3)
    0 Comments
  • Kick off Chrome Debugging

    I was talking to a friend of mine on the phone the other day and we were talking about how debugging in Chrome was sometimes frustrating. We both had some ideas on how that could have been made better for each of us.

    While you can load your page, find the line of code, and add a set of breakpoints. He let me know kicking off the debugger in a certain part of your code just by adding the following line of code where you want the code to stop:

    debugger;
    

    Once this brings up the debugging window, this behaves like a breakpoint and stops execution. Now you can see the value of your variables, or you can step through the rest of your code line by line.

    My next post will talk about the different kind of console logging functions that are availabole.

    0 Comments