Skip to content

Instantly share code, notes, and snippets.

View bokmann's full-sized avatar

David Bock bokmann

View GitHub Profile
require 'io/console'
# Reads keypresses from the user including 2 and 3 escape character sequences.
def read_char
STDIN.echo = false
STDIN.raw!
input = STDIN.getc.chr
if input == "\e" then
input << STDIN.read_nonblock(3) rescue nil
@bokmann
bokmann / suggestions.md
Last active August 29, 2015 14:11
worst_language_ever
@bokmann
bokmann / gas_vs_petrol.txt
Last active August 29, 2015 14:25
The "Gasoline vs. Petrol" Exercises
These are three exercises that deal with the thought process of converting data from one format to another,
a problem we enounter often in software development. The last problem is about publishing this data, both
as a website and as a webservice that publishes json. Tackling that problem will make you think about
various things like "how do we get the data off of the websites we're referencing?" and "when do we update
that data?" that can lead to great architectural and structural conversations.
Exercise #1:
@bokmann
bokmann / knockknockinator.rb
Last active August 29, 2015 14:25
This is a work-in-progress. This is an example for students to learn the nature of using state in a class using instance variables. This could also break into an example of why threading is complicated, but thats not the first point of this example.
The KnockKnockinator
We're going to write a class that listens to and responds to knock knock jokes.
An interaction with this class should look like this:
> inator = KnockKnockInator.new
> response = inator.hears("Knock Knock")
@bokmann
bokmann / rake_snippet.rb
Last active August 29, 2015 14:28
Created as a snipper to share with Avdi.
# once upon a time these rake tasks were in use in my house. I had a program that would scrape my kids
# TV shows off of my tivo as they were recorded and dump them in a directory. Of course, they had tivo's
# encryption on them. the 'decode' task transcoded them to mp4 and moved them to a different directory,
# and the 'publish' task would copy them to a generation one Apple TV (the one with the 40 gig hard drive).
# My kids then had a never-ending source of Dora and Dinosaur Train, and I had vital space on my Tivo for
# things like "The Walking Dead". With a parental code in my Tivo, my kids' shows were sandboxed in a
# safe place.
#
# I presented this code as an example of automation in a conference talk done several times, and this code
# was actually taken off of a slide used for that talk. As such, the original code was a little longer
jQuery.fn.submitAndUpdateCollection = function(collection_id) {
$(this).submit(function() {
$.ajax({
type: 'post',
url: $(this).attr("action"),
beforeSend: function (xhr) {
xhr.setRequestHeader("Accept", "text/html-partial")
},
data: $(this).serialize(),
success: function(partial) {
def create
unless @commentable.nil?
@comment = @commentable.comments.create!(params[:comment])
respond_to do |format|
format.html { redirect_to @commentable }
format.json { @commentable.to_json }
format.partial { render :partial => "comments/comment.html.erb",
:object => @comment,
:layout => false }
end
$(document).ready(function(){
$("#new_comment").submitAndUpdateCollection("#comments")
});
Mime::Type.register "text/html-partial", :partial
class YourTypicalWorkitem < ActiveRecord::Base
include StonePath
stonepath_workitem do
aasm_initial_state :data_entry
aasm_state :data_entry
aasm_state :data_validation
aasm_state :further_processing