Harrington Web

How to use Colors in the Command Line output with PHP

Friday, December 13, 2013

Here is a simple function you can copy into your php file and it will format whatever section of text you place in it with a certain background and foreground color.

<?php
function colorFormatText($string, $textColor, $bgColor)
{
 return chr(27)."[".$textColor."m".chr(27)."[".$bgColor."m".$string.chr(27)."[0m";
}
?>

The Colors

Here is a list of the colors available using this method. There are only 8 colors.

Text  Background  Color
30  40          Black
31  41          Red
32  42          Green
33  43          Yellow
34  44          Dark Blue
35  45          Pink
36  46          Light Blue
37  47          White

Top 10 Mac Keyboard Shortcuts

Friday, November 15, 2013
Control + Option + Command + Eject shutdown time image This option is used to shutdown your Mac. This nice thing about doing this instead of shutdown menu is it bypasses the counter and immediately starts shutting down.

Command + Option + Eject Puts the computer to sleep bypassing the countdown.

Control + Shift + Eject Allows you to put the display to sleep

Command + Space-bar shutdown time image Use this shortcut to open up the spotlight bar to search for an application or a file.

Command + Shift 4 This will allow you to select an area of the screen to take a screen shot of. Generally your picture will be dropped to your desktop.

Control + Command + D Dictionary shortcut. This is not my most used command but it can be useful in situations

Command + TAB If you are familiar with Windows this is kind of like the Alt+Tab functionality to switch between open applications

Option + Command + M Sometimes you just want to minimize everything on the screen to remove some clutter.

Command + , Open up the preferences window for your application

Command + ← / → / ↑ / ↓ These commands are useful when handling a document or text.

Command + ← or → will take you to the beginning or end of line.

Command ↑ or ↓ will take you to beginning or end of page.

JRuby Connection to AS400 DB

Wednesday, November 13, 2013

Hello friend, I suspect that by you visiting you are running in to the same issues I was having trying to get a database connection working using JDBC in JRuby. After that you may also be interested in the connecting to AS400 part. Please note that with a few tweaks of this example you can also connect to some other types of databases. I will note where as we go along.

When coding the first thing we need to do is get our environment set up properly. At the time of this writing I am using JRuby-1.7.4. If you have JRuby ready to go the next thing that we will need is the JDBC Driver that does the leg work of connecting to the AS400 DB. I like to use the JTOpen JDBC driver to connect. You can get that at http://jt400.sourceforge.net/. Once you download the driver unzip it and look through the files for a jtopen.jar and copy it to a lib folder within your project directory. If you are wanting a different type of db you can search for a JDBC driver that would be appropriate.

Lets make this thing work. We will start off by requiring java and our jar file that we just got.

require 'java'
require 'lib/jt400.jar'

Now that we have our list of requirements for the ruby file we can begin defining our class. In this section if you are using a different type of db your class definition will be different. For example MySql would be com.mysql.jdbc.Driver. From what I have read java_import is a relative new function to create instances of classes. If you have issues with the code saying ClassNotFoundException try the java.lang version commented out in the code example.

java_import 'com.ibm.as400.access.AS400JDBCDriver'

# To use on older versions of JRuby
# driverclass="com.ibm.as400.access.AS400JDBCDriver"
# java.lang::Class.forName(driverclass).newInstance

Once we have defined out class then we can build the connection to the db.

user = "someuser"
  pass = "somepass"
  conn = java.sql.DriverManager.getConnection(
      "jdbc:as400://server;naming=sql;errors=full", 
      user, 
      pass)

Lets have some fun and pull some data.

stmt = conn.createStatement
  rs = stmt.executeQuery("select name from table")
  while (rs.next) do
   puts rs.getString("name")
  end

Hey don't leave yet you need to clean up your house a little bit.

rs.close
stmt.close
conn.close()

Want to see it all put together? Take a look on GitHub

Ascii Art

Thursday, November 7, 2013

There are a variety of different ways that you can convert an image to ASCII. If you are a 3l31t3 uber geek and love the command line there is a utility called jp2a. If you run a posix complaint os like Linux, Mac etc there are ports to install the application from. Then at the command line you can jp2a yourimage.jpg

