Skip to content

Instantly share code, notes, and snippets.

@FreddieSanchez
FreddieSanchez / Graph.scala
Created March 27, 2022 22:10
bfs/dfs implementation of a graph in Scala 3
import scala.annotation.tailrec
class Graph[A](m: Map[A, Set[A]]):
type Vertex = A
type GraphMap = Map[Vertex, Set[Vertex]]
private def neighbors(v: Vertex): List[Vertex] =
m.get(v).map(_.toList).getOrElse(List.empty[Vertex])
def search(start: Vertex, end: Vertex): Boolean =
@tailrec
def bfs(toVisit: List[Vertex], visited: List[Vertex]): Boolean =
#!/bin/bash
#
# mkproj
#
# Builds a project structure for java or scala
#
# --package io.github.freddiesanchez --type [java|scala]
#
# src/
# main/
@FreddieSanchez
FreddieSanchez / gist:fcf9915427f95f44ca24
Last active August 29, 2015 14:10
Ways of creating files/directories with an letter incremention

One problem that I face often is I have to create a directory with new version of files based on a previous directory. The convesion is to use the current date 20141125 followed by an letter 'a'. I wanted to script this out instead of doing it manually.

Obtaining the current date is easy:

date "+%Y%m%d"

This should yield the date of the form YYYYMMDD.

The next part is obtaining incrementing a letter. Here are two ways of doing it. The first uses the 'tr' command. The second uses bash's Brace Expansion.

Keybase proof

I hereby claim:

  • I am FreddieSanchez on github.
  • I am freddiesanchez (https://keybase.io/freddiesanchez) on keybase.
  • I have a public key whose fingerprint is 4225 A9F5 6668 41BA AE5B 2CA8 193A BC9C 6FED 5BD9

To claim this, I am signing this object: