eTechtips

Tech Tips and Insights

  • OCR: Convert image to text

    So I had a colleague receive a list of cities to import to a database in an excel spreadsheet. It turned out that someone had placed an image of the data in the spreadsheet instead of the text. This was looking to be a long day of typing when I happened upon the following awesome site: Online OCR . I was able to convert the image to text in MS Word, MS Excel or plain text.

    All you have to do is take the image and use Paint or any image software, copy it from the document and save it as a png or jpeg. Then Save the file and you have the text ready to go. I did have a few mis-recognized letters, but changing a few keystrokes was better than the hour I would have wasted typing out all the cities.

    And all this without registration. When I registered it gave a few more options for output such as PDF, different versions of Excel and Word, and RTF. Also multi page support, convert to black and white and creating zips.

    There is also multi-language support and even an email service to send in the your docs and receive an email with the converted doc. There is a limit to the amount of pages you are allowed with the login service and you can purchase sets of pages in chunks if you use the service regularly.

    Great Service and I was able to convert the list in just a few minutes.

    Thanks Online OCR!

    0 Comments
  • Windows GodMode folder

    I just found a way to create a settings folder in Windows 7. This God Mode folder can be created by:

    1) Create a new Folder
    2) Rename the folder to : GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}
    

    Then the folder will change its icon and give you access to the settings for your computer in one place.

    0 Comments
  • Postgres: Create table if it doesn’t already exist

    I have a script that uploads a series of data into tables and occasionally I have an alternate table that is not part of my company template so I need to create the table at run time.  I do not want try to create the table if it exists already.  I also did not want to have to write a table check query and run that separately each time.

    I looked into creating a function to do this but I found that with the release of Postgres 9.1 there was an addition of the “if exists” or in my case, “if not exists” that allowed me to run one query that would only create the table if the table does not exist already.

    CREATE TABLE IF NOT EXISTS {schema}.{table_name}
    
    (
    
    sku character varying(100) not null,
    
    product_image character_varying(300) not null
    
    );
    
    
    0 Comments
  • SQL: Shorten string to length

    I had a project the other day that required me to shorten a description down to a certain length and add an elipsis. The problem I encountered was making sure that the truncation did not happen in the middle of a word.

    So using a Postgres database, I used the following query to return the shortened description without ending in a partial word.

    select 
        case when length(long_description)>= 100
        then reverse(substring(reverse(left(long_description,100)),position(' ' in reverse(left(long_description,100))))) || '...'
        else long_description
        end
        from data_feed

    The steps involved were to

    1.  Check if the field is over 100 characters,  if >100, then continue to step 2
    2.  Use left function to get 100 characters of the string
    3.  Reverse the string returned from left
    4.  Get a substring of the reversed truncated string from the first space (‘ ‘) to the end of the reversed truncated string
    5. Reverse the final string (So it is back to the correct direction of text)
    6. Append the ellipsis to the string ( or add a link or leave off if no extra chars are required)

     

    0 Comments
  • Invalid JPEG when uploading to photo service

    I create cards in Adobe Illustrator or Photoshop on occasion and have had issues with getting my prints made at on-line or in-store photo services (such as Walgreens, Walmart or Target). I have received invalid JPEG errors.

    You will need to make sure that your color mode is set to RGB for your files and not CMYK.

    Ironically, even though most printers do better with CMYK, the RGB format is required for your JPEGS at these services.

    0 Comments
  • VI: Indent lines

    The other day I was editing some code and as usual I was in Vi. It was python code and I had refactored some code and needed to indent a section of code. I did not relish the idea of trying to make sure that all the indents were done on several dozen lines of code so I looked into how to indent the code in VI.

    Here is the sequence that let me indent blocks easily.

    I used <shift>-V to select the entire line.

    Then I selected multiple lines by using the arrow keys or j or k depending on which direction you need to select.

    Then you use the ‘>’ key to indent to the right and the ‘<‘ key to decrease the indent to the left.

    0 Comments
  • Install Python modules to a different directory

    There are times that I have wanted to install some Python module on a system where I did not have access to do so.
    When you do not have permission to write into the standard library directories you
    may need to run the “python setup.py install” command with the additional option of

     --home=<Some other directory>

    make sure that this base directory has a lib/python directory within it and that you have
    exported the PYTHONPATH variable to contain this directory.

    Then simply run the command “python setup.py install –home=<Some other directory>” and your libs will
    be installed.

    Then you will need to make sure that your PYTHONPATH environment variable is always available
    to whatever runs your scripts.

    As an alternative to the PYTHONPATH, you can use the following within your scripts to target a non-standard python module directory:

    import sys
    sys.path.append("/path/to/the/module/directory")
    ## import any modules you have in your own directory
    

    Using the method in the script allows you to make the scripts available to other users that may not have the PYTHONPATH setup.

    0 Comments
  • Counting lines, words and characters with wc

    There is a simple Linux utility for counting characters, lines and words in files called wc. This allows you to give a file as an argument or a stream and get the counts of the aforementioned items.

    wc <filename>

    or

    cat <filename> | wc

    The options that wc accepts

    -c,–bytes print the byte counts
    -m,–chars print the character counts
    -l,–lines print the line counts
    -L,–max-line-length print the length of the longest line
    -w,–words print the word counts

    The ouput with no arguments will be three numbers (words,lines,characters. Otherwise the the number will reflect the argument you have passed.

    And if you pass multiple filenames the output displays counts for all files and totals.

     >wc -l HelloWorld.java sample.txt
        8 HelloWorld.java
       25 sample.txt
       33 total
    0 Comments
  • HTML: Basic HTML5 page

    This is where I start coding my web pages. This is a simple framework for an HTML5 web page. The DOCTYPE has been simplified and is supported by all major browsers even if they do not fully support the current HTML5 tags.

    <!DOCTYPE html>
    <html>
    <head>
    <title>My Sample HTML5 web page</title>
    </head>
    <body>
    This is my sample web page.
    </body>
    </html>
    0 Comments
  • Postgres: Get table and field names from a given schema

    I work with a large Postgres install that has many hundreds of schemas. there are times that I need to find a list of tables and fields from a specific schema for a web application that I am developing.

    This will return the list of table names within the giving schema:

    select relname 
    from pg_stat_user_tables 
    WHERE schemaname='schema1';
    

    Then to get the given field names from the table that I have chosen:

    select column_name 
    from information_schema.columns 
    where table_name='mytable';
    
    0 Comments