Tuesday, March 25, 2014

10 Most Controversial Programming Opinions

What's your most controversial programming opinion?


  1. Programmers who don't code in their spare time for fun will never become as good as those that do.
  2. The only "best practice" you should be using all the time is "Use Your Brain".
  3. Most comments in code are in fact a pernicious form of code duplication.
  4. XML is highly overrated.
  5. Not all programmers are created equal.
  6. If you only know one language, no matter how well you know it, you're not a great programmer.
  7. Performance does matter.
  8. Print statements are a valid way to debug code.
  9. Your job is to put yourself out of work.
  10. Getters and Setters are Highly Overused.

Tuesday, March 11, 2014

Getting the most out of Fitnesse Suites

Fitnesse offers the ability to use scripts inside tests and suites as well as use REST calls following their API. This is handy because it gives us the chance to write JavaScript/jQuery hacks to improve the utility of Fitnesse.

When writing a suite, I will create tables to put similar tests together. I start with the test name, then a description, and the current status. The script uses the test name to query the restful service, which returns the latest test result and populates the status cell based on the result. This provides a range of benefits:
  • Allows to skip running the suite, which can be time consuming on the machine it is running (as well as blocking for other test suites)
  • Get immediate results for each test instead of waiting for the suite
  • Easier to navigate than the suite test page

Example



1. Update the ajax url parameter with your url, leading up to the suite with the following period. As long as the testnames in the first column are valid, it will automatically populate the current status column with the last data.

JavaScript

<!--[if lt IE 7 ]> <span id="ie" class="ie6"></span> <![endif]-->
<!--[if IE 7 ]>    <span id="ie" class="ie7"></span> <![endif]-->
<!--[if IE 8 ]>    <span id="ie" class="ie8"></span> <![endif]-->
<!--[if IE 9 ]>    <span id="ie" class="ie9"></span> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <span id="ie" class=""></span> <!--<![endif]-->
<script>
"use strict";
// These values count up each of the tests statuses. Display for a summary of the suite.
var passingTests = 0;
var failedTests = 0;
var exceptionTests = 0;
var ignoredTests = 0;

