Skip to content

Instantly share code, notes, and snippets.

# Expected output:
# YOU ARE x YEARS OLD IN DOG YEARS
# Calculate dog years:
# 1 dog year = 7 human years
puts "Hello there, what's your age?"
user_age = gets
dog_years = user_age.to_i * 7
output_string = "you are #{dog_years} years old in dog years"
@kylekeesling
kylekeesling / pets.rb
Last active November 6, 2015 15:41
Example of a Complex Array of Hashes and how to use Enumerable methods on it
$pets = []
$pets << {
:name => 'Lallo',
:nocturnal => false,
:breed => 'Schnauzer',
:talents => ['napping', 'rolling over', 'playing dead'],
:legs => 4
}
$pets << {
(1..1000).each do |number|
if number % 7 == 0
puts "#{number} is divisible by 7"
end
end
@kylekeesling
kylekeesling / bootstrap-responsive-btn-group.scss
Last active August 29, 2015 14:27
Bootstrap 3 Responsive Button Group
@media (max-width: $screen-xs-max) {
.btn-group-responsive {
width: 100%;
margin-bottom: 10px;
.pull-left, .pull-right { float: none; }
.btn {
border-radius: $btn-border-radius-small !important;
display: block;
width: 100%;
padding-right: 0;
@kylekeesling
kylekeesling / keybase.md
Created August 14, 2014 16:00
keybase.md

Keybase proof

I hereby claim:

  • I am kylekeesling on github.
  • I am kylekeesling (https://keybase.io/kylekeesling) on keybase.
  • I have a public key whose fingerprint is 4011 27E5 ADB2 5CC7 FC50 FF9C D906 21B5 5F82 D202

To claim this, I am signing this object:

@kylekeesling
kylekeesling / kkees.plugin.zsh
Created November 15, 2013 17:32
An oh-my-zsh plugin that creates a terminal command to quickly get your rails project updated and ready to code. Assumes you're using Rails, git and Sublime Text. Also assumes your apps are stored in '~/sites', should be able to tweak this a little if your environment is a little different. Is really great if you use multiple machines for develo…
start_working() { cd ~/sites/$1; git pull; bundle install; rake db:migrate; subl .; }
@kylekeesling
kylekeesling / kyles_super_cool_pdf.rb
Created November 15, 2013 03:07
How to Generate a Prawn PDF class with a repeating footer
class KylesSuperCoolPdf < Prawn::Document
def initialize
super()
repeat :all do
#Create a bounding box and move it up 18 units from the bottom boundry of the page
bounding_box [bounds.left, bounds.bottom + 18], width: bounds.width do
text "Probably the Best Footer Ever", size: 8, align: :center
end
@kylekeesling
kylekeesling / paginator.html
Created October 31, 2013 12:35
Simple Jekyll Paginator Logic I didn't like the pagination logic provided in the Jekyll Docs (http://jekyllrb.com/docs/pagination/) since it repeated the HTML for displaying the button, so I came up w/ this. It stores the proper previous page path into a liquid variable then plops it into the HREF so you only have to code your button once
{% if paginator.previous_page %}
{% if paginator.previous_page == 1 %}
{% capture previous_page %}/{% endcapture %}
{% else %}
{% capture previous_page %}/page{{ paginator.previous_page }}{% endcapture %}
{% endif %}
<a href="{{ previous_page }}" class="previous">&larr; Newer Posts</a>
{% endif %}
{% if paginator.next_page %}
@kylekeesling
kylekeesling / geo-target.sql
Created February 21, 2013 17:03
GeoTargeting SQL for 15km Radius of Zip Code 46254
SELECT
myData.*,
ROUND(6378.137 * ACOS(
CASE
WHEN (SIN(RADIANS((SELECT latitude FROM [Zip Codes and Locations] where [Zip Code] = 46254))) * SIN(RADIANS(geo.Latitude))) + (COS(RADIANS((SELECT latitude FROM [Zip Codes and Locations] where [Zip Code] = 46254))) * COS(RADIANS(geo.Latitude)) * COS(RADIANS(geo.Longitude) - RADIANS((SELECT longitude FROM [Zip Codes and Locations] where [Zip Code] = 46254)))) > 1 THEN 1
WHEN (SIN(RADIANS((SELECT latitude FROM [Zip Codes and Locations] where [Zip Code] = 46254))) * SIN(RADIANS(geo.Latitude))) + (COS(RADIANS((SELECT latitude FROM [Zip Codes and Locations] where [Zip Code] = 46254))) * COS(RADIANS(geo.Latitude)) * COS(RADIANS(geo.Longitude) - RADIANS((SELECT longitude FROM [Zip Codes and Locations] where [Zip Code] = 46254)))) < -1 THEN -1
ELSE (SIN(RADIANS((SELECT latitude FROM [Zip Codes and Locations] where [Zip Code] = 46254))) * SIN(RADIANS(geo.Latitude))) + (COS(RADIANS((SELECT latitude FROM [Zip Codes and Locations] where [Zip Code] = 4
@kylekeesling
kylekeesling / example.html
Created January 18, 2013 19:50
How to use the jQuery Cookie plugin
<!doctype html>
<html>
<head>
<title>Example</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<!-- Available here: https://github.com/carhartl/jquery-cookie -->
<script src="jquery.cookie.js"></script>
</head>
<body>
<script>