Skip to content

Instantly share code, notes, and snippets.

View mindscratch's full-sized avatar

Craig Wickesser mindscratch

View GitHub Profile
@mindscratch
mindscratch / inflector.js
Created August 26, 2011 10:32
Inflector is a small library for working with strings.
// I found this via the following URL https://www.jig.com/static/js/inflector.js?v=600c7 on 08/26/2011
// and thought it was pretty cool, however, I haven't found a Tasty Labs JS page or some other official
// place where it has been released, so I thought I'd save a copy here for now.
// Copyright 2011 Tasty Labs
//
// Inflector is a small library for working with strings.
window.Inflector = {
@mindscratch
mindscratch / render_and_redirect.markdown
Created September 11, 2011 22:46 — forked from jcasimir/render_and_redirect.markdown
Render and Redirect in Rails 3

Render and Redirect

The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.

Render

The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.

:action

@mindscratch
mindscratch / percentile_sample.rb
Created September 19, 2011 01:22
80th percentile
values = [1, 9, 3, 12, 29, 30, 33, 17, 5, 0, 23, 7, 19, 18, 32, 56, 34]
sorted = values.sort
percentile = 0.80
num_vals = (percentile * sorted.count).ceil
puts "Values within the #{(percentile * 100).to_i}th percentile: #{sorted[0, num_vals]}"
@mindscratch
mindscratch / application.yml
Created October 7, 2011 02:24
Mongoid and Qu configuration using MongoDB URI
# this is only a partial YAML file from a Rails application
# this YAML file would be loaded and used with the settingslogic gem
defaults: &defaults
database: &database
conn_uri: mongodb://username:password@localhost:27001/
db_name: myapp_default
job_queue: &job_queue
db_name: qu
@mindscratch
mindscratch / my_rest.rb
Created October 18, 2011 10:53
Simplified HTTParty
include 'httparty'
module SimpleRest
class Request < HTTParty::Request
def attach_ssl_certificates(http)
# this method is overridden b/c its the only place we can modify the 'http' object
if http.use_ssl?
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@mindscratch
mindscratch / rails.rb
Created October 20, 2011 16:05 — forked from simi/rails.rb
Rails 3.1.1 Webrick with SSL support
#!/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 'rubygems'
require 'rails/commands/server'
require 'rack'
require 'webrick'
require 'webrick/https'
module Rails
@mindscratch
mindscratch / data.txt
Created October 31, 2011 18:41
Hadoop Streaming Map/Reduce with Ruby
Now is definitely the time
@mindscratch
mindscratch / .gitignore
Created January 13, 2012 02:04 — forked from bkeepers/.gitignore
My Sublime settings
*
@mindscratch
mindscratch / environments.txt
Created February 9, 2012 12:10
Nokogiri Issue 607: JRuby - RubyStringIO#path - NoMethodError
Linux
JRuby 1.6.5 (using ruby 1.9.2p136)
rubygems 1.8.9
Windows
JRuby 1.6.5 (using ruby 1.9.2 p290)
rubygems 1.8.10
@mindscratch
mindscratch / how_to_use_widget.js
Created February 9, 2012 16:42
JavaScriptMVC File Upload
$('#somediv-with-upload-button').uploader({
action: '/some/where',
succses: this.callback('onUploadSuccess'),
error: this.callback('onUploadError'),
click: this.callback('onUploadClick'),
params: {
tags: ['foo', 'bar', 'baz']
});
onUploadClick: function(buttonEl, event) {