$( document ).ready(function() {
// For each tr that is not the first
$('table tr:not(:first-child) td:first-child').each(function() {
// get the name of the test out (from >Test Name)
     var testname = $(this).text().substring(1);

// Make the rest call
$.ajax({ url: "http://yoururl.yourSuite."+testname+"?pageHistory&resultDate=latest&format=xml", cache: false, type: "GET", dataType: "xml", context: this, success: function(data) { var output = ""; //IE doesn't support innerHTML element if($("#ie").is('.ie6, .ie7, .ie8, .ie9')){ var correct = $(data).find("counts")[0].firstChild.text; var wrong = $(data).find("counts")[0].firstChild.nextSibling.text; var ignored = $(data).find("counts")[0].firstChild.nextSibling.nextSibling.text; var exception = $(data).find("counts")[0].firstChild.nextSibling.nextSibling.nextSibling.text; } else { // For everyone else var correct = $(data).find("counts")[0].childNodes[1].innerHTML; var wrong = $(data).find("counts")[0].childNodes[3].innerHTML; var ignored = $(data).find("counts")[0].childNodes[5].innerHTML; var exception = $(data).find("counts")[0].childNodes[7].innerHTML; } output += "<span class=\"correct\">right: " + correct + "</span><br/>"; if(wrong != "0") { output += "<span class=\"wrong\">wrong: " + wrong + "</span><br/>"; $(this).closest("tr").addClass("testFailed"); } if(wrong != "0" && exception == "0"){ failedTests++; } if(ignored != "0"){ output += "<span class=\"ignored\">ignored: " + ignored + "</span><br/>"; ignoredTests++; } if(exception != "0"){ output += "<span class=\"exception\">exception: "+ exception +"</span>"; $(this).closest("tr").addClass("testException"); exceptionTests++; } if(wrong == "0" && exception == "0" && correct != "0") { passingTests++; $(this).closest("tr").addClass("testPassed"); } // Append to status td $(this).closest("td").next().next().append(output); } }); }); }); </script>


CSS
<style>
.testPassed {
background-color:#CDFECD;
}

.testFailed {
background-color:#FFCCCC;
}

.testException {
background-color:#FFFFCC;
}

.correct { 
color:green;
font-weight:bold;
}

.wrong { 
color:red;
font-weight:bold;
}

.exception { 
color:#FFCC00;
font-weight:bold;
}

.ignored { 
color:grey;
font-weight:bold;
}
</style>

Monday, March 3, 2014

How to renew your blogger domain name

  1.  Go to admin.google.com, Sign in using your Google Apps credentials, username@yourdomain.com (not your gmail account!) -- I think the usernames default to "bloggeradmin@yourdomain.com"
  2. If you still can't get in, go to  https://admin.google.com/yourdomainname.com/ForgotAdminAccountInfo
  3. Once you submit a password reset, check your gmail linked to the account for the password reset.
  4. Log in using new credentials, go to Billing section
  5. Activate automatic renewal for domain registration.
I followed these steps and had this expired domain back up and running in about 15 minutes!

Sunday, November 3, 2013

MIME Types

f you are creating a podcast or video feed you will need to include the appropriate mime type, the proper format is indicated below.

file typeMIME type
aiapplication/postscript
aifaudio/x-aiff
aifcaudio/x-aiff
aiffaudio/x-aiff
asctext/plain
atomapplication/atom+xml
auaudio/basic
avivideo/x-msvideo
bcpioapplication/x-bcpio
binapplication/octet-stream
bmpimage/bmp
cdfapplication/x-netcdf
cgmimage/cgm
classapplication/octet-stream
cpioapplication/x-cpio
cptapplication/mac-compactpro
cshapplication/x-csh
csstext/css
dcrapplication/x-director
difvideo/x-dv
dirapplication/x-director
djvimage/vnd.djvu
djvuimage/vnd.djvu
dllapplication/octet-stream
dmgapplication/octet-stream
dmsapplication/octet-stream
docapplication/msword
dtdapplication/xml-dtd
dvvideo/x-dv
dviapplication/x-dvi
dxrapplication/x-director
epsapplication/postscript
etxtext/x-setext
exeapplication/octet-stream
ezapplication/andrew-inset
gifimage/gif
gramapplication/srgs
grxmlapplication/srgs+xml
gtarapplication/x-gtar
hdfapplication/x-hdf
hqxapplication/mac-binhex40
htmtext/html
htmltext/html
icex-conference/x-cooltalk
icoimage/x-icon
icstext/calendar
iefimage/ief
ifbtext/calendar
igesmodel/iges
igsmodel/iges
jnlpapplication/x-java-jnlp-file
jp2image/jp2
jpeimage/jpeg
jpegimage/jpeg
jpgimage/jpeg
jsapplication/x-javascript
karaudio/midi
latexapplication/x-latex
lhaapplication/octet-stream
lzhapplication/octet-stream
m3uaudio/x-mpegurl
m4aaudio/mp4a-latm
m4baudio/mp4a-latm
m4paudio/mp4a-latm
m4uvideo/vnd.mpegurl
m4vvideo/x-m4v
macimage/x-macpaint
manapplication/x-troff-man
mathmlapplication/mathml+xml
meapplication/x-troff-me
meshmodel/mesh
midaudio/midi
midiaudio/midi
mifapplication/vnd.mif
movvideo/quicktime
movievideo/x-sgi-movie
mp2audio/mpeg
mp3audio/mpeg
mp4video/mp4
mpevideo/mpeg
mpegvideo/mpeg
mpgvideo/mpeg
mpgaaudio/mpeg
msapplication/x-troff-ms
mshmodel/mesh
mxuvideo/vnd.mpegurl
ncapplication/x-netcdf
odaapplication/oda
oggapplication/ogg
pbmimage/x-portable-bitmap
pctimage/pict
pdbchemical/x-pdb
pdfapplication/pdf
pgmimage/x-portable-graymap
pgnapplication/x-chess-pgn
picimage/pict
pictimage/pict
pngimage/png
pnmimage/x-portable-anymap
pntimage/x-macpaint
pntgimage/x-macpaint
ppmimage/x-portable-pixmap
pptapplication/vnd.ms-powerpoint
psapplication/postscript
qtvideo/quicktime
qtiimage/x-quicktime
qtifimage/x-quicktime
raaudio/x-pn-realaudio
ramaudio/x-pn-realaudio
rasimage/x-cmu-raster
rdfapplication/rdf+xml
rgbimage/x-rgb
rmapplication/vnd.rn-realmedia
roffapplication/x-troff
rtftext/rtf
rtxtext/richtext
sgmtext/sgml
sgmltext/sgml
shapplication/x-sh
sharapplication/x-shar
silomodel/mesh
sitapplication/x-stuffit
skdapplication/x-koan
skmapplication/x-koan
skpapplication/x-koan
sktapplication/x-koan
smiapplication/smil
smilapplication/smil
sndaudio/basic
soapplication/octet-stream
splapplication/x-futuresplash
srcapplication/x-wais-source
sv4cpioapplication/x-sv4cpio
sv4crcapplication/x-sv4crc
svgimage/svg+xml
swfapplication/x-shockwave-flash
tapplication/x-troff
tarapplication/x-tar
tclapplication/x-tcl
texapplication/x-tex
texiapplication/x-texinfo
texinfoapplication/x-texinfo
tifimage/tiff
tiffimage/tiff
trapplication/x-troff
tsvtext/tab-separated-values
txttext/plain
ustarapplication/x-ustar
vcdapplication/x-cdlink
vrmlmodel/vrml
vxmlapplication/voicexml+xml
wavaudio/x-wav
wbmpimage/vnd.wap.wbmp
wbmxlapplication/vnd.wap.wbxml
wmltext/vnd.wap.wml
wmlcapplication/vnd.wap.wmlc
wmlstext/vnd.wap.wmlscript
wmlscapplication/vnd.wap.wmlscriptc
wrlmodel/vrml
xbmimage/x-xbitmap
xhtapplication/xhtml+xml
xhtmlapplication/xhtml+xml
xlsapplication/vnd.ms-excel
xmlapplication/xml
xpmimage/x-xpixmap
xslapplication/xml
xsltapplication/xslt+xml
xulapplication/vnd.mozilla.xul+xml
xwdimage/x-xwindowdump
xyzchemical/x-xyz
zipapplication/zip

Friday, October 25, 2013

PHP getenv Get IP address function


function get_ip_address() {
    $ip_address = '';
    if (getenv('HTTP_CLIENT_IP'))
      $ip_address = getenv('HTTP_CLIENT_IP');
    else if(getenv('HTTP_X_FORWARDED_FOR'))
      $ip_address = getenv('HTTP_X_FORWARDED_FOR');
    else if(getenv('HTTP_X_FORWARDED'))
      $ip_address = getenv('HTTP_X_FORWARDED');
    else if(getenv('HTTP_FORWARDED_FOR'))
      $ip_address = getenv('HTTP_FORWARDED_FOR');
    else if(getenv('HTTP_FORWARDED'))
      $ip_address = getenv('HTTP_FORWARDED');
    else if(getenv('REMOTE_ADDR'))
      $ip_address = getenv('REMOTE_ADDR');
    else
      $ip_address = 'UNKNOWN';

    return $ip_address; 
  }

Monday, October 7, 2013

XML XSD Schema to Java Bindings

XML Schema TypeJava Data Type
xsd:stringjava.lang.String
xsd:integerjava.math.BigInteger
xsd:intint
xsd.longlong
xsd:shortshort
xsd:decimaljava.math.BigDecimal
xsd:floatfloat
xsd:doubledouble
xsd:booleanboolean
xsd:bytebyte
xsd:QNamejavax.xml.namespace.QName
xsd:dateTimejavax.xml.datatype.XMLGregorianCalendar
xsd:base64Binarybyte[]
xsd:hexBinarybyte[]
xsd:unsignedIntlong
xsd:unsignedShortint
xsd:unsignedByteshort
xsd:timejavax.xml.datatype.XMLGregorianCalendar
xsd:datejavax.xml.datatype.XMLGregorianCalendar
xsd:gjavax.xml.datatype.XMLGregorianCalendar
xsd:anySimpleTypejava.lang.Object
xsd:anySimpleTypejava.lang.String
xsd:durationjavax.xml.datatype.Duration
xsd:NOTATIONjavax.xml.namespace.QName

Thursday, August 22, 2013

List of JavaScript Interview Questions

  • What's the difference between call() and apply()?
  • What's the difference between setTimeout() and setInterval()? I can't even begin to tell you how many "JavaScript developers" I've interviewed who cannot answer this. I'm floored every time!
  • Explain what a closure is and give examples of when to use them and why it makes sense (and sometimes I ask when it DOESN'T make sense).
  • I usually ask some probing questions that are meant to lead to an answer along the lines of "because JavaScript is single-threaded". Tricky to ask without leading the candidate, usually I try for some sort of scenario involving a slow or locked up UI.
  • Explain what prototypal inheritance is. I'm looking for an answer that indicates they generally understand how prototypes work and how inheritance with them works.
  • I like to ask "if you have an object referenced by variable O, and you have another variable M that names a method of O, how do you call the method with no arguments?" The answer of course is simply O[M]() but you'd be surprised how many people don't seem to know you can do things like that (even though it's one of the things that makes JavaScript as powerful as it is).
  • How do you make an AJAX call? Looking simply for XMLHttpRequest of course, bonus points if they mention anything about JSON-P or hidden iFrames or any other "hack" - some argue XMLHttpRequest is a hack itself of course :)
  • What's the difference between undefined and null?
  • What statement gets a reference to a DOM node by ID?
  • How do you implement a Map? (all they have to say is an object is a map and I'm happy!)
  • What are the implications of a large number of script tags on a page? (looking for something about performance and concurrent requests and that sort of thing)
  • How do you create a multidimensional array?