Skip to content

Instantly share code, notes, and snippets.

View amorphid's full-sized avatar

Michael Pope amorphid

  • Digital Turbine
  • San Francisco, CA
View GitHub Profile
@amorphid
amorphid / gist:5356720
Created April 10, 2013 17:34
Basic way to calculate length of a string
# breaks if string includes a 0
def string_length(a)
string = a + "0"
length = 0
while string[length] != "0"
length += 1
end
puts "Your statement is #{length} characters long"
@amorphid
amorphid / gist:5368246
Created April 12, 2013 00:12
String class w/ length and reverse
class String
def how_long_am_i?
length = 0
while self[length] != nil
length += 1
end
length
end
# your local variables
first_card = 11
second_card = 13
# The "card" variable can only be seen within the method
def check_face_card(card) # removed the space
if card == 11 || card == 12 || card == 13
card = 10
else
end
@amorphid
amorphid / gist:6322728
Last active December 21, 2015 14:49
From blog entry "Displaying formatted HTML in Rails"
<img src="http://i.imgur.com/v7q2NBN.jpg" title="Hosted by
imgur.com" height="350" width="350" style="float:left;margin: 0px 30px 30px 0px;" />
<h1 style="margin: 0px 0px 30px 0px;">Displaying formatted HTML in Rails</h1>
<h2 style="margin: 0px 0px 30px 0px;">The problem</h2>
<p style="margin: 0px 0px 30px 0px;">Third party blogging platforms drive me bonkers. <a href="http://en.wikipedia.org/wiki/Tumblr" target="_blank">Tumblr</a> requires you to be a CSS wizard in order to customize anything. <a href="http://en.wikipedia.org/wiki/Blogger_(service)" target="_blank">Blogger</a> is pretty good, it still hosts my old <a href="http://captainrecruiter.blogspot.com" target="_blank">Captain Recruiter blog</a>, but it's not designed to be anything more than a standalone blog and I don't like that limitation. After a few attempts to use it, I still don't understand <a href="http://en.wikipedia.org/wiki/Wordpress" target="_blank">Wordpress</a>. So given my I-want-a-blog-built-just-for-me itch, I decided to wri
# from controller
respond_to do |format|
format.html { redirect_to :back }
format.json { render json: @voteable.score } # score is an integer
end
# from application.js
$(document).ready(function() {
<h1>Posts</h1>
<ul class="posts">
<% @posts.each do |post| %>
<li>
<%= link_to "", post_votes_path(post, value: 1), class: "icon-chevron-up upvote-" %>
<br />
<span class="score">
<%= post.score %>
</span>
class Foo
attr_reader :bar
def initialize(args = {})
@bar = args.fetch(:bar)
unless bar.nil?
do_something
do_something_else
end
/usr/local/bin # put me at the top!
/usr/bin
/bin
/usr/sbin
/sbin
development:
adapter: postgresql
encoding: unicode
database: eliostrom_development
pool: 5
username: amorphid
password:
test:
adapter: postgresql
@amorphid
amorphid / 2014-11-26-i-left-my-pants-in-san-francisco.md
Last active August 29, 2015 14:10
I Left My Pants In San Franciso

November 26, 2014

Goodbye San Francisco. I've been with you over 10 years, and now I am leaving. During our time together, I have, in no particular order:

  • worked as a life insurance agent
  • suffered 2 broken arms in a bicycle accident
  • started a an insurance business
  • closed an insurance business
  • started a technical recruiting business
  • sold a technical recruiting business