Skip to content

Instantly share code, notes, and snippets.

@brugnara
brugnara / README.md
Created April 9, 2016 12:01 — forked from oscarrenalias/README.md
Docker service discovery with HAproxy, consul and registrator on Docker Machine and Docker Swarm
@brugnara
brugnara / icons_and_splash.js
Last active September 20, 2016 11:13 — forked from apla/icons_and_splash.js
Fix for cordova 3.6.3
#!/usr/bin/env node
var cordova_util = require('cordova-lib/src/cordova/util');
var projectRoot = cordova_util.isCordova(process.cwd());
var projectXml = cordova_util.projectConfig(projectRoot);
var ConfigParser = require('cordova-lib/src/ConfigParser/ConfigParser');
var projectConfig = new ConfigParser(projectXml);
projectConfig.name();
var fs = require ('fs');
@brugnara
brugnara / do.sh
Created January 3, 2015 23:21
Extract meteor deploy mongo credential and execute mongodump for you.
#!/bin/sh
#
# Daniele Brugnara
#
# usage:
# meteor mongo xyz.meteor.com --url | ./do.sh
#
read mongo_auth
@brugnara
brugnara / client.js
Created March 22, 2018 08:10 — forked from alepez/client.js
nodejs file transfer with http post
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 / child.js
Created January 4, 2015 12:21
fork vs spawn, nodejs
var i = 0;
setInterval(function() {
if (i++ % 2) {
console.log('I\'m the child!');
} else {
console.error('I\'m the child!');
}
}, 1500);
@brugnara
brugnara / n-queens.go
Last active December 11, 2020 21:05
Place N Queens on a NxN chessboard, with 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 / loop-bst.go
Created December 12, 2020 06:37
Loop a BST using channel in golang
/**
* 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 / validate-bst-with-pointers.go
Created December 12, 2020 06:39
Validate a BST using pointers with golang
/**
* 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 / lowest-common-ancestor-of-deepest-leaves.go
Created December 12, 2020 09:40
[golang] Given a BT, let's found the ancestor for the deepest leave/s
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func lcaDeepestLeaves(root *TreeNode) *TreeNode {
levels := map[int][]*TreeNode{}