Skip to content

Instantly share code, notes, and snippets.

View pwightman's full-sized avatar

Parker Wightman pwightman

View GitHub Profile
def UsersController
before_filter :get_user, only: [:show, :update]
def show
# You can use the @user variable here...
end
def update
# You can use the @user variable here...
end
@pwightman
pwightman / ruby_example.rb
Last active December 11, 2015 11:08
Some Ruby basics, given you have some experience with Java or similar.
# Declaring a class. You can subclass using: < SuperClass
class Fraction # < Foo
# Defines getters/setters
attr_accessor :numerator, :denominator
# Constructor
def initialize num, denom
# @ means it's an instance variable. Instance variables
# exist as soon as you use them. If you try to use an instance
# variable that doesn't yet exist, it just returns nil.
@pwightman
pwightman / map.rkt
Last active December 10, 2015 22:08
My first attempt at Racket.
; List comprehension version, more Racket-esque, I'm told.
(define (mymap lam l) ; lam is a lambda (see bottom) and l a list
(for/list ([i l]) ; i is given element for the iteration, l the list
(lam i))) ; The expression to be evaluated on each iteration
; From scratch (kind of). Recursively creates a list of the results of calling
; a lambda on each element
(define (mymap lam l) ; Define a function that takes a lambda and a list.
(if (empty? l) ; Base case, if the list is empty:
empty ; return an empty list
@pwightman
pwightman / jobject.rb
Last active December 10, 2015 15:38
method_missing example of accessing hashes like native objects.
class JObject
def initialize hash
@hash = hash
end
def method_missing(m, *args, &block)
m = m.to_s
if m.end_with?("=")
m = m[0, m.length - 1]
@hash[m] = args.first
@pwightman
pwightman / rbenv.md
Last active December 19, 2017 06:52
rbenv, faster Ruby, and Zeus.

RVM, which is a rather heavy-weight solution to gem conflicts, has been chafing on me so here's a tutorial on getting going with rbenv instead, which just manages Ruby and leaves gem version dependencies to Bundler.

NOTE: Just because I'm switching, doesn't mean rbenv is necessarily "better" than RVM. I'm often switching between technologies to try them out and I could end up hating rbenv in a month (though I don't anticipate it). RVM is still a fine piece of work and you'll get along with it just fine.

Deleting RVM

If you have RVM installed, you can delete it easily with:

rvm implode
@pwightman
pwightman / login.md
Created November 12, 2012 20:18
Logging into TA Queue

Get token

httparty -a post \
-H Accept:application/json -H Content-Type:application/json \
-d '{ "student": { "username":"mike liu", "location":"home" } }' \
"http://nine.eng.utah.edu/schools/uofu/eparker/CS1400/students"

Sample response:

@pwightman
pwightman / httparty.md
Created November 8, 2012 02:38
HTTParty usage

This is a much simpler HTTP library called HTTParty. The standard library that comes with Ruby is quite verbose, you have to convert a string to a URL, specify URLs and ports and all sorts of longwinded stuff. This is much easier. There's both a command line interface, if you just want to test things out for the queue at the command line, for example, as well as a ruby library. I'll show both here. You can install it with gem install httparty.

Command-line usage:

httparty -H Accept:application/json "http://nine.eng.utah.edu/schools"

# Accepts JSON, uses POST instead of GET, and does BASIC authentcation, which the queue requires
# once you've logged in. I can show you that later.
httparty -H Accept:application/json -a post -u username:password "http://nine.eng.utah.edu/schools"

IRC for URails

IRC is sort of like a free chat room. Anyone can host their own IRC server and people can connect to it, join "channels", etc. It's often used as a place users can find help with others that have their same common interest. For example, there's a server called "freenode" which is quite popular and has rooms for rails, ruby, python, and most anything you can think of.

Jeff Sandberg, a Rails Veteran who has decided to help out the group, helped set up an IRC server called snoonet that we'll be using for a URails channel that Jeff and I will usually be in when we're at our computers, where you can ask any Rails-related questions and where we can collaborate when we're working on URails stuff at the same time. This will be much easier than the mailing list or email.

IRC Client

Mac

@pwightman
pwightman / funny_java.java
Created October 4, 2012 21:05
Some straight-up funny Java code.
// This was someone's real java code in production (names changed),
// I'm not making this crap up.
class SomeClass {
public void someMethod() {
if (some_condition) {
try {
throw new Exception();
} catch(Exception e) {
System.out.println(e.message());
@pwightman
pwightman / rvm_directions.md
Created September 18, 2012 04:11
Installing RVM and Rails

Install Ubuntu on Windows

Mac OSX/Ubuntu users can skip this section. If you're running Windows, follow these instructions to install Ubuntu inside a virtual machine.

  • Download and install VirtualBox from here
  • Download this Ubuntu ISO file (Note that this is 64-bit, if you don't have a 64-bit machine then you'll want to do the 32-bit version
  • Start up VirtualBox and create a new virtual machine for Ubuntu (just follow default options on each screen if you aren't sure what to do. I recommend doing a 40GB hard drive. It won't actually consume that much, it allocates space as it needs it.)
  • Once the virtual machine is created, click on the VM you just created in the list of VMs and click the Settings button
  • In the Storage section, add an IDE controller that points to the .iso file you just down