Skip to content

Instantly share code, notes, and snippets.

@canweriotnow
canweriotnow / testes.rb
Created December 6, 2013 16:00
Quickie test server for testing things
require 'sinatra'
require 'json'
post '/good' do
content_type :json
[201, {message: "Successfully registered."}.to_json]
end
post '/bad' do
content_type :json
@canweriotnow
canweriotnow / sanderlingshare.html
Last active December 26, 2015 20:28
Share to Sanderling button
<span style="background-color:#A8BE38;display:inline-block;padding:4px;border-radius:5px;">
<a href="#" class="sanderling-share-button btn" onClick="sanderlingShare();" style="font-family: Helvetica, Arial, sans-serif;font-size: small;text-decoration: none; color: black;">
<div id="innerling">
<img src="https://s3.amazonaws.com/AnEstuary/brand/birdie-sm.png" width="20px"/>
Share on Sanderling
</div>
</a>
</span>
<script type="text/javascript">
var sanderlingShare = function() {
#!/usr/bin/env ruby
puts "How much IP do you have?"
ip_have = STDIN.gets.chomp #don't really need the STDIN
puts "Which champion do you want to buy?"
champion_want = STDIN.gets.chomp
lucian = #{lucian_value} #The #{} construct is for inside double-quoted strings, otherwise # just indicates a comment.
lucian_value = 6300
puts "#{champion_want} is #{champion_want} IP, so this means you need #{lucian_value} - #{ip_have}" #The math has to happen inside the #{} block... also, ip_have is read as a String, need to convert to an integer.

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

@canweriotnow
canweriotnow / tables.md
Created December 1, 2015 18:10
I would refute the claim...
Tables Are Cool
col 3 is right-aligned $1600
col 2 is centered $12
zebra stripes are neat $1
@canweriotnow
canweriotnow / xapi-lint.txt
Created November 30, 2015 21:20
xAPI Markdown Linter issues
xAPI.md:4: MD001 Header levels should only increment by one level at a time
xAPI.md:189: MD001 Header levels should only increment by one level at a time
xAPI.md:368: MD001 Header levels should only increment by one level at a time
xAPI.md:440: MD001 Header levels should only increment by one level at a time
xAPI.md:530: MD001 Header levels should only increment by one level at a time
xAPI.md:671: MD001 Header levels should only increment by one level at a time
xAPI.md:804: MD001 Header levels should only increment by one level at a time
xAPI.md:817: MD001 Header levels should only increment by one level at a time
xAPI.md:984: MD001 Header levels should only increment by one level at a time
xAPI.md:1109: MD001 Header levels should only increment by one level at a time
@canweriotnow
canweriotnow / unicorn
Created July 5, 2011 17:38
/etc/init.d script for unicorn
#!/bin/sh
#
# init.d script for single or multiple unicorn installations. Expects at least one .conf
# file in /etc/unicorn
#
# Modified by jay@gooby.org http://github.com/jaygooby
# based on http://gist.github.com/308216 by http://github.com/mguterl
#
## A sample /etc/unicorn/my_app.conf
##
@canweriotnow
canweriotnow / action_dispatch.rb
Created July 24, 2012 21:08
How to keep requests non-local
class ::ActionDispatch::Request
def local?
if Rails.env == 'production'
false
else
super
end
end
@canweriotnow
canweriotnow / Gemfile
Created July 24, 2012 18:33
Pieces of my app...
source 'http://rubygems.org'
gem 'rake', '0.8.7'
gem 'rails', '~> 3.0.7'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# New Relic monitoring
@canweriotnow
canweriotnow / gist:2492535
Created April 25, 2012 19:25 — forked from thommahoney/gist:2491946
RailsConf 2012 Lightning Talks
5 min:
~Objective-C + Rails:
Communicating w/rails from iOS/mac OS
Dan Hassin
1 min:
~Painless Javascript
koting hatduklgg
with wind tunnel