Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hectorcorrea
hectorcorrea / demo.html
Last active March 21, 2024 14:56
JavaScript DOM events and call back functions
<html>
<head>
<!-- what does this code do? -->
<script src="leequery.js"></script>
</head>
<body>
<h1>Playing with JavaScript</h1>
<p>
This is a paragraph with a button:
@hectorcorrea
hectorcorrea / fuse-demo.html
Created January 12, 2024 01:37
Demo how to use fuse.js with plain JavaScript
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/fuse.js/dist/fuse.js"></script>
</head>
<body>
<input type="text" id="searchTerms" placeholder="text to search" />
<button id="searchButton">Search</button>
<div id="searchResults">
# =======================================================================
# tagAdd - adds a tag (term) to the dictionary
#
# Usage:
#
# script.execute :in file:/Users/correah/src/mediaflux/tagAdd.tcl :arg -name tagName "tagXX" :arg -name tagDescription "this is the tag XX"
#
# =======================================================================
set log_name "homework-2023-03-24"
<!DOCTYPE html>
<html>
<style>
th {
border-style: solid;
}
td {
border: 0px;
padding-top: 0px;
@hectorcorrea
hectorcorrea / pre-commit
Created August 11, 2022 15:03
A sample Git pre-commit hook to make sure file vault.yml file is encrypted before accepting a commit
#!/bin/sh
# reference: https://www.atlassian.com/git/tutorials/git-hooks
#
# To use this Git hook in a given repository:
# 1. copy the content to .git/hooks/
# 2. make it an executable: chmod u+x .git/hooks/pre-commit
#
# Once installed, everytime you issue `git commit` it will make sure the file vault.yml has the
# expected token to indicate that is encrypted. If the token is not found we assume the file is
# NOT encrypted and reject the commit.
@hectorcorrea
hectorcorrea / simplest_sort.rb
Created May 9, 2022 15:02
Ruby version of "the simplest (and most surprising) sorting algorithm ever"
# Reference: https://arxiv.org/abs/2110.01111
a = [1, 9, 100, 23, 4, 99, 500, 245, 77]
n = a.length-1
puts "-- ORIGINAL --"
puts a
for i in 0..n do
for j in 0..n do
if a[i] < a[j]
@hectorcorrea
hectorcorrea / eztest.rb
Created April 8, 2022 13:59
Playing with the ezid-client gem
require "ezid-client"
require "byebug"
def show_ark(identifier)
puts "Target: #{identifier.target}"
puts "ID....: #{identifier.id}"
puts "Status: #{identifier.status}"
end
Ezid::Client.configure do |config|
# Parses timing information for lines that include "ELAPSED: "
def parse_file(filename, server)
File.readlines(filename).each do |line|
elapsed = line.index("ELAPSED: ")
next if elapsed.nil?
elapsed += 9
# Line looks like:
# I, [2021-07-10T00:49:28.827383 #9379] INFO -- : ELAPSED: All items for 99106284923506421 took 1429 ms
timestamp = line.split(" ")[1][1..-1]
api = line[elapsed..-1].split(" ")[0..1].join("_").downcase
@hectorcorrea
hectorcorrea / pod.sh
Last active February 25, 2021 22:49
Quick and dirty script to produce POD files for PUL
#!/bin/bash
#
# This script will process our Alma MARC XML full dump files
# and uploads the data to the POD project.
#
# Notice that we don't publish all records and/or all the data.
#
# This script expects the `marcli` utility to be available on the PATH
# (https://github.com/hectorcorrea/marcli/releases)
#
@hectorcorrea
hectorcorrea / traject_config_marc_xml.rb
Last active January 29, 2021 14:33
Basic example on how to process a MARC XML file with Traject. Notice that there is a trick to process MARC XML files without namespaces (like those produced by Alma).
# A very simple config file for Traject to parse a MARC XML file.
#
# Usage:
# traject -t xml -c traject_config_marc_xml.rb -w Traject::DebugWriter xml_tiny.xml
to_field 'title', extract_marc('245a', first: true)