Skip to content

Instantly share code, notes, and snippets.

View craigmartin's full-sized avatar

Craig Martin craigmartin

  • Glee Machine, LLC.
  • Portland OR
View GitHub Profile
# In Ruby...
#
# 1) Sum up 1 to 100
# sum = (1..100).inject(0){|cummulative,n| cummulative+n}
# puts sum
#
# 2) Using TestUnit, test #1
# Please see this Gist: git://gist.github.com/1120032.git
#
# 3) What's the difference between including a module & extending a module?
@craigmartin
craigmartin / alphabetpie.rb
Created August 2, 2011 19:17
#9. Given the alphabet, print letter 1 is a, letter 2 is b .. (used print for producing results as requested.)
short_enum = (1..26).to_enum
long_enum = ('a'..'z').to_enum
loop do
print "letter #{short_enum.next} is #{long_enum.next}, "
end
@craigmartin
craigmartin / alphabetpie_eachline.rb
Created August 2, 2011 19:14
Given the alphabet, print out letter 1 is a, letter 2 is b ..
short_enum = (1..26).to_enum
long_enum = ('a'..'z').to_enum
loop do
puts "letter #{short_enum.next} is #{long_enum.next}"
end
@craigmartin
craigmartin / href_preventDefault.html
Created August 2, 2011 12:12
solution to question #6 - pre-plugin
<!DOCTYPE html>
<html>
<head>
<style>p { background:yellow; margin:6px 0; } p.off { background: black; }</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<p>Hello!</p>
Good to see you.
<p>Want to try some links?</p><br><br>
@craigmartin
craigmartin / sum1to100.rb
Created August 2, 2011 11:37
answer to #1
sum = (1..100).inject(0){|cummulative,n| cummulative+n}
puts sum
@craigmartin
craigmartin / math_tester.rb
Created August 2, 2011 11:34
Test/Unit for sum 1to100 program
require 'test/unit'
class MathTester < Test::Unit::TestCase
def test_addition
assert_equal( 3, 1+2 )
assert_equal( 5, 2+3 )
end
def test_subtraction
@craigmartin
craigmartin / network.js
Created August 2, 2011 11:21
A jQuery plugin for social network links or any other links .. (as used for Van Specialties)
(function ($) {
var script, css, html, offset, options;
script = $('script[src$="network.js"]');
// Set options.
options = {
style: 'dark'
};
if (script.data('style')) {
@craigmartin
craigmartin / gist:1114742
Created July 29, 2011 21:08
blocks/Procs/lambdas/and Methods -my view
* Blocks are simply Procs that can not be saved.
* Blocks should be used as a one-time solution. If 2 or more closures are being passed, use a Proc.
Use case examples:
1.) Block: method is breaking an object down into smaller pieces, and I want to let my users interact with these pieces.
2.) Block: I want to run multiple expressions atomically, eg: a database migration.
3.) Proc: I want to reuse a block of code multiple times.
@craigmartin
craigmartin / current user.rb
Created April 1, 2011 21:16
this is the current user.rb -- changed unless @user.update_or_create to unless User.update_or_create
get "/user/profile" do
haml :profile
end
get "/user/profile/change" do
haml :change_profile
end
post "/user/profile" do
# unless @user.create(:nickname => params[:nickname],
@craigmartin
craigmartin / current app file
Created April 1, 2011 21:14
monsoc.rb - (app file) with @user.update_or_create changed to User.update_or_create
require 'rubygems'
#require 'ruby-debug'; debugger;
gem 'rest-client', '=1.6.1'
%w(./config haml sinatra digest/md5 rack rack-flash json rest-client ./models).each { |lib| require lib}
set :sessions, true
set :show_exceptions, true
set :environment, :development
use Rack::Flash
get "/" do