Skip to content

Instantly share code, notes, and snippets.

class Student
attr_accessor :name, :photo_url, :section, :twitter
def introduce
return " <li>
<img src='#{self.photo_url}'>
<h3><a href='https://twitter.com/#{self.twitter}'>#{self.name}</a></h3>
</li>"
end
end
require 'open-uri'
require 'json'
require './student.rb'
url = "http://yearbook-api.herokuapp.com/2013/Spring/36.json"
raw_response_string = open(url).read
ruby_response_object = JSON.parse(raw_response_string)
list_from_api = ruby_response_object["students"]
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
@raghubetina
raghubetina / list_tag.rb
Created May 25, 2013 22:31
A simple typeahead input tag
module ApplicationHelper
def list_tag(name, *args)
options = args.extract_options!.merge(name: name, list: name)
input_tag = tag :input, options
datalist_tag = content_tag :datalist, nil, id: name do
args[0].collect do |value|
tag :option, value: value
end.join.html_safe
end
@raghubetina
raghubetina / person.rb
Created July 16, 2014 13:58
Day 10 Warmup
# The following line will pull Rails' enhancements of Ruby's Date class into
# this script.
# You will then be able to use methods like Date.today, which returns an object
# representing today.
# You can also do things like Date.parse("1809-02-12") and it will return an
# object representing that date.
# You can then subtract one from the other to find the number of days between.
require 'active_support/core_ext/date/calculations'
class Person < Primate
@raghubetina
raghubetina / sublime.md
Last active April 26, 2017 15:38
Sublime Setup Guide

One-Time Sublime Configuration

We are going to be writing all of our code using the plain text editor Sublime Text 3. In this guide, you will customize your installation with shortcuts and other things in order to make your life easier.

What follows may seem opaque, but don't worry about it -- we just need to go through this process once, and then we'll be all set for the quarter. You aren't expected to understand exactly how it is all working right now.

Installation

Download Sublime Text 3 (not 2) for your platform of choice [here][1], and install it (locate and double-click the file you just downloaded).

@raghubetina
raghubetina / installing_rails.md
Last active November 15, 2018 18:34
Installing Ruby and Rails

Installing Ruby and Rails

Ruby is a wonderfully simple language, and Rails is an astonishingly powerful framework. Unfortunately, installing them can sometimes be the hardest part of learning to code.

In this guide I will lay out the least error-prone method of installing that we've found. Hopefully you will have no issues and it will be smooth sailing.

In case you do run into an error, first try restarting your computer and then re-try the last step that you got stuck on. If that doesn't work, we'll fix it together.

If you can't install Ruby on your laptop for some reason (for example, it belongs to your employer and you are not allowed to install things), skip to here.

@raghubetina
raghubetina / homework_workflow.md
Created January 13, 2015 18:15
Homework Workflow

TLDR; Get Help, Don't Get Frustrated

Here's a general workflow that you ought to think about while doing homework:

  1. Read any instructions completely.
  2. Dive in; don't spend too much time planning. Break the problem into the smallest steps you can think of and get started on the first one.
  3. Code until you get stuck on something for at least 15 minutes.

What To Do When You Get Stuck

@raghubetina
raghubetina / terminal_prompt.md
Last active October 9, 2015 11:43
Customizing Your Terminal Prompt

Customizing Your Terminal Prompt

tl;dr

Run the following command from anywhere in Terminal:

echo PS1=\"\\w $ \" >> ~/.bash_profile
@raghubetina
raghubetina / crud_with_ruby.md
Last active March 4, 2019 14:36
CRUD with Ruby

CRUD with Ruby

Here is a quick reference on how to insert, retrieve, update, and delete rows from your database tables using our ActiveRecord-backed Ruby classes.

Adding Tables to the Database

First, we need a Ruby class to represent the real-world thing we're trying to model, and we need an underlying database table to store information about each individual thing.

Rails includes an easy generator to help us get set up with both of these things quickly. Supposed I wanted to create a table to store instructors, with two string columns first_name and last_name. I could use this shortcut from the Command Line: