Skip to content

Instantly share code, notes, and snippets.

View agodin3z's full-sized avatar
🍻
Working hard~

Andrés Godínez agodin3z

🍻
Working hard~
View GitHub Profile
@agodin3z
agodin3z / Luhn.js
Created November 17, 2020 02:27 — forked from jscari/Luhn.js
Luhn algorithm - generate / validate
var Luhn = {
// length of our number (check digit included)
length: 10,
pow2: [0, 2, 4, 6, 8, 1, 3, 5, 7, 9],
// compute check digit
checksum: function (x) {
var sum = 0;
var n;
var odd = false;
for (var i = x.length - 1; i >= 0; --i) {
@agodin3z
agodin3z / validateCard.js
Created November 17, 2020 02:00
Validate credit/debit card number (Luhn Algorithm)
export const validateCard = ((arr) => {
return (num) => {
let len = num.length;
let bit = 1;
let sum = 0;
let val;
while (len) {
val = parseInt(num.charAt(--len), 10);
// eslint-disable-next-line no-bitwise,no-cond-assign
sum += (bit ^= 1) ? arr[val] : val;
@agodin3z
agodin3z / getCardType.js
Last active November 17, 2020 01:58
Get credit/debit card type
export const getCardType = (num) => {
let type = 'unknow';
if (num.match('^3[47]\\d{0,13}')) {
type = 'amex';
} else if (num.match('^(?:6011|65\\d{0,2}|64[4-9]\\d?)\\d{0,12}')) {
type = 'discover';
} else if (num.match('^3(?:0([0-5]|9)|[689]\\d?)\\d{0,11}')) {
type = 'diners';
} else if (num.match('^(5[1-5]\\d{0,2}|22[2-9]\\d{0,1}|2[3-7]\\d{0,2})\\d{0,12}')) {
type = 'mastercard';
@agodin3z
agodin3z / isValidUrl.js
Created October 19, 2020 15:31
Check if the string is a valid URL
const isValidUrl = (url) => {
const regex = new RegExp(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi);
return url.match(regex);
};
@agodin3z
agodin3z / sequelize-migration-file-generator.js
Last active June 16, 2023 08:13 — forked from manuelbieh/sequelize-migration-file-generator.js
Creates migration files for existing sequelize models [custom]
#!/usr/bin/env node
const fs = require('fs');
const models = require('../models');
for (const model in models) {
const tableName = models[model].tableName;
let defaultValue = '';
let onUpdate = '';
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@agodin3z
agodin3z / Login.cpp
Last active November 17, 2020 01:49
Simple Login with Cpp - Linux y Windows
#include <iostream>
#include <stdlib.h>
#include <string>
#ifdef WINDOWS
#include <windows.h>
#else
// Assume POSIX
#include <termios.h>
#include <unistd.h>
#endif
@agodin3z
agodin3z / SistemaPedidos.cpp
Last active November 17, 2020 01:48
Simple sistema de pedidos
#include <iostream>
#include <stdlib.h>
#include <cstdlib>
#include <string.h>
using namespace std;
// Varibles Globales
int error = 0, salir = 0, atras = 1;
string admUser="admin", admPass="54321", cajUser="cajero", cocUser="cocina", usrPass="12345";
@agodin3z
agodin3z / media_queries.css
Created January 17, 2016 00:04
Media queries for standard devices
/* ----------------------------------------------- */
/* ------------------- Laptops ------------------- */
/* ----------------------------------------------- */
/* ----------- Laptops Non-Retina Screens ----------- */
@media screen
and (min-device-width: 1200px)
and (max-device-width: 1600px)
and (-webkit-min-device-pixel-ratio: 1) {
}
<!-- Schema.org markup for Google+ -->
<meta itemprop="name" content="site name">
<meta itemprop="description" content="descripcion max 155 caracteres">
<meta itemprop="image" content="imagen">
<!-- Twitter Cards -->
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@usuario" />
<meta name="twitter:title" content="titulo" />
<meta name="twitter:description" content="descripcion max 140 caracteres" />