Skip to content

Instantly share code, notes, and snippets.

View chadjemmett's full-sized avatar

Chad Jemmett chadjemmett

View GitHub Profile
@chadjemmett
chadjemmett / card deck method
Last active January 2, 2016 04:39
Making a card deck.
def new_deck
all_cards = {}
[:hearts, :diamonds, :clubs, :spades].each {|suit| all_cards[suit] = (1..13).to_a.shuffle!}
return all_cards
end
@chadjemmett
chadjemmett / Deal cards
Created January 4, 2014 04:27
Deal cards method The @all_cards is an instance variable of a hash. Outside of the method.
def deal_cards
suit = [:hearts, :diamonds, :clubs, :spades]
return @all_cards[suit.sample].pop
end
@chadjemmett
chadjemmett / fourtune_random.rb
Created January 5, 2014 02:18
Added/changed features to a fortune telling program
#fake animated status bar.
def sleep_dots(seconds)
seconds.times do
print "."
sleep(1)
end
return " "
end
#the response arrays.
def string_thing(string)
holding_array = []
unless string.empty?
holding_array << String.new(string.slice! (0..249))
end
return holding_array
end
<%= $thing %>
<form action='/thing1' method='post' >
<input type='hidden' name='_method' value='put'>
<input type='submit' value='Upvote'>
<form action='/thing2' method='post' >
<input type='hidden' name='_method' value='put'>
<input type='submit' value='Downvote'>
require 'sinatra'
#this is the number that goes up or down in value
$thing = 1
#this gets the index page
#
get "/" do
erb :index
#the link to this gist code => https://gist.github.com/ceejaay/801c2e5de59710b1a402#file-index-erb
end
<ul>
<%= @list_of_names.each do |name| %>
<form action="/save_the_names" method="post">
<li><%= name %></li><input type="checkbox" name="name_i_want_to_save"
<% end %>
<input type="submit">
</form>
</ul>
require 'gosu'
TICKS_PER_JUMP = 50
FONT_COLOR = 0xff_ffff00
class GameWindow < Gosu::Window
def initialize
super 640, 480
self.caption = "Runner"
@floor = [Floor.new(50, 400), Floor.new(350, 400), Floor.new(650, 400)]
@player = Player.new(75, 200)
#for ruby gosu
def collision?(barrier_x, barrier_y)
(barrier_x.between?(@x - 50, @x) and barrier_y.between?(@y, @y + 50)) || (barrier_x.between?(@x, @x + 50) && barrier_y.between?(@y - 50, @y)) || (barrier_x.between?(@x - 50, @x) && barrier_y.between?(@y - 50, @y)) || (barrier_x.between?(@x, @x + 50) && barrier_y.between?(@y, @y + 50))
end
require 'gosu'
FONT_COLOR = 0xff_ffff00
class SpaceInvader < Gosu::Window
def initialize
super 640, 480
self.caption = "Space Invaders"
@message = Gosu::Font.new(20)
coordinate_array = []
i = 0