Skip to content

Instantly share code, notes, and snippets.

Enrique Esquinas esquinas

Block or report user

Report or block esquinas

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@esquinas
esquinas / airport_to_timezone_converter.rb
Last active Jan 17, 2020
Quick & dirty module to convert an Airport's IATA code into an IANA Timezone. Data source is the timezones.csv file in @mj1856's gist https://gist.github.com/mj1856/6d219c48697c550c2476 (Thanks, Matt Johnson-Pint)
View airport_to_timezone_converter.rb
#encoding: utf-8
# Usage example:
# --------------
#
# airport_code = 'TFN' # Tenerife Norte Airport in the Canary Islands.
# canary_islands_tz = AirportToTimezoneConverter.from_iata(airport_code)
# puts canary_islands_tz # => "Atlantic/Canary"
#
# winter_time = '2020-01-01 12:00:00'
@esquinas
esquinas / djb2e-hash.js
Created Sep 3, 2019
Quick & simple non-cryptographic 32bit hash function for non-security applications like generating colors from a string or slug. Based on the djb2a algorithm but + UTF16 rotation, + reversal, + XORing a random number.
View djb2e-hash.js
// Usage:
// djb2eHash( 'Hello World1' ); # => 1171219298
// djb2eHash( 'Hello World2' ); # => 449666786
// djb2eHash( 'Hello World3' ); # => 201925602
// djb2eHash( 'Hello World4' ); # => 3033001186
function djb2eHash(string, randomNumber = 0xcde7) {
// UTF16-rotate a character.
function rotU16(charCode) {
return 0x10000 - charCode;
}
@esquinas
esquinas / prettify-json-from-chromes-console.js
Created Aug 2, 2019
Used to prettify (make readable) JSON data returned by the WP JSON REST API, for example. Usage: copy & paste into your Chrome's console (in Firefox is built-in).
View prettify-json-from-chromes-console.js
document.querySelector('pre').textContent = JSON.stringify(JSON.parse(document.querySelector('pre').textContent), null, 4);
@esquinas
esquinas / describe.js
Last active Jul 15, 2019
A JS debugging tool like console.log() but a little amplifyed. Copy/paste it in your browser console and use it like "describe(something)"
View describe.js
function describe(x) {
function trueType(obj) {
return (Number.isNaN(obj) && 'NaN') || (Object.prototype.toString.call(obj).slice(8, -1));
}
let description = `DESCRIPTION:
------------
trueType: ${trueType(x)},
typeOf: ${typeof x},
boolean: ${!!x},
number: ${+x},
@esquinas
esquinas / quick-SI-APA-EUR-number-formatting.js
Created Jan 12, 2019
Quick SI/APA euro currency formatting in functional JavaScript.
View quick-SI-APA-EUR-number-formatting.js
const intlSpanishFormatter = Intl.NumberFormat('es-ES', { style: 'currency', currency: 'EUR'});
const PreventGroupingOfFourIntegerDigits = function ({type, value }, idx, parts) {
(idx === (parts.length - 7) && value.length < 2 && (parts[idx + 1].value = ''));
return value;
};
intlSpanishFormatter.formatToParts(1234.56).map(PreventGroupingOfFourIntegerDigits).join('');
@esquinas
esquinas / NAV-posts-pagination.php
Last active Oct 23, 2018
WP pagination partial (TODO: add theme classes)
View NAV-posts-pagination.php
<?php if ( get_previous_posts_link() || get_next_posts_link() ) : ?>
<div class="">
<nav class="">
<ul>
<li><?php posts_nav_link( '</li><li>' ); ?></li>
</ul>
</nav>
</div>
@esquinas
esquinas / my_uuid_codes.rb
Last active Aug 14, 2018
Quick, dirty but typographically resilient UUID codes. Hex digits A, B, C, D, E and F are replaced by letters that cannot be mistaken by any digit or any other letter. The choosen letters are E, J, N, P, V and X.
View my_uuid_codes.rb
# Takes 3 optional params: an int code_length, a string "separator" and a look-up "table" (hash).
def my_uuid_code(
code_length = 24,
separator: '-',
table: { "0" => '0', "1" => '1', "2" => '2', "3" => '3', "4" => '4', "5" => '5',
"6" => '6', "7" => '7', "8" => '8', "9" => '9',
"A" => 'E', "B" => 'J', "C" => 'N', "D" => 'P', "E" => 'V', "F" => 'X' })
posibilities = 16**code_length
@esquinas
esquinas / birthday_collision.rb
Created Aug 14, 2018
Calculate percentage probability of birthday collisions (Birthday paradox) in Ruby
View birthday_collision.rb
def prob_of_birthday_collision(people = 23.0, days = 365.25)
e = Math::E
k = people.to_f()
n = days.to_f()
return 100.0 * (1.0 - e**((-k * (k - 1.0)) / (2.0 * n)))
end
@esquinas
esquinas / birthday_collision.py
Created Aug 14, 2018
Calculate percentage probability of birthday collisions (Birthday paradox)
View birthday_collision.py
import math
def prob_of_birthday_collision(people=23.0, days=365.25):
e = math.e
k = float(people)
n = float(days)
return 100.0*(1.0-e**((-k*(k-1.0)) / (2.0*n)))
You can’t perform that action at this time.