Skip to content

Instantly share code, notes, and snippets.

View gabrieldewes's full-sized avatar
🎯
Focusing

Gabriel Dewes gabrieldewes

🎯
Focusing
View GitHub Profile
@gabrieldewes
gabrieldewes / BinaryTree.js
Last active November 30, 2016 13:17
A Binary Search Tree implementation in JavaScript (iterative)
/**
* @description Implementação de uma árvore binária de busca em JavaScript.
* @author Gabriel Dewes at 13 oct, 2016
*/
/**
* @constructor
*/
function BinaryTree() {
/**
@gabrieldewes
gabrieldewes / BinaryTree.java
Created October 31, 2016 12:02
A Binary Tree implementation in Java (recursive with basic functions (insert, remove))
// javac BinaryTree.java
// java BinaryTree
/**
* Created by Dewes on 13/09/2016.
*/
public class BinaryTree {
// Nosso nó pai
private Node node;
@gabrieldewes
gabrieldewes / Hashify.js
Last active February 9, 2017 19:13
Simple Java Script object hashing
/**
* @description Simple hashing for JS objects
* @author Gabriel Dewes at 9 nov, 2016
*/
Object.prototype.hashify = function(obj, len) {
obj = obj || this;
len = len || 2;
var i, j, r=[];
for (i=0; i<len; i++) {
r.push(i*268803292);
@gabrieldewes
gabrieldewes / uuid.js
Last active February 3, 2017 17:06
Simple and fast generation of RFC4122 UUIDs in Browser
/* Simple and fast generation of RFC4122 UUIDS. */
(function(root, factory) {
'use strict';
root.uuid = factory();
})(window, function() {
var byteToHex = [];
for (var i=0; i<256; ++i) {
byteToHex[i] = (i + 0x100).toString(16).substr(1);
@gabrieldewes
gabrieldewes / objectId.js
Last active February 3, 2017 20:34
Quickly generate random unique strings
/* It's of unspecified quality and not RFC4122.
* Very slow due to string replaces
*/
var objectId = function () {
var timestamp = (Date.now() / 1000 | 0).toString(16);
return timestamp + 'xxxxxxxxxxxxxxxx'.replace(/[x]/g, function() {
return (Math.random() * 16 | 0).toString(16);
}).toLowerCase();
};
@gabrieldewes
gabrieldewes / br_states.json
Last active February 9, 2017 16:58
Todos estados do Brasil com código UF, nome, sigla, área em KM² e região, segundo IBGE.
[{
"codigo_uf": 11,
"unidade_federacao": "Rondônia",
"sigla": "RO",
"area_km2": 237765.376,
"regiao": "Norte"
},{
"codigo_uf": 12,
"unidade_federacao": "Acre",
"sigla": "AC",
@gabrieldewes
gabrieldewes / data_to_table.js
Last active March 23, 2017 18:45
Simple snippet to generate HTML table for JSON or Array data.
if ("undefined"===typeof jQuery) throw new Error("This function requires jQuery.");
function table(element, data) {
var g, a, b, r, i, e, l,
s = Date.now();
g = $("<table class='table table-responsive table-hover'/>").appendTo(element);
a = $("<thead />").appendTo(g);
/* Generates the table thead */
r = data[0]; // Some element of any position, use the element with more atributtes
for (i in r) {
if (r.hasOwnProperty(i)) {
@gabrieldewes
gabrieldewes / count_tables_and_sum_rows.sql
Created February 10, 2017 17:35
Get the number of tables and the total of rows of all tables in MySQL
SELECT SUM(TABLE_ROWS) AS 'Total de Linhas', COUNT(*) AS 'Total de Tabelas'
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'databaseName';
@gabrieldewes
gabrieldewes / toYyyymmddhhmmss.js
Created November 2, 2017 18:36
JS Date "yyyy-mm-dd hh:mm:ss" format
(function() {
"use strict";
Date.prototype.toYyyymmddhhmmss = function() {
var yyyy = this.getFullYear(),
mm = this.getMonth() < 9 ? ("0" + (this.getMonth() + 1)) : (this.getMonth() + 1),
dd = this.getDate() < 10 ? ("0" + this.getDate()) : this.getDate(),
hh = this.getHours() < 10 ? ("0" + this.getHours()) : this.getHours(),
min = this.getMinutes() < 10 ? ("0" + this.getMinutes()) : this.getMinutes(),
ss = this.getSeconds() < 10 ? ("0" + this.getSeconds()) : this.getSeconds();
return "".concat(yyyy).concat("-")
@gabrieldewes
gabrieldewes / UploadResource.java
Created November 23, 2017 18:07
Uploading some binary file to http server
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
public class UploadResource {
// Uploading some binary file to http server