Skip to content

Instantly share code, notes, and snippets.

@hectorcorrea
hectorcorrea / webserver.js
Last active November 17, 2022 19:54
web server in node.js
// A very basic web server in node.js
// Stolen from: Node.js for Front-End Developers by Garann Means (p. 9-10)
var port = 8000;
var serverUrl = "127.0.0.1";
var http = require("http");
var path = require("path");
var fs = require("fs");
var checkMimeType = true;
@hectorcorrea
hectorcorrea / mongoGetNewId.js
Created June 30, 2013 15:25
A quick way to get incremental ids for documents in MongoDB via the findAndModify feature. This snippet gets a new incremental/sequential ID. Keep in mind that this is not a good strategy when you database is horizontally distributed which is why MongoDB out of the box uses a much more complex algorithm to calculate _id. Use at your own risk. [S…
var getNewId = function(db, callback) {
var counters = db.collection('counters');
var query = {'name': 'myCustomId'};
var order = [['_id','asc']];
var inc = {$inc:{'next':1}};
var options = {new: true, upsert: true};
counters.findAndModify(query, order, inc, options, function(err, doc) {
if(err) {
@hectorcorrea
hectorcorrea / validtreev2.js
Created February 14, 2014 14:25
Validates a Binary Search Tree (version 2)
function isValidTree(root) {
// Walk the tree in order and add values to an array.
var values = [];
walkNode(root, values);
if (values.length == 1) {
// one-node tree is valid
return true;
}
@hectorcorrea
hectorcorrea / validatetreev4.js
Created February 18, 2014 05:05
Validates a Binary Search Tree (version 4)
// Validates a binary tree.
// This is a much elegant implementation than the previous two
// since it does not store an array of all the values, but rather
// it just keeps track of the last element compared against.
// Also, notice how processing is stopped as soon as a bad
// element is found.
function isValidTree(root) {
var lastValue = null;
var validator = function(value) {
@hectorcorrea
hectorcorrea / validatetree.scala
Created February 26, 2014 02:22
Validates a Binary Search Tree
// Validates a binary search tree (BST) to make sure
// all nodes are in order.
//
// Same implementation as https://gist.github.com/hectorcorrea/9064942 in JavaScript
class Node(theValue: Int, leftNode: Node, rightNode: Node) {
def value = theValue
def left = leftNode
def right = rightNode
override def toString = value.toString
@hectorcorrea
hectorcorrea / .bashrc
Last active May 8, 2023 21:02
My .bashrc
PS1="\w \$ "
alias ls='ls -G -la'
# Git aliases
alias st='git status'
alias br='git branch'
alias co='git checkout'
alias lg='git log'
alias df='git diff'
@hectorcorrea
hectorcorrea / dpla.html
Last active August 29, 2015 14:15
DPLA API Demo in plain HTML + JavaScript
<!DOCTYPE html>
<html>
<head>
<title>DPLA API demo</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<h2>DPLA API Demo</h2>
<p>Enter your DPLA API and git <i>Go</i> to fetch images from the Getty Trust</p>
@hectorcorrea
hectorcorrea / rdf4rdbms.md
Last active February 18, 2017 22:53
RDF for Relational Database heads
@hectorcorrea
hectorcorrea / ldp_containers.md
Last active June 10, 2021 13:49
A summary of the basic differences between the different kind of containers that LDP supports.

This document is a summary of the basic differences between the different kind of containers that Linked Data Platform (LDP) supports.

LDP specifies three types of containers:

  1. Basic Container
  2. Direct Container
  3. Indirect Container.

This documents describes the differences between the three types of containers by showing what triples are added by an LDP Server when adding a new element to each kind of container.

In particular we assume we have a fictitious blog entry (/blog/entry1/) and we want to add a comment to it. We start by showing what happens if the blog entry is a Basic Container, then we show what happens if the blog entry was instead a Direct Container, and lastly if it was an Indirect Container.

@hectorcorrea
hectorcorrea / frbr.md
Last active August 29, 2015 14:24
Notes from FRBR + Fedora + Inheritance meeting

FRBR + Fedora + Inheritance

My notes from the Google Hangout organized by Christina Harlow (@cm_harlow) on 7/14/2015

Keep in mind that I captured this as the video call went on and I might have gotten some of it wrong. I'll update this page with a link to the recording once it becomes available.

What is FRBR?

FRBR (Functional Requirements for Bibliographic Records) is a 1998 recommendation of the International Federation of Library Associations and Institutions (IFLA) to restructure catalog databases to reflect the conceptual structure of information resources. - http://www.oclc.org/research/activities/frbr.html