For those who would still like to try this but would rather a fun browser based GUI with all the wonderous mouse clicky stuff. Take a whiff of this cool website. http://picascii.com/

    ````````````````       `.,,,,';;;;;;;;;;;::...`:;;;;;;::;..:,`.`.`.....`,                          
    ```````                .,,.,:;;;;';;;;;;:``.,;;;;;;;;';:;;,;:` ,,,........                         
```                       `,,:::';;;;;;;;;;; ,:;;;;:;;;;;;;;'',,:,:``...,,...:                         
                          .,,:::';;;;;;;;;;:;,;;;;;;,,.:;;;:,,.,,::,,``.,,,..,                         
                          .,,,';;;;;;;;;:;:``'';;;,,;;;;:,,,.,,,::..,  . ,,....                        
```                      .,,.,';;;;;;;;;.:,`;;;;,,;;:,,,::::;;:,,.:,..,,`.,...,                        
              ````       ,,.,,;;;;;;;;;,`,,;;:;,;;,.,:,,,,,.,,,,,:,.,:.:,,`,.,: ``                  ```
         ```````        `,.,;:;;;;;;;;;;;`,:;;,,;.,,,,,,.,........,,,...::,..,:                        
                         ..:;:';;;;:;;;;;:;:;,,:,,,,,,,,.............;...;:,`::.                       
                         .,;;;:';;:::;;;;;;'::,,,,,..,................;.,.;:,.,                        
                        `.:;,;:;;::;;;;;;;;;,:,:,,,,.,...,...,.........:`..::,.``                      
                         :::,:';;;;;;;;;;;;,,.,,,,,,,,..................:..,::,`          ````         
                        `::;::;;;;;;;;;;;;:,:,,,,,,,,,.....,..........``,,:..,,,`   ``..`````````````` 
                        .:::;:;;;;;;;;;;;;::.,,,.,,......................;,`:`..`   `````              
                        ,:::;:;;;;;;;;;;;;,:.;,,,,,......................:.,,,`..`                     
                        ::::':;;;;;;;:::;;,:,;;;::,,......................,,,,,.,`                     
                       .::;;::;;;;;;;;;;;;:,;;;;;;;;:::::,,,,.............;,.:`  .`                    
                       ,::::;:;;;;;;;;;;;:,,;;;;;;;::::::::::::::,,,,,,,,,:,:`   .`             ``     
                       ,::::':;;;;;;;;;;',:.;;;;;;::::::::::::::::::::::::::::  `..                    
                       ::;;:';;;;;;;;;;;;,,,;;;;;:::::::::::::::::::::::::::,,```.`                    
                       ;;';;;;;;;;;;;;''';::;;;;;::::::::::::::::::::::::::::,,`..`                    
                       :;;;;:';;;::;;;;;';,;'::::::::::::::::::::::::::::::::,:...,                   `
                      `,,::::::::::::::,,:,:,,,,....,,:::::::::::::::::::::::,:,,.,                  ``
                   .,,:,,,:,,,,,,,,,,,,,,,,,,,,,,.............,,,,,::::::::;:::;:.,                    
                  `::,::,,,,,,,,,,,,,,,,,,,,,,,.......................,,,,:'.:;,,,`                    
                  .:::,:,,,,,,,,,,,,,,,,,,,,,,,,........................,.,:,:;':..`                   
                  .,,:,,::,,,,,,,,,,,,,,,,,,,...............................,,,,,`,,                   
                  ,,,:,:::,,,,,,,,,,,,,,,,,......................................,,.                   
         ```      .,,,,,:::,,,,,,,,,,,,,,,,....................................`,.,.                  `
                  `,,,,,,::,,,,,,,,,,,.,,,,,.........................`.`.`....`...,`                   
                  `,,,,::::,,,,,,,,,,,,,,,,,::,,,,......................```..```...                    
                   ,,,,:,:,,,,,,,,,,,,,::::;:;;:::,,..........,,,,,,,,...```````..`                    
                  `,:.:,,::,,,,,,,,,::;:::,,,::;:::,..........,,,:;;:::,,,.`````..               ````  
....```           `,,,:,,,:,,,,,,,,::::,,,,...,,,,,,,........,,,:::::,,,,,,.````..              `      
.````              ;,,,::,:,:,,,,,,,,,,,,:::::,,,,,,,........,,,,,,,..,,,,,,.```..                     
````               ',,,,:,:,,,,,,,,,,,::;'''';;';,:,,,.......,,::'''';;:,,,..```.                      
    ``  ``  ``     .,,,.::,,:,,,,,,,::;';:::;,,.;;:::,......,::;,:;;:,;;;:,..```.                      
