Skip to content

Instantly share code, notes, and snippets.

View pjb3's full-sized avatar

Paul Barry pjb3

View GitHub Profile
@pjb3
pjb3 / app.jsx
Last active August 29, 2015 14:22
BEWD Spring 2015 Class 4 Homework - React + LocalStorage Notes App
var NoteEditor = React.createClass({
getInitialState: function() {
return {
content: this.props.note.content
}
},
handleChange: function(event) {
this.setState({ content: event.target.value });
},
@pjb3
pjb3 / app.js
Created May 21, 2015 00:59
In-class work Web, May 20
$(function(){
$("form").on( "submit", function(event) {
console.log('email:', $('[type=email]').val());
return false;
});
})
@pjb3
pjb3 / terminator.sql
Created March 25, 2015 02:14
Kill all queries that have been running for more than a minute in a Postgres datavase
select pg_terminate_backend(pid)
from (
SELECT
pid
FROM pg_stat_activity
WHERE query <> '<insufficient privilege>'
AND state <> 'idle'
AND pid <> pg_backend_pid()
AND query_start < now() - interval '1 minute'
ORDER BY query_start DESC) t;

Object-Oriented Order Calculator

In this assignment we will be creating an object-oriented order total price calculator. Your branch already has a failing test, your job is to make it pass. You will not need to make changes to the test file, but feel free to add more tests to the test file if it can help you in developing the code. Create a new file named 'order.rb' and put your code in there.

To do this, you will need to make 3 classes.

  1. Product

    The product class needs to have name and price accessors and a constructor to allow you to set those values. If you aren't sure how to do this, refer to the slides on the flexible initializer

@pjb3
pjb3 / README.md
Last active August 29, 2015 14:06

Assignment for Ruby Basics

Implement the calculate_total method so that the tests pass. The method should accept an order represented as an Array of Hashes and calculate the total cost of the order. Each Hash should represent a line item of the order with a key for the quantity and a key for the unit price of the item. After calculating the total of the order and additional tax rate of 5% should be added. The return value should be a string, the total formatted as a price with 2 decimal points and a dollar sign, such as $1.99.

Hints

# Enable bash completion for rbenv commands
source ~/.rbenv/completions/rbenv.bash
__rbenv_ps1 ()
{
rbenv_ruby_version=`rbenv version | sed -e 's/ .*//'`
printf $rbenv_ruby_version
}
# Enable bash completion for git commands/branches
source /usr/local/etc/bash_completion
Muffin 2.99
Coffee 3.75
Smoothie 3.99
@pjb3
pjb3 / gist:11272968
Created April 24, 2014 23:26
How link to works
<%= link_to "Text", "/link" %>
<a href="/link">Text</a>
<%= link_to "Text", product_path(product) %>
<a href="/products/1">Text</a>
<% link_to "<span class='icon'>Text</span>", '/link' %>
<a href="/products/1">
<span class='icon'>Text</span>
</a>
@pjb3
pjb3 / georelocate.coffee
Created April 2, 2014 15:28
How to fake your location in a browser
@navigator.geolocation.watchPosition = (callback) ->
setInterval(->
callback
coords:
latitude: 39.286031201326416,
longitude: -76.61204230156727
, 5000)
@pjb3
pjb3 / .irbrc
Last active February 19, 2016 14:13
Basic Ruby IRB config
require 'irb/completion'
# History
#require 'irb/ext/save-history' #wirble does history
IRB.conf[:PROMPT_MODE] = :SIMPLE
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
IRB.conf[:AUTO_INDENT] = true
# use HIRB if available