Skip to content

Instantly share code, notes, and snippets.

View KatrinaHoffert's full-sized avatar

Katrina Mitchell KatrinaHoffert

View GitHub Profile
@KatrinaHoffert
KatrinaHoffert / demo.html
Created February 8, 2015 22:44
Demoing reverse routing
<input id="locationId" type="hidden" value="123" />
<button id="submitButton">Submit</button>
<script>
$("#submitButton").on("click", function() {
// TODO: check if set, first, and handle case of not set
var locationId = $("#locationId").val();
var destUrl = jsRoutes.controllers.LocationController
.showLocation(locationId).url;
window.location(destUrl);
#!/usr/bin/env python 1
import Tkinter as tk 2
class Application(tk.Frame): 3
def __init__(self, master=None):
tk.Frame.__init__(self, master) 4
self.grid() 5
self.createWidgets()
def createWidgets(self):

First: The term monad is a bit vacuous if you are not a mathematician. An alternative term is computation builder which is a bit more descriptive of what they are actually useful for.

You ask for practical examples:

Example 1: Handling would-be partial functions:

def divide(numerator: Int, denominator: Int): Option[Int] = {
	if(denominator != 0) Some(numerator / denominator)
	else None
@KatrinaHoffert
KatrinaHoffert / Scala intro.md
Last active August 29, 2015 14:13
Stop making shelves and start making unicorns -- putting the "fun" in "functional"

Scala is an object oriented and functional language that compiles to class files for use on the JVM (same as Java). Biggest advantage is that it provides very powerful functional programming concepts as well as a number of useful programming tools for writing cleaner or less code (two major complaints about Java is that it is overly verbose and slow to evolve).

This file explains the basics to Scala as well as some cool features about it. The point is to make it clear that it's probably not going to be a difficult jump to use and in fact may be completely worthwhile.

Types and variables

Types like those in Java

Most of Scala's basic types are very similar to Java's. Main difference is that they're all objects. And thus, we write the type in uppercase (Scala code conventions are very similar to Java's). Also, types now go after the variable name. An example of a simple function is shown below:

def greet(name: String) = {
/*jshint multistr:true */
text = "Blah blah blah blah blah blah Eric \
blah blah blah Eric blah blah Eric blah blah \
blah blah blah blah blah Eric";
var myName = "Eric";
var hits = [];
@KatrinaHoffert
KatrinaHoffert / .Instructions_for_vimrc.md
Last active August 29, 2015 14:10
My current .vimrc file

This is my .vimrc file. Just install it to ~/.vimrc. I've tested this on Windows with Cygwin's MinTTY and on Linux with Konsole.

In order to use it, you'll need to make a few other changes.

##Plugins

In order for the plugins to work, you'll have to install Vundle as described here. You'll probably only have to do steps 2 and 4. Step 1 is just getting Git (which you probably already have) and step 3 is already done. vim-airline is the part that really makes it look pretty.

##Fonts

@KatrinaHoffert
KatrinaHoffert / aaa.h
Created November 24, 2014 03:03
Demonstration of include guards -- now with include guards
#ifndef _AAA_H_
#define _AAA_H_
int foo();
#endif
@KatrinaHoffert
KatrinaHoffert / aaa.h
Created November 24, 2014 02:53
Demonstration of include guards -- before include guards
int foo();
#!/usr/bin/env bash
#
# By Mike Hoffert. Based on clean-kernel.sh in OS161.
#
# Does a better job of removing unnecessary files. Will reset the build number
# that OS161 thinks it is (if you don't like this, remove the line that deletes
# src/defs.mk).
#
# You will have to re-run conf-kernel.sh after running this (and rebuild, of
# course). If you use my other script, build-kernel2.sh, this script should only
#!/usr/bin/env bash
#
# By Mike Hoffert. Based on build-kernel.sh in OS161.
#
# Alternative build script. Only errors are shown. Will automatically
# configure the script.
#
# Usage:
# ./build-kernel2 <kernel-name> [options]
#