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 / 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 / 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 / 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;
/**
* 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 / 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