Skip to content

Instantly share code, notes, and snippets.

@johvet
johvet / array_validator.rb
Created August 31, 2017 18:42
A Rails validator which is allows to apply any validator to array type columns
# frozen_string_literal: true
##
# Validator for array columns
#
# Credits go to Alexander Menzhinsky, who created an initial version of this [https://gist.github.com/amenzhinsky/c961f889a78f4557ae0b].
#
# Usage:
# validates :array_column, array: { length: { is: 20 }, allow_blank: true }
# validates :array_column, array: { numericality: true }
@johvet
johvet / form.rb
Last active August 29, 2015 14:05
Problem destroying awesome_nested_set
class Form < ActiveRecord::Base
has_many :questions, :dependent => :destroy
end
$ curl http://localhost:9200/massactioncasecms_development_sharings/_search?pretty=true
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
class AllowTranscodingUserToBeNull < ActiveRecord::Migration
def up
change_column :transcodings, :user_id, :string, :null => true
end
def down
change_column :transcodings, :user_id, :string, :null => false
end
end
class DashboardReplies
constructor: ->
$('form.discussion-reply').formSubmit
disableWhileLoading: true
success: (form$, data, params) =>
@format_reply(form$, data.discussion_entry)
error: (data) ->
console.log "*** IT FAILED"
@johvet
johvet / backtrace.log
Created December 10, 2012 17:36
backtrace after calling /courses
SQL (0.3ms) SET client_min_messages TO 'panic'
SQL (0.3ms) SET standard_conforming_strings = on
SQL (0.3ms) SET client_min_messages TO 'notice'
Setting Load (1.8ms) SELECT * FROM "settings" WHERE ("settings"."name" = 'default_account_id') LIMIT 1
Cache read: _account_lookup2/2
Cache hit: _account_lookup2/2 ({:expires=>3600 seconds})
Processing CoursesController#index (for 96.49.86.58 at 2012-12-10 18:33:02) [GET]
Parameters: {"action"=>"index", "controller"=>"courses"}
@johvet
johvet / sample.rb
Created September 25, 2012 12:08
sample middleware
config.middleware.use AssetAccess
@johvet
johvet / gist:3150292
Created July 20, 2012 11:41
Rails Console Session with DateTime problem
1.9.2p318 :019 > a.reload
ActionActivity Load (2.0ms) SELECT "activities".* FROM "activities" WHERE "activities"."type" IN ('ActionActivity') AND "activities"."id" = $1 LIMIT 1 [["id", 38]]
=> #<ActionActivity id: 38, contribution_id: 10, contribution_type: "Show", type: "ActionActivity", activity_at: "2012-07-20 10:58:00", content: "Also a new one", covered_episode: nil, episode_released_on: "2012-07-20", email_from: nil, email_to: nil, title: nil, user_id: 1, deleted: false, created_at: "2012-07-20 10:58:39", updated_at: "2012-07-20 11:38:21", action_status_id: 2>
1.9.2p318 :020 > a.activity_at
=> Fri, 20 Jul 2012 03:58:00 PDT -07:00
1.9.2p318 :021 > a.attributes = {:activity_at => '2012-07-20 03:58:00'}
=> {:activity_at=>"2012-07-20 03:58:00"}
1.9.2p318 :022 > a.changed?
=> true
1.9.2p318 :023 > a.changes