Skip to content

Instantly share code, notes, and snippets.

@jtmorris
jtmorris / py_docstrings_strings.py
Last active August 6, 2019 20:43
Successful partial string comparison in Python doctests. Enable the use of ellipsis in string output checked by a doctest.
# When comparing inexact strings in Python doctests, and using ellipsis,
# be sure to follow the output generating statement with a comment:
# "# doctest: +ELLIPSIS"
# Reference: https://web.archive.org/web/20190806202840/https://pymotw.com/2/doctest/#handling-unpredictable-output
# This tripped me up when first starting out with doctests. I would
# output a string in which the end or middle was unimportant. I needed
# to ensure only certain parts. The tests would always fail. This
# turns on ellipsis processing when dealing with strings.
/**
* Drive a collection of stepper motors, 1 step at a time in sequence, a desired number of steps.
* Used to approximate simultaneous motion of each stepper by not blocking until motion is completed.
*
* steppers = Array of Stepper library stepper motors.
* numSteppers = length of steppers array.
* numStepsMap = number of total steps to advance by. Positve number moves forward. Negative number moves backward.
*/
void simultaneousStepperDrive(Stepper steppers[], int numSteppers, int numStepsMap[]) {
int stepsExecuted = 0;
@jtmorris
jtmorris / gist:6182007
Created August 8, 2013 06:34
HTML: Dropdown Menu
<ul id='main-nav'>
<li><a href=''>Item 1</a></li>
<li><a href=''>Item 2</a></li>
<li><a href=''>Item 3</a></li>
<li>
<a href=''>Item 4</a>
<ul>
<li>
<a href=''>Subitem 1</a>
<ul>
@jtmorris
jtmorris / gist:6181999
Created August 8, 2013 06:33
CSS: Dropdown Menu - Horizontal with vertical sublevels
#main-nav { list-style-type: none; }
#main-nav ul { list-style-type: none; margin: 0; padding: 0; }
#main-nav a { display: block; width: 100%; height: 100%; text-align: center; line-height: 30px; }
/* Universal Level Code */
#main-nav li { width: 175px; height: 30px; }
#main-nav li ul { position: absolute; display: none; }
#main-nav li:hover > ul { display: block; }
/* Level 1 */
@jtmorris
jtmorris / gist:5804013
Created June 18, 2013 09:36
htaccess: Remove the www.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^your-site.com$ [NC]
RewriteRule ^(.*)$ http://your-site.com/$1 [L,R=301]
@jtmorris
jtmorris / gist:5803962
Created June 18, 2013 09:28
JQuery: AJAX
$(document).ready(function(){
$("form#formId").submit(function() {
inputField = $('#inputFieldId').attr('value');
$.ajax({
type: "POST",
url: "yourpage.php",
cache: false,
data: "inputField ="+ inputField,
success: function(html){
$("#ajax-results").html(html);
@jtmorris
jtmorris / gist:5803937
Last active December 18, 2015 15:19
HTML5: DOCTYPE
<!DOCTYPE HTML>