Skip to content

Instantly share code, notes, and snippets.

View feroult's full-sized avatar
always coding ;)

Fernando Ultremare feroult

always coding ;)
View GitHub Profile
@feroult
feroult / macros_base.rb
Created February 7, 2011 21:07
RSpec Macros Recorder
module MacrosBase
def self.included(base)
base.extend(GroupMethods)
end
module GroupMethods
def mock(model_name)
class_eval <<-EOFMOCK
def mock_#{model_name}(stubs={})
(@mock_#{model_name} ||= mock_model(#{model_name.to_s.classify}).as_null_object).tap do |#{model_name}|
@feroult
feroult / controller_macros.rb
Created February 7, 2011 21:08
Rails Controller Macros (with scaffold default)
module ControllerMacros
def self.included(base)
base.extend(GroupMethods)
end
def mock_access(user = mock_model(User))
controller.stub('require_user').and_return(true)
controller.stub('current_user').and_return(user)
end
@feroult
feroult / customers_controller_spec.rb
Created February 7, 2011 21:10
RSpec for a Rails Controller, using macros
require 'spec_helper'
describe CustomersController do
before(:each) do
mock_filter(:require_user_owner)
end
# GET /customers
get :index do
@feroult
feroult / line_items_controller_spec.rb
Created February 7, 2011 21:35
Macro template example
require 'spec_helper'
describe LineItemsController do
mock :order
mock :customer
# GET /orders/11/line_items
get :index, :order_id => 11 do
default :stub => :off
http://rubyonrails.org/
http://guides.rubyonrails.org/
http://pragprog.com/book/rails4/agile-web-development-with-rails (excelente livro)
http://www.slideshare.net/dextra/minicurso-ruby-on-rails-dextra (palestra introdutória)
@feroult
feroult / login.js
Last active August 29, 2015 14:01
Appengine devserver login/logout with QUnit Page JS
// See qunit-pages: https://github.com/murer/qunit-page
function login(page, user) {
page.step('login', function() {
page.stop();
$.get("/_ah/logout?continue=/blank.html", function(data) {
console.info("logout");
$.post('/_ah/login?continue=/blank.html', {
'email' : user + '@wavez',
'continue' : '/blank.html',
'action' : 'Log In'
goog.provide('n');
module(n, function() {
var started = false;
function go(path, callback) {
var controllerInfo = parse(path);
window[controllerInfo.controller][controllerInfo.action].call(this, controllerInfo.params, callback);
window.history.pushState('wink', "", path);
$('.dropdown.open .dropdown-toggle').dropdown('toggle');
@feroult
feroult / yawp.py
Created January 13, 2015 11:11
Datastore change property tool
from google.appengine.ext import ndb
from google.appengine.api import datastore
from google.appengine.api import datastore_types
from google.appengine.api import datastore_errors
from functools import partial
# import yawp from yawp
# yawp('/people').query().fetch()
# http://stackoverflow.com/questions/10709893/ndb-expando-model-with-dynamic-textproperty
# http://stackoverflow.com/questions/19842671/migrating-data-when-changing-an-ndb-fields-property-type/19848970#19848970
@feroult
feroult / yawp-hierarchy.md
Last active January 20, 2016 11:51
YAWP! Hierarchy Mapping

Note: You should consider when to use ancestor/key design with care. You'll get a limit of 1 write/sec for each entity group.

First, map your entity endpoints:

  @Endpoint(path = "/users")
  public class User {
      @Id
      IdRef<User> id;
 
@feroult
feroult / draw_maps.js
Created February 11, 2016 20:24
Draw Maps
module(maps, function() {
function AreaMap(selector, lat, lng, radius) {
var WINKEE_SQUARE = new google.maps.LatLng(-22.865964, -47.054778);
var center = WINKEE_SQUARE;
if (lat) {
center = new google.maps.LatLng(lat, lng);
}