This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_model' | |
class ActiveCouchModel | |
extend ActiveModel::Callbacks | |
include ActiveModel::Conversion | |
include ActiveModel::Naming | |
include ActiveModel::Validations | |
define_model_callbacks :save, :create | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nmatrix/nmatrix' | |
class NMatrix | |
def standardize_columns! | |
cols.times do |i| | |
col = self[0..-1,i] | |
self[0..-1,i] = (col - col.mean[0]) / col.std[0] | |
end | |
self | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addParams = (path, params) -> | |
query = objToQuery(params) | |
joinChar = if /\?/.test(path) then '&' else '?' | |
"#{path}#{joinChar}#{query}" | |
objToQuery = (obj) -> | |
pairs = [] | |
for own key, val of obj | |
if val? and val != '' | |
val = encodeURIComponent(val) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'google_places' | |
api_key = 'key' | |
# Actually executing stubbed-out spec "should request spots by bounds" from client_spec.rb | |
# Supplying a bounding box to a text search query does not seem to work, nor is this feature documented: | |
# https://developers.google.com/places/web-service/search#TextSearchRequests | |
query = 'pizza' | |
# Bounds is around city of Nashville TN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple global PubSub system built around $.Callbacks | |
# Enables PubSub without relying on DOM element bindings | |
# | |
# Usage: | |
# | |
# PubSub.subscribe 'foo', (message) -> console.log("Received: #{message}") | |
# PubSub.publish 'foo', 'bar' | |
# # Outputs: "Received: bar" | |
$(document).on 'ready', () -> | |
window.PubSub = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Rails commands multi-process demo | |
# | |
# For use with https://github.com/rails/commands | |
# | |
# Put this file in an app in script/superconsole (or whatever name) and chmod +x | |
# or just put this in lib/superconsole.rb. | |
# | |
# This script opens the console in the development env, and forks a child process |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Positioned | |
extend ActiveSupport::Concern | |
included do | |
before_save :set_position, unless: :position | |
end | |
module ClassMethods | |
def positioned | |
order(:position, :id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Helper to set HTTP Basic Auth in functional/controller tests | |
# Put this in test/test_helper.rb: | |
class ActionController::TestCase | |
def login_via_http_basic_auth username, password | |
@request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(username, password) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Processing Test</title> | |
<script type="text/javascript" src="http://cloud.github.com/downloads/processing-js/processing-js/processing-1.4.1.js"></script> | |
</head> | |
<body> | |
<canvas id="mysketch" data-processing-sources="sketch.pde"></canvas> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Middleware to tap into request so that you can provide an alternate response depending upon request conditions. | |
# | |
# Supplied block should return a Rack-compatible response, or nil/false to pass on handling of the request. | |
# | |
# Example: | |
# | |
# use Rack::Tap do |env| | |
# if Rack::Request.new(env).host == 'admin.myapp.com' | |
# [301, {'Location' => 'http://www.myapp.com/admin'}, []] | |
# end |