Skip to content

Instantly share code, notes, and snippets.

View jamesdabbs's full-sized avatar

James Dabbs jamesdabbs

View GitHub Profile
@jamesdabbs
jamesdabbs / ARGV and dispatch.md
Created February 16, 2015 23:59
A quick note answering a question about dispatching from ARGV

In working on her command line todo manager, Katie asked a good question about being able to use a NoMethodError. NoMethodError specifically applies to trying to call methods on an object and there isn't (an obvious) one here, but I wanted to suggest an idea. Notice that you probably have a big long where statement where each case is just "do the thing that the user typed in with whatever arguments they supplied". Here's one potential way to simplify that:

class Dispatcher
  def add
    ...
  end
  def list
    ...
 end

Hello gist!

@jamesdabbs
jamesdabbs / curl.rb
Created February 17, 2015 17:57
A (deliberately not-so-great) example of making HTTP request from Ruby using curl
require 'json'
require 'pry'
url = "https://api.github.com/orgs/TIY-DC-ROR-2015-Jan/repos"
response = `curl #{url}`
data = JSON.parse response
# Try poking around here and taking a look at `data`
# binding.pry
@jamesdabbs
jamesdabbs / git_hooks.md
Created February 18, 2015 20:28
Quick reference on some useful git hooks.
@jamesdabbs
jamesdabbs / heroku_scan.rb
Created March 3, 2015 18:23
Use the Heroku Platform API to find an app by config variable (namely `MANDRILL_USERNAME`)
require 'httparty'
require 'pry'
ADDRESS = "app15863835@heroku.com"
class Heroku
include HTTParty
base_uri "https://api.heroku.com"
def self.get_token
#!/usr/bin/env ruby
def s n
Math.sqrt n
end
approxes = [
"3",
"s(7 + s(6 + s(5)))",
"(63 * (17 + 15 * s(5))) / (25 * (7 + 15 * s(5)))",
@jamesdabbs
jamesdabbs / mic_check.rb
Created March 28, 2015 19:31
Checks that your system is set up and ready to learn
#!/usr/bin/ruby
# ^- tells the shell to run this script using _system_ ruby
#
# To use, either copy this file or save its contents into a new file
# (named e.g. `mic_check.rb`), and then run
# $ chmod +x ./mic_check.rb
# $ ./mic_check.rb
#
# Checks your system to ensure that it's setup as expected:
# * has developer tools, brew, a recent git and an editor
@jamesdabbs
jamesdabbs / rcc-resources.md
Created May 15, 2015 13:26
Rails crash course - Resources
@jamesdabbs
jamesdabbs / models.py
Created June 25, 2012 05:11
A simple example of dynamic models in Django
from django.db import models
def get_column_attrs(width):
""" Creates the specified number of fields and adds them to a dict,
suitable to be used as a model's attrs
"""
attrs = dict(
('col_{}'.format(i), models.IntegerField(default=1))
for i in range(0, width)
@jamesdabbs
jamesdabbs / dbpull.py
Created July 2, 2012 15:33
A custom django-admin command to replace Heroku's db:pull command
from optparse import make_option
import os
import subprocess
import urllib2
from django.conf import settings
from django.core.management.base import BaseCommand
class Command(BaseCommand):