DEV Community

Discussion on: How do you manage re-usable code snippets?

Collapse
 
jeremyf profile image
Jeremy Friesen

I use org-roam paired with org-babel. Org-roam helps me tag and relate it. Org-babel means I have rich "backticks"; meaning the code is editable and runable.

Below is an example. The first two paragraphs are "prose" and the #+BEGIN_SRC line indicates that what follows is PlantUML code, which I can run from Emacs and will generate the file feed-strategy-erd.png.

Below is a rough sketch of the Entity Relationship Diagram I would use were we putting all of this in the database.

The goal of these conceptual tables is to provide a means to configure and generate SQL that calculates each article’s relevancy score based on the user’s preferences.  And to then return the most relevant articles for the user.

#+BEGIN_SRC plantuml :file feed-strategy-erd.png
  @startuml
  !theme amiga

  entity experiment {
      ,* id
      --
      ,* label
      ,* start date
      ,* end date
  }

  entity variant_experiment {
      ,* experiment_id
      ,* variant_id
      --
      ,* probability of using this variant

  }

  entity variant {
      ,* id
      --
      ,* label
      ,* order_by_lever_id
  }

  entity variant_relevancy_lever {
      ,* variant_id
      ,* relevancy_lever_id
      --
      ,* config (e.g. relevancy score range)
  }

  entity order_by_lever {
      ,* id
      --
      ,* order_by_fragment
  }

  entity relevancy_lever {
      ,* id
      --
      ,* label
      ,* user_required
      ,* select_fragment
      ,* joins_fragments
      ,* group_by_fragment
  }

  experiment ||--|{ variant_experiment
  variant ||--o{ variant_experiment
  relevancy_lever ||--o{ variant_relevancy_lever
  variant ||--o{ variant_relevancy_lever
  order_by_lever ||--o{ variant
  @enduml
#+END_SRC

#+RESULTS:
[[file:feed-strategy-erd.png]]
Enter fullscreen mode Exit fullscreen mode
Collapse
 
jeremyf profile image
Jeremy Friesen

The above is an example of code I don't often call but want to remember.

Otherwise, I use a snippet manager. For Emacs that's a mix of Yasnippets (for ye'old Textmate style snippets) and Tempel when I want more bare metal Lisp snippets.