Skip to content

Instantly share code, notes, and snippets.

View nghiaht's full-sized avatar

Huỳnh Trọng Nghĩa nghiaht

View GitHub Profile
@nghiaht
nghiaht / test_upload.py
Created March 21, 2019 09:09
Testing Django Rest Framework with multipart/form-data request
from django.test import TestCase
from rest_framework.test import APIClient
class FileUploadTestCase(TestCase):
def test_upload(self):
client = APIClient()
client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key)
# or self.client (Django https://docs.djangoproject.com/en/dev/topics/testing/advanced/)
response = client.post(reverse('upload-file'), {
@nghiaht
nghiaht / force_exit_telegraf_bot.js
Last active November 12, 2023 06:43
Auto restart Telegram bot using telegraf
const Telegraf = require("telegraf");
const bot = new Telegraf("TOKEN");
bot.catch((err) => {
console.error('Ooops', err);
process.exit(1); // I choose exit, you should use PM (Process Manager) and let them automatically restart the bot
// Or sth else
})
@nghiaht
nghiaht / generate_rsa_keypair.sh
Created September 13, 2018 03:30
Generate RSA keypair (public, private + pkcs8) using openssl command
# Private key
openssl genpkey -algorithm RSA -out private.pem -pkeyopt rsa_keygen_bits:2048
# Public key
openssl rsa -pubout -in private.pem -out public_key.pem
# Private key in pkcs8 format (for Java maybe :D)
openssl pkcs8 -topk8 -in private.pem -out private_key.pem
## nocrypt (Private key does have no password)