Navigation Menu

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 / 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 / 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 / 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 / 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))
}
/**
* Example data in the collection:
*
* [
* { _id: ObjectId(), key: "foo", value: "bar" },
* { _id: ObjectId(), key: "fbKey", value: "123" },
* { _id: ObjectId(), key: "logoUrl", value: "https://my-site.s3.aws.us-east-1/logo.png" },
* ]
*/
@jgdev
jgdev / .zshrc
Last active June 11, 2020 11:55
Auto Activate Python VirtualEnv - ZSH
# ... your zsh file
function _virtualenv_auto_activate() {
current_dir=$(pwd)
if [[ -d "./venv" && -z "$VIRTUAL_ENV" ]]; then
export VIRTUAL_ENV_PATH=$current_dir;
source $VIRTUAL_ENV_PATH/venv/bin/activate
elif [[ ! -z "$VIRTUAL_ENV" && $current_dir != "$VIRTUAL_ENV_PATH"* ]]; then
export VIRTUAL_ENV_PATH=;
deactivate