Skip to content

Instantly share code, notes, and snippets.

View KatrinaHoffert's full-sized avatar

Katrina Mitchell KatrinaHoffert

View GitHub Profile
@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) = {

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
#!/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):
@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);
@KatrinaHoffert
KatrinaHoffert / output
Created February 18, 2015 02:21
Output of `gcc -v main.o hello.o`
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/lto-wrapper.exe
Target: x86_64-pc-cygwin
Configured with: /cygdrive/i/szsz/tmpp/gcc/gcc-4.9.2-2.x86_64/src/gcc-4.9.2/configure --srcdir=/cygdrive/i/szsz/tmpp/gcc/gcc-4.9.2-2.x86_64/src/gcc-4.9.2 --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/libexec --datadir=/usr/share --localstatedir=/var --sysconfdir=/etc --libdir=/usr/lib --datarootdir=/usr/share --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --enable-__cxa_atexit --with-dwarf2 --with-tune=generic --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmath-s
.file "hello.c"
.section .rdata,"dr"
.LC0:
.ascii "Hello, World!\0"
.text
.globl sayHello
.def sayHello; .scl 2; .type 32; .endef
.seh_proc sayHello
sayHello:
pushq %rbp
/**
* jQuery Typeahead
* Copyright (C) 2014 RunningCoder.org
* Licensed under the MIT license
*
* @author Tom Bertrand
* @version 1.7.6 (2015-01-17)
*
* @link
* http://www.runningcoder.org/jquerytypeahead/
/*------------------------------------*\
CONTENTS
\*------------------------------------*/
/*
LAYOUT
INPUT, BUTTON & DROPDOWN
*/
/*------------------------------------*\
LAYOUT
jack: function(req, res) {
if (req.isSocket && req.body.hasOwnProperty('gameId') && req.body.hasOwnProperty('pNum') && req.body.hasOwnProperty('thiefId') && req.body.hasOwnProperty('victimId') && req.body.hasOwnProperty('jackId') && req.body.hasOwnProperty('targetId')) {
Game.findOne(req.body.gameId).populate('players').populate('deck').populate('scrap').exec(function(error, game) {
if (error || !game) {
console.log("Game " + req.body.gameId + " not found for jack");
res.send(404);
} else {
Player.find([req.body.thiefId, req.body.victimId]).populate('hand').populate('points').populate('runes').exec(function(erro, players) {
if (erro || !players[0] || !players[1]) {
import java.awt.Point;
public class Main {
public static int[][] create2dArray(int size) {
int[][] array = new int[size][size];
for(int row = 0; row < size; ++row) {
for(int col = 0; col < size; ++col) {
array[row][col] = (col + 1) + size * row;
}