`` ``  ````          ,:.,:,,,:,,,,,,:,:::::;::.,:::,:,,....,,,::,;::;.,:::,,.`````                  ` `
```..``.`````        .,,,,,,:,,,,,,,,,,,,,,,,,,,:,,,:,,,...,,.,,:,,::,...,...`.`                      `
```.,,::,,,,..``     `,,,,,,,,,,,,,,,,,,,,,,,,,,::,,,:,,,..,,,,::,,,,........```                      `
`` ``.,,::::,,..     ,,::,,,,,,,,.,,,,,,,:,,,,:,,,,,::,,,..,,..,:,,,,,.....`````            `..``..````
,`   ````..::,:,..```,,::,,,,,,,,,,,,,,,,,:::,,,,,,::,,,,..,,...,,:,,,,,.....```.          `...```..```
:.  ```   `.,.,:,.```.,,:,,,,,,,,,,,,,,,,,,,,,,.,,,:::,,,...,......,,......````..        ````..````````
;,.```     ```.,:....',,:,,,,,,,,,,,,,,,.......,,,,,::,,,.................`...`.`     `       `        
;,..``     ```.,.`,,:'+;:,,,,,,,,,,,,,,,........,,,,,,,,,.....................`.                       
;,...``    `````.';;;''+,:,,,,,,,,,,,,,,...`....,,,,,,,,,......................`            ``````     
;,,,.`` `` ``:`;';;;'''+::,,,,,,,,,,,,........,,,:::,,,,.....,,,...............`   ````....``..,,:,.`  
:,,,,.`````:'.'';;';;''+::,,,,,,,,,,,,,.....,,,:::::,,,,.....,,,,,..............`..............,,....``
;,,:,,.``.'',;';:.;;''++::,,,,,,,,,,,,,,...,,,,,:,,,,,,........,,,,.............```.``...,,,...```   ``
:,,,,...;'':;'',,'''''++::::,,,,,,,,,,,.,,,,,,,,:,,,,,,........,,,,,,.,..,.....:';`,..,,,..``        ``
:,:,,,,''':;'';,':;'''++:::,:,,,,,:,,,,,,,,:,,,,:,,,,,,.......,...,:,,,,,,,,...;;,`.`,..``          ```
;:::,:''';;''':'';''''++;::,:,,,,,,,,,,,,:,,,,,,,::::,,,...,,,,...,,::,,,,,,.,.,`.'':,,,.  `       `   
'::,;''';;;'';'+;'''''++;::,,:,,,,,,,,,,,,,.,,,,,:::,:,,,,,::,.....,,::,,,,,...''''++;,:;;.`   ```````.
';:;''';:;''';+';'''''++'::,:,,,,,,,,.,,,,,,.,,,,,,::,::::,,.,,......,:,,,....::;''''+',:;;:.``.```.,,:
;:''';;,:;'';'+'''''''+++;:,,,,,,,,,,..,.,,,,....,,,,,,..,.,.......,..,..,,.,,';,;'''++',::':,.```,,::;
;''';;.;;'+''+#'''''''++#;::,,:,,,,,,.,.,,,:,,,..................,,,..,.,.,..,+';:;'''++,`,:;;,.`.:,,::
''';;`;;'++''++'''''''++#;;::,,,,,,,,,.,,,,,;+;:,,,,..........,,;:..,...,,.,,'+';;;;'+':`,```` `.,:..,:
'';;`;;;++,'++''''''''++#';;::,,,,,,,,...,,,:;:,.,,,,,,,,,,,,,';:........,,.,+',,..``...+';,::;:::;,,:;
';:`;;;';.'++#''''''''++#+;;:::,,,,,,,...,..,::'..```..,..``.;;,........,,,,::,.';;'';''++':,,:;,;:';;;
;;`;;;'::;'+#+''''''''++#+';;::,,,,,,,.,,....,:::;..``````..::,.........,,,,;:'+';;''';'+++'::::;:';::;
:`;;;'.:''+++'''''''''+++#'';;::,,,,,,,......,,,::,,,.....,:,..........,,,,,:;+''';''''''++';:;:';;';;;
`;;;;`:+''+++'''''''''+++#'';;;::,,,,,,,.....,.,,,,,,,,,,,,,.........,..,,:;,:;++';;''''''++':;;;;;+':;
;;;;`,++'+++++''''''''+++#'';;;:::,,,,,,,....,...,....,...............,,,:+;,:;+++;;''''''++'`,::,`;'':
';;,,+++++++++''''+'''+++++';';;::,,,,,,,,...,,....,..................,,,+';:,;'++';''''';:,..` ``.:'+;
;;;,'++++++++''''++'''+++++'';';;:::::,,,,,,,,,,......,.............,,,,'+'';,:;+'';'':.,``,'+;;;'';'+'
';`:'++++++++:'+''+'''+++++';;;'';;::,,,,,,,.,,,,.,...............,,,,,'+''';::;'',.,.`,;''''+';;;';''+
;,,'+'++++',:.''''+''''++++';;;;'';:::,:,,,.,,,,,.................,,,:'+'''';;:;;,,;;''''''''+';';';''+
;.''++''+,.`'++'+'+''''+++++;;;;;'';:::,:,,,.,,,.................,,:,;+'''''';::''+';''''''''+';';';;'+
.,+++':,:,+'+#+''+++'''+++++;;;;;;'';:::::,,,,,,,,,,.............,:,;#'''''';;::;'+';''''''''++;';'';''
,'+++,`;++'++++''+++'''+++++;;:;;;;'';::::::,,,,,,,,.............,::#+''''''';;::;'';'''''''''+''''''''
:++::,++++'++++'++++'''+++++'::;;:;;'';:::::,,,,,,,,.............::#++''''''';;:;;+';''''''''+'';;;;.''
+:;`'+++++''++++++++'''+++++';::::;;;'';::::,,,,,,.............,::'#++''''''';;;:;;'''''''';',,.`````''
:`;+++++''''++++'+++'''++++++;:::::::;'';::::,,,,,............,,::+++'''''''';;;:;;';;'';,.,``:';''';''
'+++++++'+''+++;'+++'''++++++;::::::::;;';;;::,,,,,........,,,,:::;++''''''''';;;:'';..,``,;'''''''';''
++++++++''''++:.'+++''''+++++';:,:,:::::;'';':,,,,,.,.,,,,,,,,::::++++'''''''';;;:,:` ,;'''''''''''';';
++++++++'+''+;,+++++''''++++++;:::,::,::::;';;:::,,,,,,,,,,,,::,:;++++''''''';';;,,'';;''''''''''''';',
++++++++'';,:,+++++''''''+++++;:::,,,:,:,:::''';::,,,,,,,,,:::,,:;++++''''''''';+;''';;'''''''''';'';',
+++++++',:..++++++++''''+++++++:::,,,,,,,::,:;;;;;::::;;:::::,,::+++++'''''''''#';'''';'''''''''';'';,.
+++'++,.`;'+++++++++'''''++++++;::,,,,,,,,,,,,::;;;;'';;::::,,::;++++++''+'''+++';'''';'''''''''''''':'
++++;:.'''''++++++++'''''+++++++::,,,,,,,,,,,,,,,:::::::::,,,,::''++''++''+'+''+'''''';;''''''''':...,'
++;:`'++'''+++++++++''''''++++++::,,,,,,,,,,,,,,,,,,,,,,,,,,,::;;'''''+++''''''+'''''';''''':.:,.`...''
,:`:++++'''+++++++++''''''+++++++,,,,,,,,,,,,,,,,,,,,,,,,,,,,::++`;'''''+''''''+'''''';;:.,.`.;''''''''
`;++++++''++++++++++'''''''++++++:,,,,,,,,,,,,,,,,,,,,,,,,,,::;'''.:'''''+''';''+'';:,,. .;'''''+'''''+
++++++++'''++++'+++''''''''++++++;:,,,,,,,,,,,,,,,,,,,,,,,,,,:+''''`,'+'';''''+'',.``.:;;'''''''''''''+
++++++++''''++':+++'''''''''++++++:,,,,,,,,,,,,,,,,,,,,,,,,,:;+''''' .+'+''''',...,''+''''''''''''''''+
+++++++''''+',,'+++''''''''''++++++:,,,,,,,,,,,,,,,,,,,,,,,:;'''''';'`:'''''''''+''''++'';;'''''''''''+
++++++++'';,,,++'++''''''''''+++++++,,,,,,,,,,,,,:,,,,,,,,,:;+'''''';;.''''''++''''''''''';''''''''+'++
++++++++:,.,'+++'++''''''''''+++''+'+:,,,,,,::,,,,,,,,,,,,,:;'''''''''::''''+''''''''''''''''''+++++'++
'+++++::`.''++++''''''''''''''+''++''',,,,,,,:,:,,,,,,,,,,::,;'''''''''.:'''''''''''''+''''''';,,,,::'+
+++';:`,+'+'++++''''''''''''''+'''''+'::,,,,,,:,,,,,,,,,,,,'::;'''''''''`,+'''''''''''+'+'':.. ,:;'''+:
+';:`,''''''++++''''''''''''''+''+''+'+.+,,,,,,,,,,,,,,,,,:+'.:'''''''''''''''''+''''',,:,.`.''''''++,,
;:.,+'''''''++++++++';++++''''+'''+'+'':,+:,,,,,,,,,,,,,,,;'''`'''''''''+'''''''''''.``,''+'''''+++'+.+
`,+'+''''''''+++'+'.++'++#+#+'+'''+'''''`''',,,,,,,,,,,,,:''''',.''''''+''''';,,:::.''''''''''''+++++++
+++'''''''''+'+'',:.++++'+'''+#''''''''',+'+',,,,,,,,,,,::+'''+;`,''''+''':,,`.,:;;''''''''''''''+++'++
++''''''''''''';:.:''''''++''''+#+''+''';`'''+:;,,,,,,,::;+''''';,;'':.,,.`:'''''''''''''''''++'''+'+++
+''''''''''''::..'+'''''''+''''++++'''''',''''+,,,,,,,,::'''''''':,;,`,:;'''+'''''''''''''''+++++'+'+++
''''''''''',:`.''''''''''++'''+',;,`'''''.:'''';:,,,,:::;+'''''''','''''''''''''''''''''''''''::::,,+++

