Skip to content

Instantly share code, notes, and snippets.

View dbalduini's full-sized avatar

Diego Balduini dbalduini

  • Brazil
View GitHub Profile
@dbalduini
dbalduini / alias.ps1
Last active November 4, 2023 00:13
Unix like commands in Powershell
# create empty file
ni hello.txt
# remove directory recursively
rmdir
# list files
ls
@dbalduini
dbalduini / git_alias.sh
Last active November 16, 2022 17:48
git alias
git config --global alias.co 'checkout'
git config --global alias.br 'branch'
git config --global alias.st 'status'
git config --global alias.alias 'config --get-regexp ^alias'
git config --global alias.squash '!git reset $(git merge-base master $(git branch --show-current))'
git config --global alias.squash-undo 'reset HEAD@{1}'
@dbalduini
dbalduini / bitset.py
Created September 13, 2021 19:15
bit-array study
class BitSet:
"""
bit-array implementation
"""
def __init__(self, size):
# same as size / 32 (2^5)
self.arr = [0] * ((size >> 5) + 1)
@dbalduini
dbalduini / perceptron.js
Created February 28, 2020 23:37
My first perceptron that models the AND logical gate
// AND logic
// @see https://medium.com/@stanleydukor/neural-representation-of-and-or-not-xor-and-xnor-logic-gates-perceptron-algorithm-b0275375fea1
// The perceptron model is x1+x2–1 where weights is 1
// Classify into 1 or -1 where
// 1 = true
// -1 = false
const trainingData = [
[1, 1, 1],
[1, 0, -1],
[0, 1, -1],
@dbalduini
dbalduini / gerar-cidades.js
Created August 10, 2019 16:41
Gera lista de cidades do Brasil e copia para a area de transferencia
/**
* Generated from Wikipedia.
* Link: https://pt.wikipedia.org/wiki/Lista_de_munic%C3%ADpios_do_Brasil
*/
var xs = [];
$('.mw-parser-output li').each(function() {
xs.push($(this).text());
});
@dbalduini
dbalduini / ansible-vault.ps1
Last active April 26, 2019 13:27
Ansible vault in docker
param (
[switch]$Decrypt = $false,
[switch]$Encrypt = $false,
[string]$Path
)
$Dir = $(pwd)
$Target = "/tmp"
$Image = "<my-image-with-ansible>"
$C = "view"
// Reverse inplace the two char arrays splitten by space. Examples:
// perfect makes practice -> practice makes perfect
// a b c -> c b a
function reverse(arr) {
reverseArray(arr, 0, arr.length-1);
}
// reverse array inplace
function reverseArray(arr, start, end) {
@dbalduini
dbalduini / jsbin.nigedok.js
Created March 10, 2019 17:58
JS BinDijkstra algorithm// source https://jsbin.com/nigedok
// dijkstra algorithm
// Dijkstra’s algorithm works when all the weights are positive
// If you have negative weights, use the Bellman-Ford algorithm.
// START -> A
// START -> B
// B -> A
// A -> FIN
// B -> FIN
@dbalduini
dbalduini / postBinaryData.js
Last active August 22, 2018 22:29
post base64 binary data with nodejs request module
const convert = require('buffer-to-stream');
const request = require('request');
/**
* Post binary data in base64.
* @param opt The request options
* @param data The binary data in base64 string
* @param cb The request callback
*/
function _postBinaryData(opt, data, cb) {
@dbalduini
dbalduini / concat_uniq.sh
Last active July 21, 2018 01:19
Join csv by unique column
#!/bin/bash
awk -F'|' '(!a[$1]++){print $0"|"FILENAME;}' *.csv