Skip to content

Instantly share code, notes, and snippets.

View chadjemmett's full-sized avatar

Chad Jemmett chadjemmett

View GitHub Profile
<%= $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'>
def string_thing(string)
holding_array = []
unless string.empty?
holding_array << String.new(string.slice! (0..249))
end
return holding_array
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.
@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 / 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
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="click.js"></script>
</head>
<body>
<h1>This should do something!!</h1>
</body>
@chadjemmett
chadjemmett / click.coffee
Created January 3, 2014 21:50
basic coffeescript file
$('h1').click ->
alert("You clicked this")
@chadjemmett
chadjemmett / csv_to_db.rb
Created October 26, 2013 19:19
So this will get csv data into a rails database. I just did it from the console. But you could make it a rake task. the headers in the csv file have to match the model attributes attr_accessor variables.
require 'csv'
CSV.foreach(filename, :headers => true) do |row|
Pokemon.create!(row.to_hash)
end
@chadjemmett
chadjemmett / _error_messages.html.erb
Created October 20, 2013 01:35
Shared error messages for ruby on rails. Replace @user with relevant variable. Also change the css classes and such to match the app you use it on.
<% if @user.errors.any? %>
<div id="error_explanation" >
<div class="alert alert-error">
The form contains <%= pluralize(@user.errors.count, "error") %>.
</div>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li></br>
<% end %>
</ul>
@chadjemmett
chadjemmett / string_puzzle.rb
Created September 18, 2013 00:08
A string generator for a programming challenge.
array = []
random_number = rand(5) + 5
string = ""
walls_and_halls = ["W", "."]
(random_number * random_number + 1).times { string << walls_and_halls.sample }
string = string.chop!