Skip to content

Instantly share code, notes, and snippets.

@agumonkey
agumonkey / hn.el
Last active September 26, 2021 14:38
porting hackernews -> org-mode from js to elisp https://gist.github.com/dharmatech/2ef271907cb73298318fdb50a4ee7d54
;;; hn.el --- convert hacker news post into org-mode buffer -*- lexical-binding: t -*-
;; Copyright (C) 2018- Free Software Foundation, Inc.
;; Author: Johan Ponin <johan.ponin.pro@gmail.com>
;; Version: 0.0.1
;; Package-Version: 20181103.0001
;; Keywords: hackernews, org-mode
;; This program is free software; you can redistribute it and/or modify
@pierrejoubert73
pierrejoubert73 / markdown-details-collapsible.md
Last active April 26, 2024 02:03
How to add a collapsible section in markdown.

How to add a collapsible section in markdown

1. Example

Click me

Heading

  1. Foo
  2. Bar
    • Baz
  • Qux

Acceleration of Two Objects Connected by a Cord

A ball of mass m1 and a block of mass m2 are attached by a lightweight cord that passes over a frictionless pulley of negligible mass, as shown in the figure below. The block lies on a frictionless incline of angle θ. Find the magnitude of the acceleration of the two objects and the tension in the cord.

Let's solve this problem using Symbolism, a computer algebra library for C#.

Free-body diagram for the ball:

Let's solve the following physics problem using Symbolism, a computer algebra library for C#.

One strategy in a snowball fight is to throw a first snowball at a high angle over level ground. While your opponent is watching the first one, you throw a second one at a low angle and timed to arrive at your opponent before or at the same time as the first one.

Assume both snowballs are thrown with a speed of 25.0 m/s.

The first one is thrown at an angle of 70.0° with respect to the horizontal.

The problem to solve

An example problem from the textbook Physics for Scientists and Engineers by Serway and Jewett:

Let's solve this using Symbolism, a C# library for computer algebra and symbolic computation.

Symbol definitions

Neo4j inspired graph database in Microsoft Access

Here I've clicked on the Book label. The nodes list displays nodes with the Book label. I then clicked on Dune, so the relationships list shows that the AUTHOR of Dune is Frank Herbert who was BORN_IN Tacoma.

Now I've selected the Album label and TheJoyOfMotion node. The relationship lists show that AnimalsAsLeaders RELEASED this album, that Lippincott is a TRACK on this album, and that this track was inspired by Tom Lippincott.

Quotation

Assuming a document system involving multiple authors each with their own documents:

A user should be able to select text in another document and use it as a quotation in their own document.

This quotation should be a link which will take a user back to the referenced text.

This quotation should link to the particular version of the document that is referenced.

;; Generics with return types
#| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$ petite --script generics.scm
|# ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (gen-id template-id . args)

Generics in Scheme

In a previous note I demonstrated polymorphism in Scheme using Chez Scheme's compile time values and properties.

The code in that example is pretty raw; you might not want to code each generic in that manner. One approach is to decouple the signature/method table. We can do this by factoring out some code into a 'make-generic' procedure:

(define (make-generic table)
  (lambda (stx)
 (lambda (lookup)

Polymorphism in Scheme via compile time dispatch

Here's an example of polymorphism in C++:

int nth ( int a[] , int i ) { return a[i] ; }

double nth ( double a[] , int i ) { return a[i] ; }

One way to think of this is that there are two functions called nth. One can be called with an int array and the other can be called with a double array. The function that is called is determined at compile time by looking at the type of the expression of the first argument.