Skip to content

Instantly share code, notes, and snippets.

@mankind
mankind / mail_boxer_notes.rb
Last active October 26, 2018 10:03
rails Mail-boxer notes
#send a message between two users. This will create a Mailoxer::Conversation behind the scene.
user_1 = User.where(email: 'user email').first
user_2 = User.where(email: 'user email').first
message_subject = "Review of work"
message_body = "Kindly look at my submitted work"
user_1.send_message(user_2, message_body , message_subject)
#starting Mail_boxer::Conversation
a = Mailboxer::Conversation.find(1)
yy = a.mesages
@mankind
mankind / _funder.html.erb
Created October 23, 2018 13:59
Enable autocomplete In Hyrax for funder's field
<%= f.input key,
as: :multi_value,
input_html: {
class: 'form-control',
id: 'ubiquity-funder',
data: { 'autocomplete-url' => "/authorities/search/local/funder",
'autocomplete' => key }
},
required: f.object.required?(key) %>
@mankind
mankind / create dropdown ie hyku authority or controlled vocabulary
Last active July 7, 2020 09:30
Add multipart metadata fields to samvera active_fedora models
Your next task is to turn the audience field into a dropdown and the dropdown options are 'particpant', 'spectator', 'graduate', 'apprentice'
See http://samvera.github.io/customize-metadata-controlled-vocabulary.html
1. Create a yaml file conatining vocabularies ie dropdown names in config/authorities with thesame name as your field. So if your field is funder, you will have
config/authorities/funder.yml eg https://github.com/ubiquitypress/hyku/blob/test/config/authorities/funder.yml
http://samvera.github.io/customize-metadata-controlled-vocabulary.html#create-a-vocabulary
In that file, add the values you want in your dropdown following the format above.
2. Create a service to load the dropdown names or vocabularies in app/services/
@mankind
mankind / _attribute_rows.html.erb
Created August 22, 2018 15:12
attempt to use custom attribute renderere to display samvera active_fedora multi-part metadata json field
<%= presenter.attribute_to_html(:creator, render_as: :creator) %>
@mankind
mankind / _attribute_rows.html.erb
Last active July 17, 2019 08:49
attempt to display samvera active-fedora json metatdata field using custom indexer approach
<%= presenter.attribute_to_html(:formatted_creator, render_as: :faceted) %>
@mankind
mankind / _contributor_group.html.erb
Last active August 17, 2018 14:57
samvera multi-part field
<%=
f.input :contributor_group, as: :contributor_group_type,
wrapper_html: { class: 'multi_value' },
input_html: { class: 'form-control', multiple: true },
include_blank: true,
required: f.object.required?(key)
%>
@mankind
mankind / binary_search_tree.rb
Created November 7, 2017 01:24
Valid Binary Search Trees
module BinarySearchTree
class Node
include Comparable
attr_reader :value
attr_accessor :left, :right, :nodes_tracker
def initialize(value)
@value = value
self.nodes_tracker = []
@mankind
mankind / rails-jsonb-queries
Last active April 17, 2024 12:14
Ruby on Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")

Assuming this table definition:

CREATE TABLE segments (segments_id serial PRIMARY KEY, payload jsonb);
With JSON values like this:

INSERT INTO segments (payload)
VALUES ('{
     "a": [
        {

"kind": "person",

@mankind
mankind / base.html
Last active July 21, 2016 09:45
Simple user defined form fields using html and javacsript. see demo: http://codepen.io/anon/pen/dMEywE and http://jsbin.com/vikibacese/edit?html,js,output
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title> User define form element Example </title>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-1.23.1.css">
<style>
#div1 {