Skip to content

Instantly share code, notes, and snippets.

View profh's full-sized avatar

Larry Heimann (Prof. H) profh

  • Carnegie Mellon University
  • Pittsburgh, PA
  • X @profh
View GitHub Profile
@profh
profh / introrx.md
Created October 14, 2020 17:32 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@profh
profh / Count lines in Git repo
Created April 17, 2020 18:47 — forked from mandiwise/Count lines in Git repo
A command to calculate lines of code in all tracked files in a Git repo
// Reference: http://stackoverflow.com/questions/4822471/count-number-of-lines-in-a-git-repository
$ git ls-files | xargs wc -l
@profh
profh / 67272_Exam1_2020.rb
Created February 27, 2020 18:38
Arrays and hashes for the 2020 midterm in 67-272
characters = { kirk: :TOS, spock: :TOS, picard: :TNG, janeway: :VOY, scotty: :TOS, sisko: :DS9,
kira: :DS9, chakotay: :VOY, seven: :VOY, dax: :DS9, tuvok: :VOY, tpol: :ENT,
riker: :TNG, troi: :TNG}
series = { TOS: "The Original Series", NTG: "The Next Generation", DS9: "Deep Space 9",
VOY: "Voyager", ENT: "Enterprise" }
runtimes = { TOS: [1966, 1969], NTG: [1987, 1994], DS9: [1993, 1999],
VOY: [1995, 2001] , ENT: [2001, 2004] }
@profh
profh / blocks_2019.rb
Created February 25, 2020 15:07
Blocks from exam 1, Spring 2019
criminal_aliases = {"Oswald Cobblepot"=>"Penguin", "Jonathan Crane"=>"Scarecrow", "Harvey Dent"=>"Two Face", "Edmund Dorrance"=>"Bane", "Thomas Elliot"=>"Hush", "Carmine Falcone"=>"The Roman", "Victor Fries"=>"Mr. Freeze", "Sophia Gigante"=>nil, "Matt Hagan"=>"Clayface", "Pamela Isley"=>"Poison Ivy", "Waylon Jones"=>"Killer Croc", "Selina Kyle"=>"Catwoman", "Kirk Langstrom"=>"Man-Bat", "Salvatore Maroni"=>nil, "Jack Napier"=>"Joker", "Edward Nigma"=>"Riddler", "Harleen Quinzel"=>"Harley Quinn", "Slade Wilson"=>"Deathstroke", "Ra's al Ghul"=>"Ra's"}
female_criminals = %w[Selina\ Kyle Harleen\ Quinzel Pamela\ Isley Sophia\ Gigante"]
convicted_felons = ["Oswald Cobblepot", "Jonathan Crane", "Harvey Dent", "Edmund Dorrance", "Thomas Elliot", "Victor Fries", "Matt Hagan", "Pamela Isley", "Waylon Jones", "Selina Kyle", "Salvatore Maroni", "Edward Nigma", "Harleen Quinzel", "Slade Wilson"]
# enhanced_powers = ["Jonathan Crane", "Edmund Dorrance", "Matt Hagan", "Pamela Isley", "Waylon Jones", "Kirk Langstrom", "S
# An example of nested forms if using the "accepts_nested_attributes_for" approach
# Context is projects and tasks, not customers and users
# Assumes you are using simple_form and nested_form gems:
# gem 'simple_form', '3.0.1'
# gem 'nested_form','0.3.2'
<%= simple_nested_form_for @project, :html => { :class => 'form-horizontal' } do |project_form| %>
<div class="row">
<div class="small-7 columns">
<fieldset>
class CustomersController < ApplicationController
include ActionView::Helpers::NumberHelper
# Many controller actions missing...
def new
@customer = Customer.new
user = @customer.build_user
end
<!DOCTYPE html>
<html>
<head>
<title>Tab Components in Vue</title>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
<script type="text/javascript" src="https://unpkg.com/vue@2.5.9/dist/vue.js"></script>
<!DOCTYPE html>
<html>
<head>
<title>Vue.js Demos</title>
<script type="text/javascript" src="https://unpkg.com/vue@2.5.9/dist/vue.js"></script>
@profh
profh / symbols.rb
Created February 8, 2018 02:16
Understanding Ruby Symbols
# Simple method format purposes
def brk
puts "============================"
end
# Finding all symbols and symbol methods that Ruby already knows:
symbols = Symbol.all_symbols.sort{|x,y| x.to_s <=> y.to_s }
symbols.each { |x| print x.to_s + "\t" }
brk
@profh
profh / book_manager_example.ex
Created June 8, 2016 15:33
Using iex with BookManager app
### Stepping through class example on BookManager
# Import Ecto.Query first, or none of this works in iex:
import Ecto.Query
# A simple example
query = from BookManager.Book
BookManager.Repo.all(query)
# Creating aliases because BookManager is just to long to keep rewriting: