Skip to content

Instantly share code, notes, and snippets.

View tsprates's full-sized avatar
🖥️
Working from home

Thiago Prates tsprates

🖥️
Working from home
View GitHub Profile
@tsprates
tsprates / ColorLuminance.sql
Last active June 28, 2018 13:43
Function to PostgreSQL to Calculate Lighter or Darker Hex Colors.
--
-- Convert to decimal and change luminosity
-- Inspired by: http://www.sitepoint.com/javascript-generate-lighter-darker-color/
--
--
-- Reverse: to_hex
-- See: http://grokbase.com/t/postgresql/pgsql-general/0541qyk9ya/help-with-converting-hexadecimal-to-decimal
CREATE OR REPLACE FUNCTION from_hex(t text) RETURNS integer AS $$
DECLARE
/**
* Conway Sequence
*
* @see http://en.wikipedia.org/wiki/Look-and-say_sequence
* @author Thiago Prates
*/
public class ConwaySequence {
/**
* Generate a element at position n according to *Conway Sequence*.
@tsprates
tsprates / HmacSHA512.java
Created May 28, 2014 16:44
Hmac SHA512
/**
* HmacSHA512
*
* @see <http://drumcoder.co.uk/blog/2011/apr/21/calculate-hmac-hash-java/>
* @param String value
* @param String secret
* @return String
*/
private String buildHmacSignature(String value, String secret) {
String result;
@tsprates
tsprates / getColorNameFromHexColor.js
Last active February 23, 2016 01:55
Converts a color name to its corresponding hex string.
/**
* Converts a color name to its corresponding hex string.
*
* @example getHexColor('orange') == '#ffa500'
* @param {String} colorValue The color name.
* @return {String}
*/
var getColorNameFromHexColor = (function() {
var elem = document.createElement('div');
var bg;
@tsprates
tsprates / ccw.js
Last active August 29, 2015 14:08
Checks if the google.maps.Polygon.Path is inside the polygon, to determine if exists "holes" inside the google.maps.Polygon.
/**
* Checks if the google.maps.Polygon.Path is inside the polygon.
*
* @see {@link https://developers.google.com/maps/documentation/javascript/overlays#Polygons}
* @see {@link http://gmaps-samples-v3.googlecode.com/svn/trunk/poly/pentagon.html}
* @see {@link http://debian.fmi.uni-sofia.bg/~sergei/cgsr/docs/clockwise.htm}
* @see {@link http://en.wikipedia.org/wiki/Curve_orientation}
* @param {google.maps.Polygon.Path} path
* @returns {boolean}
*/
@tsprates
tsprates / caesar_cipher.js
Last active August 29, 2015 14:15
Caesar Cipher
/**
* Caesar cipher.
*
* @link http://en.wikipedia.org/wiki/Caesar_cipher
* @param {string} msg
* @param {number} shift
* @return {string}
*/
function caesarCipher(msg, shift) {
var result = "",
@tsprates
tsprates / to_ascii.js
Last active March 17, 2022 21:13
Correspondent ASCII characters.
/**
* To ASCII.
*
* @param {string} text
* @returns {string}
*/
function toAscii(text) {
var noAscii = 'áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ';
var ascii = 'aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC';
var resultText = '';
@tsprates
tsprates / quicksort.js
Last active August 29, 2015 14:16
Quicksort implementation in JS.
/**
* Quicksort implementation.
*
* @see {@link http://en.wikipedia.org/wiki/Quicksort}
* @param {array} arr
* @result {array} Sorted array
.*/
var quicksort = function(arr) {
function partition(arr, left, right) {
@tsprates
tsprates / binary-tree.c
Last active April 30, 2022 11:23
A Binary Tree implementation in C
// Binary Tree
// Author: Thiago Prates <tsprates@hotmail.com>
#include <stdio.h>
#include <stdlib.h>
typedef struct _node {
int data;
struct _node* left;
struct _node* right;
@tsprates
tsprates / bandit.txt
Last active February 25, 2024 17:16
The Bandit wargame is aimed at absolute beginners.
# https://overthewire.org/wargames/bandit/
bandit1 NH2SXQwcBdpmTEzi3bvBHMM9H66vVXjL
bandit2 rRGizSaX8Mk1RTb1CNQoXTcYZWU6lgzi
bandit3 aBZ0W5EmUfAf7kHTQeOwd8bauFJ2lAiG
bandit4 2EW7BBsr6aMMoJ2HjW067dm8EgX26xNe
bandit5 lrIWWI6bB37kxfiCQZqUdOIYfr6eEeqR
bandit6 P4L4vucdmLnm8I7Vl7jG1ApGSfjYKqJU
bandit7 z7WtoNQU2XfjmMtWA8u5rN4vzqu4v99S
bandit8 TESKZC0XvTetK0S9xNwm25STk5iWrBvP