Skip to content

Instantly share code, notes, and snippets.

View gist:603217
// Load the original image from disk
using (Image originalImage = Image.FromFile(Server.MapPath("~/App_Data/" + file.FileName)))
{
// Apply the queued transformations to the original image
using (Image newImage = filters.Apply(originalImage))
{
return File(newImage.ToByteArray(), file.ContentType);
}
}
View custom_steps.rb
Given /^I visit subdomain "(.+)"$/ do |sub|
#host! "#{sub}.example.com" #for webrat
Capybara.default_host = "#{sub}.example.com" #for Rack::Test
Capybara.app_host = "http://#{sub}.example.com:9887" if Capybara.current_driver == :culerity
################################################################################
# As far as I know, you have to put all the {sub}.example.com entries that you're
# using in your /etc/hosts file for the Culerity tests. This didn't seem to be
# required for Rack::Test
################################################################################
@doxavore
doxavore / mongoid_scope_building.rb
Created Nov 17, 2010
Using Mongoid's scoping mechanisms can really add up... not always in a good way.
View mongoid_scope_building.rb
# Example implementation, ignoring the less important details:
class MyTree
include Mongoid::Document
include Mongoid::Tree
referenced_in :account, :inverse_of => :trees
field :slug
scope :slugged, lambda { |s, options={}| where(options.merge(:slug => s)).first }
View gist:736619
// jQuery barfs because $(empty).data("autocomplete") => undefined
$(".course-autocomplete").autocomplete({
source: "/courses/autocomplete.json"
}).data("autocomplete")._renderItem = function(ul, item) {
return $("<li>")
.data("item.autocomplete", item)
.append("<a>" + item.name + "</a>")
.appendTo(ul);
};
View gist:796283
first = ["t", "o", "p", "c", "o", "d", "e", "r", "s", "i", "n", "g", "l", "e", "r",
"o", "u", "n", "d", "m", "a", "t", "c", "h", "f", "o", "u", "r", "n", "i"]
second = ["n", "e", "f", "o", "u", "r", "j", "a", "n", "u", "a", "r", "y", "t", "w",
"e", "n", "t", "y", "t", "w", "o", "s", "a", "t", "u", "r", "d", "a", "y"]
hash = Hash.new(0)
(first + second).each_with_index do |element, i|
hash[element] += 1
end
View gist:987147
_getObjectAttr: function () {
var object = {},
formValues = this.get("value");
for (name in formValues) {
if (formValues.hasOwnProperty(name)) {
var nameParts = name.replace(/\]/g, '').split('['),
building = object;
dojo.forEach(nameParts, function (part, idx) {
View gist:1023439
(function () {
// Static list across all Persons?
var pets = [ ];
dojo.declare("Person", null, {
}
}());
View gist:1067561
fromString: function (dateString) {
if (!dateString) { return new Date(); }
// IE/Safari expects "2011/05/03 09:03:21-0500"
if (dojo.isIE || dojo.isSafari) {
// Replace hyphens with forward slashes (2011-05-03 => 2011/05/03)
dateString = dateString.replace(/^(\d{4})-(\d{2})-(\d{2})/, "$1/$2/$3");
// Replace T prefixing time with a space (T09:03:21 => " 09:03:21")
dateString = dateString.replace(/T(\d+:\d+:\d+)/, " $1");
// Remove colon in timezone (-05:00 => -0500)
View gist:1197960
require 'java'
require 'jodconverter-cli-2.2.1.jar'
def convert(file_in,file_out)
inputFile = java.io.File.new(file_in)
outputFile = java.io.File.new(file_out)
# connect to an OpenOffice.org instance running on port 8100
connection = com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection.new(8100)
connection.connect()
View gist:1197963
require 'java'
require 'jodconverter-cli-2.2.1.jar'
def convert(file_in,file_out)
inputFile = java.io.File.new(file_in)
outputFile = java.io.File.new(file_out)
# connect to an OpenOffice.org instance running on port 8100
connection = com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection.new(8100)
connection.connect()