Skip to content

Instantly share code, notes, and snippets.

View oropesa's full-sized avatar
🙂
I'm chachon

Oropesa oropesa

🙂
I'm chachon
View GitHub Profile
@oropesa
oropesa / Window.js
Created April 6, 2019 18:42
Initial steps of an electron project
const { BrowserWindow } = require( 'electron' );
const defaultProps = {
width: 1024,
height: 640,
webPreferences: { nodeIntegration: true },
show: false
};
class Window extends BrowserWindow {
@oropesa
oropesa / elementIsVisibleInViewport.js
Created February 24, 2019 20:52
Returns true if the element specified is visible in the viewport, false otherwise. Use Element.getBoundingClientRect() and the window.inner(Width|Height) values to determine if a given element is visible in the viewport. Omit the second argument to determine if the element is entirely visible, or specify true to determine if it is partially visi…
kconst elementIsVisibleInViewport = (el, partiallyVisible = false) => {
const { top, left, bottom, right } = el.getBoundingClientRect();
const { innerHeight, innerWidth } = window;
return partiallyVisible
? ((top > 0 && top < innerHeight) || (bottom > 0 && bottom < innerHeight)) &&
((left > 0 && left < innerWidth) || (right > 0 && right < innerWidth))
: top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
};
@oropesa
oropesa / arrayToCSV.js
Created February 24, 2019 20:42
Converts a 2D array to a comma-separated values (CSV) string. Use Array.prototype.map() and Array.prototype.join(delimiter) to combine individual 1D arrays (rows) into strings. Use Array.prototype.join('\n') to combine all rows into a CSV string, separating each row with a newline. Omit the second argument, delimiter, to use a default delimiter …
const arrayToCSV = (arr, delimiter = ',') =>
arr.map(v => v.map(x => `"${x}"`).join(delimiter)).join('\n');
/**
* In: . Out: 2018
* In: 2018. Out: 2018
* In: 2013. Out: 2013-18
* In: 1998. Out: 1998-2018
*
* @param string $year
* @return string
*/
function get_website_year_start( $year ) {
@oropesa
oropesa / codigo.gs
Last active September 25, 2018 13:42
Google Spreadsheet Script: Cast digit number to letter number; of money, including cents, in spanish.
var UNIDADES = new Array( "", "un", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve", "diez", "once", "doce", "trece", "catorce", "quince", "dieciséis", "diecisiete", "dieciocho", "diecinueve", "veinte", "veintiuno", "veintidos", "veintitres", "veinticuatro", "veinticinco", "veintiseis", "veintisiete", "veintiocho", "veintinueve" );
var DECENAS = new Array( "", "diez", "veinte", "treinta", "cuarenta", "cincuenta", "sesenta", "setenta", "ochenta", "noventa", "cien" );
var CENTENAS = new Array( "", "ciento", "doscientos", "trescientos", "cuatrocientos", "quinientos", "seiscientos", "setecientos", "ochocientos", "novecientos" );
function numero2LetrasRecursivo( numero ) {
var resultado = "";
switch( true ) {
case( numero == 0 ):
resultado = "cero";
break;
@oropesa
oropesa / encrypt-decrypt.php
Last active June 10, 2022 16:05
Encrypt and decrypt in php
$string = "Hello World";
$encrypted = oro_encrypt_string( $string );
$decrypted = oro_decrypt_string( $encrypted );
echo $string . '<br />' . $encrypted . '<br />' . $decrypted;
function oro_encrypt_string( $string, $key = '', $iv = '', $method = '' ) {
$encrypt_method = empty( $method ) ? 'AES-256-CBC' : $method;
$secret_key = empty( $key ) ? 'random' : $key;
charset "utf-8";
/* CSS Document */
.kek{
text-shadow: 1px -1px 0 #767676,
-1px 2px 1px #737272,
-2px 4px 1px #767474,
-3px 6px 1px #787777,
-4px 8px 1px #7b7a7a,
-5px 10px 1px #7f7d7d,
@oropesa
oropesa / native-fonts.css
Created March 1, 2018 12:11
Uses the native font of the operating system to get close to a native app feel.
.system-font-stack {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
/**
-apple-system. is San Francisco, used on iOS and macOS (not Chrome however)
BlinkMacSystemFont. is San Francisco, used on macOS Chrome
Segoe UI. is used on Windows 10
Roboto. is used on Android
Oxygen-Sans. is used on GNU+Linux
function header_status($statusCode) {
static $status_codes = null;
if ($status_codes === null) {
$status_codes = array (
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
200 => 'OK',
201 => 'Created',
@oropesa
oropesa / toType.js
Last active March 5, 2018 16:49
'typeof' return de basic type. 'toType' return the specify type. EXAMPLE [object Date] return 'date', not 'object'.
var toType = function(obj) {
return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
}
toType({a: 4}); //"object"
toType([1, 2, 3]); //"array"
(function() {console.log(toType(arguments))})(); //arguments
toType(new ReferenceError); //"error"
toType(new Date); //"date"
toType(/a-z/); //"regexp"