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 / responsive-table-ant-design.js
Created August 31, 2021 09:54
Responsive table with Ant Design
import { Table } from "antd";
...
<Table
...
scroll={{ x: "max-content" }}
/>
...
@nghiaht
nghiaht / gist:6fc19596453e325bce7586e2e5f0c432
Created November 23, 2020 06:56
Source directory containing current symlinked script
SCRIPT_REAL_DIR=$(dirname $(realpath "$0"))
echo ${SECRIPT_REAL_DIR}
@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 / replace_multiple_regex_matches.js
Created July 24, 2019 10:23
replace multiple regex matches in Javascript
var r = /t\-test|test/g; // Note: /g
var input = "these are test t-test";
var output = input.replace(r, "") // Replace matched with ""
@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 / jest_enzyme_material_ui_select_on_change.js
Last active December 6, 2018 08:06
Jest Enzyme: onChange for material-ui Select (SelectInput - react-admin)
const handleSubmit = sinon.spy();
const wrapper = mount(
<Provider store={store}>
<MyForm onSubmit={handleSubmit} />
</Provider>
);
// Assume MyForm having a platform select input whose name is "platform"
const elem = wrapper.find("Select[name='platform']");
elem.prop("onChange")("iOS"); // Get onChange and call directly instead of the traditional elem.simulate("change", {target: {value: "iOS"}}) for <select> or <input>
@nghiaht
nghiaht / prepare_python_mysqlclient.sh
Last active October 30, 2018 04:51
Setup steps for python mysqlclient
cd ~
mkdir virtualenvs
cd virtualenvs
pip install virtualenv
virtualenv default # or virtualenv -p python3 default (depends on environments)
sudo apt-get install -y python-dev # or python3-dev
sudo apt-get install -y libmysqlclient-dev
source default/bin/activate
@nghiaht
nghiaht / check_keystore.sh
Created October 18, 2018 03:32
Check keystore expiration date
keytool -list -v -keystore keystore.jks
# Enter password
# Check the line "Valid from..."
@nghiaht
nghiaht / 3des_using_node_builtin_crypto.js
Last active March 11, 2022 22:11
Sample codes for encrypting and decrypting by 3DES using node-forge or built-in crypto module
const crypto = require("crypto");
/**
* Encrypt 3DES using Node.js's crypto module *
* @param data A utf8 string
* @param key Key would be hashed by md5 and shorten to maximum of 192 bits,
* @returns {*} A base64 string
*/
function encrypt3DES(data, key) {
const md5Key = crypto.createHash('md5').update(key).digest("hex").substr(0, 24);
tar -xzf <file>.tar.gz