Skip to content

Instantly share code, notes, and snippets.

View danilomo's full-sized avatar

Danilo Oliveira danilomo

View GitHub Profile
@danilomo
danilomo / distances.hs
Last active May 24, 2017 14:30
Find the closest vector in a list to a given vector v
type Vector3D = (Float, Float, Float)
arr :: [ Vector3D ]
arr = [ ( 35, 30, 39 ),( 20, 12, 5 ) ]
tp :: Vector3D
tp = (19,13,3)
dist:: Vector3D -> Vector3D -> Float
@danilomo
danilomo / Range.java
Last active July 18, 2017 09:52
Finds which sub-interval contains a given value. Hardcoded X flexible solution
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class HardcodedRangeTest {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
@danilomo
danilomo / Range2.java
Last active July 18, 2017 09:52
Finds which sub-interval contains a given value. Flexible solution
interface Command {
public void execute();
public static final Command EMPTY = new Command() {
@Override
public void execute() {
// do nothing.
}
};
}
@danilomo
danilomo / Graph.scala
Last active July 26, 2017 08:11
Functional Graph API in Scala, using edge list as representation
/**
* A functional Graph object in Scala, for learning purposes.
*/
class Graph[V,W](val vertices: List[V], val edges: List[(V,V,W)]) {
override def toString(): String = vertices.toString() + ", " + edges.toString()
def addVertex(v: V): Graph[V,W] = Graph( v :: this.vertices, this.edges )
def addEdge(e: (V,V,W)): Graph[V,W] = Graph(this.vertices, e :: this.edges )
@danilomo
danilomo / gist:07779d8cf28e067f47ee98f1c3432583
Last active March 1, 2018 10:14
.emacs with a new untitled buffer in text mode and *GNU Emacs* and *scratch* killed
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(tool-bar-mode nil))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
@danilomo
danilomo / stack.fs
Created March 26, 2018 15:30
Reverse last n items on the stack
: create-stack
dup
1 + cells allocate throw dup 0 swap !
over over swap cells erase
swap drop
;
: write-on-top ( address n -- address ) swap dup dup @ 1 + cells + rot swap ! ;
: move-cursor ( address n -- address ) over dup @ rot + swap ! ;
@danilomo
danilomo / pomodoro.sh
Created May 8, 2018 15:44
pomodoro timer
#!/bin/bash
function check-command {
type $1 > /dev/null 2>/dev/null
if [ $? -ne 0 ]
then
(>&2 echo "Command $1 expected, but not found.")
(>&2 echo "Please install dependencies: sudo apt-get install sqlite3 jq")
exit 1
@danilomo
danilomo / VisitorOld.java
Created June 6, 2018 07:00
Visitor pattern example
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package visitorchallenge;
import ast.Exp;
import ast.MulExp;
import ast.NegExp;
@danilomo
danilomo / VisitorAlternative.java
Created June 6, 2018 07:01
Visitor pattern revisited
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package visitorchallenge;
import ast.Exp;
import ast.MulExp;
import ast.NegExp;
@danilomo
danilomo / chain.py
Created June 7, 2018 11:09
Emulating bash's chain of commands ( && operator )
class LinkedList:
def __init__(self, head, tail):
self.head = head
self.tail = tail
def reverse(self):
l = self
newl = None
while l:
newl = cons(l.head, newl)