Skip to content

Instantly share code, notes, and snippets.

@josephmosby
josephmosby / sqrt
Last active August 29, 2015 14:06
Mechanisms for describing a square root function, from MIT
(define (average x y)
(/ (+ x y) 2))
(define (improve guess x)
(average guess (/ x guess)))
(define (good-enough? guess x)
(< (abs (- (square guess) x)) 0.001))
(define (sqrt-iter guess x)
@josephmosby
josephmosby / Sum-of-greatest-two
Created September 15, 2014 18:20
Saving accomplishments in Lisp because parentheses
(define (find-largest x y z)
(cond ((and (> x y) (> x z)) x)
((and (> y z) (> y x)) y)
((and (> z x) (> z y)) z)))
(define (find-second-largest x y z)
(cond ((and (> y x) (< y z)) y)
((and (> z y) (< z x)) z)
((and (> x z) (< x y)) x)))
@josephmosby
josephmosby / app.js
Created August 26, 2014 20:15
IE 10 and 11 targeting
jQuery(document).ready( function() {
var doc = document.documentElement;
doc.setAttribute('data-useragent', navigator.userAgent);
});
@josephmosby
josephmosby / checkwidth.js
Created November 21, 2013 21:08
Adjust menus to be table-cell or inline-block depending on height
function checkWidth() {
var windowSize = jQuery(window).width();
if (windowSize > 660) {
jQuery("#main-menu").css('display', 'table-row');
jQuery("#main-menu li").css('display', 'table-cell');
} else {
jQuery("#main-menu").css('display', 'inline');
jQuery("#main-menu li").css('display', 'inline-block');
}
}
@josephmosby
josephmosby / footer_drop.js
Created November 20, 2013 21:16
Drop a footer to the bottom of the page
@josephmosby
josephmosby / drupal6dbsurgery.md
Created September 9, 2013 20:41
A brief description of some database surgery on theme files in Drupal 6.

Theme Database Surgery with Drupal 6

Occasionally a Drupal 6 theme will refuse to budge, despite any attempts to force a theme update. I came across this problem while attempting to modify my theme.info file to add a few additional JS files. Saving the theme configuration did not work, nor did clearing the database cache.

The following step did work, however:

  1. Access the database through phpmyadmin. Theme information is stored in the 'system' table with a type of 'theme.'
  2. Hunt down the theme entry in question.
  3. Edit the theme's info. This JSON entry is architected in the following manner: a. Keys with the type "a:x" where x is an integer indicate the number of entries in the following hash table.

In our most recent exercise, we explained the basic structure of a web page to our hypothetical student. By doing so, we presented static content to our student. It's now time for us to introduce the basics of dynamic content to our student by introducing some basic JavaScript.

Let's start again with our HTML document from before:

	<head>
		<title>This is our first web page!</title>
	</head>

The Curious Case of the Paralyzed Man and the Password Manager

To the system engineer, "accessibility" represents a set of user stories for an end user who cannot, for reasons unrelated to intentionally-designed security, access all application functionality. An individual who cannot see will have issues reading a system screen, and must use some sort of technology to have a screen translated into an audio format. An individual who cannot hear cannot make use of training materials with a voiceover. These user stories are often not initially considered by the system engineer, who is generally restricted by deadlines and must consider only the functionality that he requires to test the application as well as the requirements of his direct customer. Though these combined requirements may ultimately satisfy 99% of the application's end users, the final 1% presents an interesting challenge for the engineer.

I came across a thread on Hacker News posted by a quad

Teaching Code to Artists, Round 2

In our earlier lesson, we discussed the basics of the web and how pages can be modified in-line as an introduction to programming for our hypothetical student. It's now time to expose a little bit more of the underbelly of the internet.

In this lesson, we want to walk the student through the construction of an HTML document and demonstrate how these elements are represented within the browser. Our student is starting to grasp the idea that data is delivered via the Internet to their browser, so we need to show them that they can build this very same data themselves. Let's start things off slowly:

<html>

</html>

Dealing with Spreadsheets in Python

A friend recently came to me with a data management problem. He has a stack of Excel spreadsheets that need to be turned into an API, which means that the data is going to have to be dumped out of those spreadsheets and inserted into a database. I haven't seen the data yet, so I can't make a recommendation on how we should tackle it - but I have some ideas.

Option 1: Export to Access

Microsoft Excel actually provides a really nice integration with Access, and Access allows you to set up data extracts that can be loaded into your data storage mechanism of choice. This is easily the most "point-and-click" method for approaching this task if you're of the GUI persuasion. The "External Data" tab of your Microsoft Access database will have everything you need to import and export your data, if you'd prefer to use this method. Given the quality of the wizards available to help you, I won't be discussing this one much.

Option 2: Work with CSVs