Skip to content

Instantly share code, notes, and snippets.

@dima4p
dima4p / difference.js
Created June 10, 2021 15:42 — forked from Yimiprod/difference.js
Deep diff between two object, using lodash
/**
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
function changes(object, base) {
return _.transform(object, function(result, value, key) {
if (!_.isEqual(value, base[key])) {
# == Schema Information
#
# Table name: quota
#
# id :integer not null, primary key
# campaign_id :integer
# target :integer default("0")
# completed :integer default("0")
# parent_ids :text default("{}"), not null, is an Array
# settings :json default("{}")
@dima4p
dima4p / gist:911742
Created April 9, 2011 20:35
Monkey patch for Mechanize
class Mechanize
class Page
def initialize(uri=nil, response=nil, body=nil, code=nil, mech=nil)
@encoding = nil
method = response.respond_to?(:each_header) ? :each_header : :each
re_test = /charset\s*=/i
re_select = /charset\s*=\s*([^; "]+)/i
response.send(method) do |header,v|
next unless v =~ re_test
@dima4p
dima4p / controller.rb
Created March 15, 2011 10:20
lib/templates/rails/scaffold_controller/controller.rb
class <%= controller_class_name %>Controller < ApplicationController
# GET <%= route_url %>
# GET <%= route_url %>.xml
def index
@<%= plural_table_name %> = <%= orm_class.all(class_name) %>
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @<%= plural_table_name %> }