Skip to content

Instantly share code, notes, and snippets.

View rudyhuynh's full-sized avatar

Rudy Huynh rudyhuynh

  • VN
View GitHub Profile
@rudyhuynh
rudyhuynh / disable git pager.sh
Created February 19, 2023 13:54
To disable git paging when running git branch, git diff, ...
git config --global core.pager ""
@rudyhuynh
rudyhuynh / clonepsql.md
Last active February 9, 2023 04:45
Clone PSQL database to different machine

Assume you want to clone all data of table Abc into a database in a different machine.

  1. At src machine:
PGPASSWORD=password sudo pg_dump --host localhost --port 5432 --username username --format plain --verbose --file '/tmp/Abc.bak' --table Abc databasename
  1. Copy file to dst machine.

  2. At dst machine:

@rudyhuynh
rudyhuynh / table-to-json.js
Created April 15, 2021 09:06 — forked from johannesjo/table-to-json.js
Snippet to convert html table to json (to be used with google chrome or similiar)
function tableToJson(table) {
var data = [];
// first row needs to be headers
var headers = [];
for (var i=0; i<table.rows[0].cells.length; i++) {
headers[i] = table.rows[0].cells[i].innerHTML.toLowerCase().replace(/ /gi,'');
}
// go through cells
@rudyhuynh
rudyhuynh / node-notify-with-sound.js
Created June 20, 2020 15:37
Node notify with sound
require("node-notifier").notify({ title: "Title", message: "Message", sound: "Ping" });
@rudyhuynh
rudyhuynh / vagrant_setdate.sh
Created March 27, 2020 05:25 — forked from unfulvio/vagrant_setdate.sh
How to change server time on a Vagrant box on Virtualbox
#!/bin/bash
# Log in into the box
vagrant ssh
# VirtualBox syncs host time with guest, so we need to shut off VBox Guest Additions first
sudo service vboxadd-service stop
# Now you can set any date and time
sudo date -s "2020-10-01 10:25:00"
@rudyhuynh
rudyhuynh / convert-mov-to-mp4.md
Created March 18, 2020 13:53
Convert MOV to MP4
brew install ffmpeg
ffmpeg -i my-video.mov -vcodec h264 -acodec mp2 my-video.mp4
@rudyhuynh
rudyhuynh / log-to-file.js
Last active January 9, 2020 03:00
A logger that is similar to console.log but log to file, for NodeJS
/**
* Usage:
* const {logger} = require('./log-to-file')
* logger.log('something')
*/
const path = require('path');
const fs = require('fs');
const FILE_PATH = path.resolve(__dirname, 'default.log');
@rudyhuynh
rudyhuynh / parseUrlQuery.js
Last active January 31, 2020 03:38
Parse URL Query String to JSON
[...new URLSearchParams(location.search)].reduce((acc, [key, value]) => ({...acc, [key]: value}), {})
@rudyhuynh
rudyhuynh / readFileWithFileReader.js
Created September 3, 2019 03:13
read file with FileReader
const uploadFile = e => {
const file = e.target.files[0];
const fr = new FileReader();
fr.onload = () => {
initialState.queryBuilderState = JSON.parse(fr.result);
forceReRender();
};
fr.readAsText(file);
};
@rudyhuynh
rudyhuynh / downloadJson.js
Last active July 7, 2021 04:10
Download a JSON in javascript
function downloadJson(data, filename = 'data.json') {
const dataAtr =
'data:text/json;charset=utf-8,' +
encodeURIComponent(JSON.stringify(data));
const el = window.document.createElement('a');
el.setAttribute('href', dataAtr);
el.setAttribute('download', filename);
el.click();
}