Skip to content

Instantly share code, notes, and snippets.

@jgonera
jgonera / gist:781722
Created January 16, 2011 12:01
JS for file upload progress with gp.fileupload and Nginx module
function pollGp() {
$.ajax({
type: 'GET',
url: '/gp.fileupload.stat/${c.upload_id}',
cache: false,
dataType: 'json',
timeout: 5000,
success: function(response) {
if (response.state == 1) {
$('#progressbar div').css('width', response.percent + '%');
# Fabrication
Fabricator(:user) do
email { sequence(:email) { |n| "tester#{n}@test.com" } }
password 'tester'
end
Fabricator(:store, from: :dropbox_store) do
path '/myproject'
end
# project.rb
class Store
include Mongoid::Document
end
class Project
include Mongoid::Document
field :name
@jgonera
jgonera / gist:1302398
Created October 20, 2011 21:09
Profiling Mongoid (?) problem
Total: 24 samples
12 50.0% 50.0% 12 50.0% garbage_collector
2 8.3% 58.3% 2 8.3% Hash#[]=
1 4.2% 62.5% 1 4.2% ActiveSupport::Notifications::Fanout#publish
1 4.2% 66.7% 1 4.2% Array#inspect
1 4.2% 70.8% 1 4.2% BSON::OrderedHash.allocate
1 4.2% 75.0% 3 12.5% CBson.deserialize
1 4.2% 79.2% 1 4.2% Kernel#dup
1 4.2% 83.3% 1 4.2% Kernel#tap
1 4.2% 87.5% 1 4.2% Mongoid::Logger#debug
@jgonera
jgonera / gist:1303392
Created October 21, 2011 09:01
Profiling Mongoid (?) problem, 1.9.2-p290
Total: 17 samples
4 23.5% 23.5% 4 23.5% garbage_collector
1 5.9% 29.4% 1 5.9% AbstractController::I18nProxy#initialize
1 5.9% 35.3% 1 5.9% ActionController::LogSubscriber#start_processing
1 5.9% 41.2% 1 5.9% ActionView::PathSet#find_all
1 5.9% 47.1% 13 76.5% ActiveSupport::Callbacks#run_callbacks
1 5.9% 52.9% 1 5.9% ActiveSupport::Configurable::ClassMethods#config
1 5.9% 58.8% 1 5.9% BSON::ObjectId#initialize
1 5.9% 64.7% 1 5.9% BSON::OrderedHash.allocate
1 5.9% 70.6% 1 5.9% Class#from_string
@jgonera
jgonera / gist:1303536
Created October 21, 2011 10:34
Mongo driver vs. Mongoid benchmark
require 'benchmark'
require 'mongo'
require 'mongoid'
require './project'
db = Mongo::Connection.new.db('coledit_development')
Mongoid.configure do |config|
config.master = db
end
@jgonera
jgonera / gist:1303871
Created October 21, 2011 13:37
Python MongoDB performance test
from pymongo import Connection
from pymongo.objectid import ObjectId
connection = Connection()
db = connection.coledit_development
def test():
project = db.projects.find_one({'_id': ObjectId('4e52ccbd3a5c9f20b8000003')})
#print project['name']
@jgonera
jgonera / gist:1306405
Created October 22, 2011 19:40
Dumb MongoDB benchmark
var i, project;
for (i=0; i<1000000; ++i) {
project = db.projects.find({"_id": ObjectId("4ea1661a3a5c9f09b5000005")});
project[0].name; // to actually fetch the object
}
@jgonera
jgonera / gist:1477482
Created December 14, 2011 17:08
Custom interface for Mocha with background function
var mocha = require('./mocha');
var Suite = mocha.Suite
, Test = mocha.Test;
/**
* BDD-style interface:
*
* describe('Array', function(){
* describe('#indexOf()', function(){
* it('should return -1 when not present', function(){
@jgonera
jgonera / gist:2897851
Created June 8, 2012 20:02
Google Chart interpolateNulls
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Google Charts</title>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
function drawVisualization() {