Skip to content

Instantly share code, notes, and snippets.

Avatar

Dmitri Koulikoff dima4p

View GitHub Profile
@dima4p
dima4p / difference.js
Created Jun 10, 2021 — forked from Yimiprod/difference.js
Deep diff between two object, using lodash
View difference.js
/**
* 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])) {
View quotum.rb
# == 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 Apr 9, 2011
Monkey patch for Mechanize
View gist:911742
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 Mar 15, 2011
lib/templates/rails/scaffold_controller/controller.rb
View 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 %> }