Skip to content

Instantly share code, notes, and snippets.

View jgdev's full-sized avatar
🏠
Working from home

Joan Peralta jgdev

🏠
Working from home
View GitHub Profile
@jgdev
jgdev / error_response.json
Created February 23, 2024 04:06
Cardnet Responses
{
"ResponseCode": "05",
"TransactionID": "YTDZYW",
"TransactionId": "YTDZYW",
"RemoteResponseCode": "N/A",
"AuthorizationCode": "N/A",
"RetrivalReferenceNumber": "000000000001",
"CreditCardNumber": "493198______6702",
"TxToken": "txn-4b6e9ad69e5b4e8d996d244a0af14986",
"ResponseDetails": "transaction_rejected"
@jgdev
jgdev / macos.md
Last active February 12, 2024 12:04
Generate SSL Self-Signed Certificate

Installation

  • sudo echo "127.0.0.1 yourhostname.dev" >> /etc/hosts
  • brew install nginx
  • brew services start nginx
  • export CERT_NAME=yourhostname.dev
  • export SSL_FOLDER=/etc/ssl
  • export NGINX=/opt/homebrew/etc/nginx
  • chmod +x ./generate_certificate.sh
@jgdev
jgdev / cardnet_service.py
Last active February 5, 2024 23:38
Implementación CardNet Python
from myapp.settings.base import API_BASE_URL, PAYMENTS_MERCHANT_NAME, PAYMENTS_MERCHANT_NUMBER, PAYMENTS_MERCHANT_TERMINAL, PAYMENTS_MCC
from myapp_payments.models import Transaction
from django.utils.translation import gettext as _
class CardNetPaymentIntegrationService:
def get_message_from_status_code(status_code):
match status_code:
case "success":
@jgdev
jgdev / digitalocean-restore-network.sh
Created September 24, 2023 14:08
DigitalOcean - restore network on droplet resize
#!/bin/sh
DROPLET_IP=
DROPLET_GATEWAY=
ip link set eth0 up
ip link set eth1 up
ip addr flush dev eth0
ip addr add $DROPLET_IP/32 dev eth0
ip route add $DROPLET_GATEWAY dev eth0
@jgdev
jgdev / useFetch.ts
Created August 27, 2023 14:49
React Hook to fetch API resources
import { useCallback, useEffect, useState } from "react";
type Status = "idle" | "loading" | "error" | "fetched" | "debouncing";
export type Options = {
timeout?: number;
debounceTime?: number;
};
export type FetchAttempt<T> = Partial<RequestInit> & {
@jgdev
jgdev / Component.container.tsx.hbs
Created March 4, 2023 17:45
Generate react components using Plop
import React from 'react';
import { Props as ComponentProps, {{pascalCase name}} } from './{{pascalCase name}}'
export type Props = ComponentProps & {};
export const {{pascalCase name}}Container = (props: Props) => {
return (
<{{pascalCase name}} {...props} />
);
@jgdev
jgdev / aes256cbc.py
Last active February 26, 2023 21:14
python encode/decode aes256 example
# pip3 uninstall pycrypto
# pip3 install pycryptodome
from Crypto.Cipher import AES
import base64
BLOCK_SIZE = 16
def pad(data):
@jgdev
jgdev / cloudSettings
Last active November 3, 2022 06:21
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-08-13T20:52:32.602Z","extensionVersion":"v3.4.3"}
@jgdev
jgdev / index.html
Last active June 1, 2022 19:04
Get percentage of image loading.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Get percentage loaded from image</title>
<script type="text/javascript">
Image.prototype.onChangeSize;
Image.prototype.load = function(url){
var _this = this,
req = ((XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
@jgdev
jgdev / postbuild.js
Last active April 23, 2022 17:22
TypeScript resolve root path alias script
import fs from 'fs'
import path from 'path'
function listJsFiles(dir) {
return fs.readdirSync(path.resolve('.', dir)).reduce((files, file) => {
let result = [...files]
const filePath = path.join(dir, file)
if (fs.lstatSync(filePath).isDirectory()) {
result = result.concat(listJsFiles(filePath))
}