Skip to content

Instantly share code, notes, and snippets.

@canweriotnow
canweriotnow / date.clj
Created February 10, 2012 21:51
wtf dates
(ns oraclj.util.date
(:import [java.sql Timestamp])
(:use [clojure.string]))
(defn gregorian-to-julian
[date-map]
(let [year (:year date-map)
month (:month date-map)
day (:day date-map)
hour (:hour date-map)
@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
@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 / 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

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.

#!/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.
@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() {
@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
# db/migrate/XXXXXXXXXXXXX_add_authentication_token_to_users.rb
class AddAuthenticationTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :authentication_token, :string
add_index :users, :authentication_token, :unique => true
end
end
App = new Marionette.Application();
App.addRegions {
"headerRegion": "#header"
"topMenuRegion": "#top-menu"
"mainRegion" : "#main"
}
App.on 'initialize:after', ->
Backbone.history.start()