Skip to content

Instantly share code, notes, and snippets.

View keybase.md

Keybase proof

I hereby claim:

  • I am brugnara on github.
  • I am brugnara (https://keybase.io/brugnara) on keybase.
  • I have a public key ASCoJBlnKDqzCqhNkSlpPVBbQvuRel9O-oKGyYRC7MnoFQo

To claim this, I am signing this object:

View snapshot-array.go
type SnapshotArray struct {
hash map[int]map[int]int
snap int
}
func Constructor(length int) SnapshotArray {
array := SnapshotArray{
map[int]map[int]int{},
0,
@brugnara
brugnara / lowest-common-ancestor-of-deepest-leaves.go
Created Dec 12, 2020
[golang] Given a BT, let's found the ancestor for the deepest leave/s
View lowest-common-ancestor-of-deepest-leaves.go
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func lcaDeepestLeaves(root *TreeNode) *TreeNode {
levels := map[int][]*TreeNode{}
@brugnara
brugnara / validate-bst-with-pointers.go
Created Dec 12, 2020
Validate a BST using pointers with golang
View validate-bst-with-pointers.go
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func loopBST(root *TreeNode) bool {
if root == nil {
@brugnara
brugnara / loop-bst.go
Created Dec 12, 2020
Loop a BST using channel in golang
View loop-bst.go
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func printBST(root *TreeNode) {
chn := make(chan int)
@brugnara
brugnara / n-queens.go
Last active Dec 11, 2020
Place N Queens on a NxN chessboard, with Go!
View n-queens.go
func totalNQueens(n int) int {
if n == 1 {
return 1
}
board := make([][]bool, n)
for i:=0;i<n;i++ {
board[i] = make([]bool, n)
}
@brugnara
brugnara / client.js
Created Mar 22, 2018 — forked from alepez/client.js
nodejs file transfer with http post
View client.js
var request = require('request');
var path = require('path');
var fs = require('fs');
var filename = process.argv[2];
var target = 'http://localhost:3000/upload/' + path.basename(filename);
var rs = fs.createReadStream(filename);
var ws = request.post(target);
@brugnara
brugnara / README.md
Created Apr 9, 2016 — forked from oscarrenalias/README.md
Docker service discovery with HAproxy, consul and registrator on Docker Machine and Docker Swarm
@brugnara
brugnara / child.js
Created Jan 4, 2015
fork vs spawn, nodejs
View child.js
var i = 0;
setInterval(function() {
if (i++ % 2) {
console.log('I\'m the child!');
} else {
console.error('I\'m the child!');
}
}, 1500);