Skip to content

Instantly share code, notes, and snippets.

@jonpaul
jonpaul / test.rb
Last active December 15, 2015 10:29
inheritance!
module Mde
def match_for_mde(mde, arclass_id, arclass_filename)
rule = Parser.new(mde)
es_query = Bar.new(rule, arclass_id, arclass_filename).es_query
rest_call_for_truth(es_query)
end
def rest_call_for_truth(query)
@jonpaul
jonpaul / errors.go
Last active December 15, 2015 04:49
Go Tour Exercises
package main
import (
"fmt"
"math"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
@jonpaul
jonpaul / gist:5092383
Created March 5, 2013 17:52
MapperParsingException[mapping [analysis]]; nested: ClassCastException[java.lang.String cannot be cast to java.util.Map]
a node "properties" cannot contain the name/value setting of "dynamic":"true"
Never.
@jonpaul
jonpaul / spec.rb
Created October 16, 2012 13:18
from article sourcefile
describe "GET profile" do
let(:player) { Dish::Player.new('simplebits') }
before do
VCR.insert_cassette 'base', :record => :new_episodes
end
after do
VCR.eject_cassette
@jonpaul
jonpaul / secure_rails
Created September 14, 2012 19:07
SSL webrick
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
require 'rails/commands/server'
require 'rack'
require 'webrick'
require 'webrick/https'
module Rails
class Server < ::Rack::Server
def default_options
var A, E, J, M, WS, async, duc, e, ejs, euc, fs, haml, http, mime, n, qs, url, w, _ref, _ref1;
_ref = [
JSON, Math, decodeURIComponent, encodeURIComponent, (function(p) {
return p.replace(/\/*$/, '').replace(/^\/?/, '/');
}), (function(d, s) {
var k, v;
for (k in s) {
v = s[k];
d[k] = (d[k] instanceof Array ? d[k].concat(v) : v);
@jonpaul
jonpaul / example.rb
Created July 30, 2012 18:54
sr3 permalinks as attachments
# gets permalink for file on s3
#
# *Parameters:*
# (+String+) -- aws_path full path of key to be uploaded to AWS (usually generated)
#
# *Returns:*
# (+String+) -- url
def self.get_permalink(aws_path, content_type = nil, content_disposition = nil)
return nil if aws_path.blank?
s3 = AWS::S3.new
@jonpaul
jonpaul / resque.rb
Created July 26, 2012 19:54
resque initializer
Resque.redis = Redis.new(:host => APP_CONFIG[:redis], :port => APP_CONFIG[:redis_port])
Dir["#{Rails.root}/app/workers/*.rb"].each { |file| require file }
require 'resque/failure/multiple'
require 'resque/failure/redis'
@jonpaul
jonpaul / backbone_sync.js
Created July 24, 2012 19:14
Rewriting backbone.sync for rails CSRF
(function($) {
var methodMap = {
'create': 'POST',
'update': 'PUT',
'delete': 'DELETE',
'read' : 'GET'
};
var getUrl = function(object) {
if (!(object && object.url)) return null;
@jonpaul
jonpaul / registrations_controller.rb
Created July 24, 2012 19:08 — forked from jwo/registrations_controller.rb
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else