Skip to content

Instantly share code, notes, and snippets.

View JKring's full-sized avatar

jake kring JKring

View GitHub Profile
@JKring
JKring / route_specs.rb
Created February 13, 2014 02:09
magical route spec generator!
controllers = %x[ls app/controllers].split("\n").map { |c| c.gsub(".rb", "") }
controllers.each do |controller|
filename = "#{ Rails.root }/tmp/routing/#{ controller.gsub("controller", "routes_spec.rb") }"
%x[touch #{ filename }]
File.open(filename, 'w') do |f|
f.write("require 'spec_helper'\n\n")
methods = controller.classify.constantize.new.public_methods - ApplicationController.new.public_methods
f.write("describe 'routes for #{ controller.classify }' do\n\n")
methods.each do |m|
unless m.to_s.starts_with?("_one_time")
@JKring
JKring / docs.md
Created April 16, 2014 00:41
Newest Scripted API Docs
var params = {};
$.ajax({
type: "GET", url: "/cd000031/v1/job_templates",
data: params,
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Token token=pzZwPPATmAqsye9ZXbjS");
}
}).done(function(data){
console.dir(data);
});
@JKring
JKring / testing.js
Created August 17, 2014 03:17
moar testing
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.open("http://www.washingtonpost.com/gog/talk-to-us.html#submit-a-listing", function(status) {
if ( status === "success" ) {
page.includeJs("http://code.jquery.com/jquery-1.7.1.min.js", function() {
page.evaluate(function() {
@JKring
JKring / pricing.md
Last active August 29, 2015 14:09
New Pricing Docs

Going forward, Job and JobTemplate will including a pricing object.

Job Templates

The pricing object will include an integer for both base and specialist. The integer is in cents. For example, the response below indicates that Standard Blog Posts start at $99, and go up to $149 with a specialist.

[
  {
    "id": "52cdda648b588f7e020034d5",

"pricing": { "base": 9900, "specialist": 14900 },

@JKring
JKring / wat.rb
Created February 27, 2015 18:09
Ruby is weird
def do_something(str: this_is_not_defined_anywhere)
puts str
end
# Works fine
do_something(str: 'dogs')
# Obviously doesn't work fine
do_something
# => NameError: undefined local variable or method `this_is_not_defined_anywhere' for main:Object
@JKring
JKring / mongoid_criteria_array_bug.rb
Created May 19, 2015 17:35
Mongoid Criteria .to_a redundancy
### make sure the mongoid.yml is a file in the same directory:
# test:
# sessions:
# default:
# database: db
# hosts:
# - localhost:27017
### run with:
# export MONGOID_ENV=test; ruby mongoid_criteria_array_bug.rb
@JKring
JKring / word_count.rb
Last active September 5, 2015 02:24
All the words!
content = []
Document.no_timeout.each do |d|
if d.revisions.present?
revision = d.revisions.select { |r| r.contents.present? }.last
if revision
content << revision.contents.join(' ').gsub(/<\/?[^>]*>/, ' ')
end
end
end
puts content.join(' ').scan(/\w+/).size
@JKring
JKring / nginx.conf
Last active September 28, 2015 19:38
Scripted Nginx Configuration
user deploy;
worker_processes 4;
error_log /var/log/nginx/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
@JKring
JKring / ma.rb
Created May 23, 2012 00:21
MongoMapper Associations
require 'rubygems'
require 'mongo_mapper'
MongoMapper.database = "test_associations"
class Job
include MongoMapper::Document
belongs_to :invoice