Skip to content

Instantly share code, notes, and snippets.

var altmetricURL = 'https://api.altmetric.com/v1/doi/' + ArticleData.doi;
var dimensionsURL = 'https://metrics-api.dimensions.ai/doi/' + ArticleData.doi;
var counterURL = 'https://counter.plos.org/api/v1.0/stats/totals/doi/' + ArticleData.doi;
var URLs = [altmetricURL, dimensionsURL, counterURL];
var isMetricsView = location.pathname.indexOf('metrics') > 0
if (isMetricsView) {
var citedSection = new MetricsCitedSection();
var discussedSection = new MetricsDiscussedSection();
var savedSection = new MetricsSavedSection();
@benjaminkreen
benjaminkreen / pdf_multisearch.html
Created September 18, 2019 20:29
For doing multiple searches on a pdf
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>PDF searcher</title>
</head>
<body>
@benjaminkreen
benjaminkreen / get_alert_results.rb
Last active July 19, 2019 21:28
Gets alert results based on NED alerts
require 'httparty'
require 'date'
# This currently just gets all of the alerts and fetches the resulting documents. A good way to test this would be to
# compare the returned count of documents. if its close that would be great.
# here are all the keys that exist in the query column of the alerts table.
# ["startPage", "filterSubjects", "unformattedQuery", "query", "eLocationId", "pageSize", "resultView", "volume", "sortValue", "sortKey", "filterKeyword", "filterArticleTypes", "filterSubjectsDisjunction", "filterAuthors", "filterJournals", "id", "sort", "filterArticleType", "filterStartDate", "filterEndDate", "resultsPerPage", "sortOrder", "page", "x", "y", "from", "q", "filterSections"]
ALLOWED_QUERY_KEYS = ["q", "filterSubjects", "volume", "filterKeyword", "filterArticleTypes", "filterSubjectsDisjunction", "filterAuthors", "filterJournals","filterArticleType", "filterSections", "query", "unformattedQuery"]
WOMBAT_SEARCH_URL = 'https://collections.plos.org/dynamicSearch'
@benjaminkreen
benjaminkreen / PLOSSimilarArticles.js
Last active June 19, 2019 20:45
Similar Article code
let containerClass = 'related-articles-container';
let listId = 'related-articles-list';
let header = 'Similar PLOS Articles';
let params = new URLSearchParams(window.location.search);
let relatedDoi = params.get('id');
let allowedTypes = ['Research Article', 'Front Matter'];
// GTM doesn't support backtick notation, refactor
function relatedCallback (data) {
console.log(data)
let relatedDocs = data['moreLikeThis'][relatedDoi]['docs']
@benjaminkreen
benjaminkreen / plos_transactional_email.rb
Created February 4, 2019 21:09
rails implementation transactional emailing with queueing
# app/controllers/events_controller.rb
class EventsController < ApplicationController
def create
Event.create(params.permit(:event_type, :doi, :event_data))
render json: {}, status: :ok
end
end
# app/models/event.rb
class Event < ActiveRecord
@benjaminkreen
benjaminkreen / plos_salesforce_user_importer.rb
Created January 22, 2019 21:48
A discourse scheduled job to import plos salesforce users
module Jobs
class ::PlosSalesforceUserImporter < Jobs::Scheduled
every 2.hours # TODO: not sure if correct
CLIENT_KEYS = [:username, :password, :client_id, :client_secret, :host]
SETTING_PREFIX = 'plos_salesforce_user_importer_'
IMPORT_FIELDS = %w(
Id PersonEmail Salutation FirstName LastName Name
Affiliation__pc GUID_Acct__c ORCiD__c Iso_Country_Code__pc
@benjaminkreen
benjaminkreen / moodle_csv.rb
Last active January 17, 2019 21:33
Discord user import for moodle data
require "csv"
require File.expand_path(File.dirname(__FILE__) + "/base.rb")
# Edit the constants and initialize method for your import data.
# Requires that Custom User Fields be created before running scrit with names matching the keys in REQUIRED_USER_FIELD_NAME_MAP
# Call it like this:
# RAILS_ENV=production CSV_FILE=/path/to/file.csv bundle exec ruby script/import_scripts/moodle_csv.rb
class ImportScripts::MoodleCsv < ImportScripts::Base
CSV_FILE_PATH = ENV['CSV_FILE']
@benjaminkreen
benjaminkreen / transmogrifier.rb
Last active June 27, 2019 16:35
A script to convert plos landing page json
require 'json'
require 'csv'
require 'pry'
class Transmogrifier
# this class takes a bunch of plos landing page json and
# renders bootstrap 4 html into a CSV that can be imported
# to wordpress. Makes ya wonder.
def initialize(page_object)