GIT - Disable Gnome-SSH-askpass

Wednesday, September 18, 2013

Recently ran a update on my Fedora Core 18 and have been really annoyed with the dialog window popping up everytime I run a remote GIT command from the CLI. There is an easy quick fix for this.

unset SSH_ASKPASS

PHEW!!! All Better lol. Have fun coding!

Colorful Tropic Salsa

Thursday, June 6, 2013

Ingredients

  • Pineapple
  • Avacado
  • Cilantro
  • Tomato
  • Salt
  • Jalepeno
  • Lime

Prepare

Chop up all the pineapple, avacado, tomato, jalepeno and cilantro into evenly sized chunks. If you don't like chunky salsa feel free to chop up finer or stick in a blender. Put ingredients in a bowl and mix well adding some salt and squeezed lime to taste. For best results mix well and set in fridge for an hour before eating. All the juice will meld together creating a very tasty salsa, that goes great on mixed greens salad.

Soap Requests using CURL

Saturday, April 20, 2013

If you ever need a way to test a webservice from a curl you can make a file of your request XML and call the following command below to get a response.

curl -H "Content-Type: text/xml; charset=utf-8" \
     -H "SOAPAction: " \
     -k\
     -d @file.xml\
     -X POST https://www.webservice-url.com/webservice/