Skip to content

Instantly share code, notes, and snippets.

View simonfongnt's full-sized avatar

Simon Fong simonfongnt

View GitHub Profile
# Client configs, 16.04,
script-security 2
up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf
# network manager, 16.04, install below package to enable import openvpn client configs
sudo apt install network-manager-openvpn-gnome
# Client configs, 18.04/18.10
@simonfongnt
simonfongnt / gist:a7b73e3010b6d1a2b462b2303ccc7383
Created November 18, 2020 03:19
check & delete /.cache ubuntu
what's going to be deleted:
find ~/.cache/ -depth -type f -atime +365
deleted (last accessed more than a year ago)
find ~/.cache/ -type f -atime +365 -delete
@simonfongnt
simonfongnt / ubuntucleanupspace.sh
Last active November 16, 2021 03:24
ubuntu clean up space
rotate the files first so that recent entries are moved to inactive files
journalctl --rotate
Retain only the past two days:
journalctl --vacuum-time=30d
Retain only the past 500 MB:
journalctl --vacuum-size=500M
@simonfongnt
simonfongnt / cipter.js
Created October 19, 2020 03:43
CryptoJS Encryption Decryption Javascript
// constants / params
const key = CryptoJS.enc.Utf8.parse('example-key');
const iv = CryptoJS.enc.Utf8.parse('example-iv');
// functions
function CryptJsWordArrayToUint8Array(wordArray) { // https://github.com/brix/crypto-js/issues/274
const l = wordArray.sigBytes;
const words = wordArray.words;
const array = new Uint8Array(l);
let i=0; /*dst*/
let j=0; /*src*/
@simonfongnt
simonfongnt / index.html
Last active October 19, 2020 03:33
Drive API index HTML in Chrome Extension
<html>
<head>
<title>Example</title>
<style>
button {
padding: 10px;
background-color: #3C79F8;
display: inline-block;
}
</style>
@simonfongnt
simonfongnt / background.js
Created October 19, 2020 03:30
Drive API Background Javascript in Chrome Extension
chrome.browserAction.onClicked.addListener(function() {
chrome.tabs.create({url: 'index.html'});
});
@simonfongnt
simonfongnt / manifest.json
Created October 19, 2020 03:28
Drive API Manifest Example in Chrome Extension
{
"name": "Manifest Example",
"description" : "Drive API Manifest in Chrome Extension",
"version": "1.0",
"permissions": [
"identity"
],
"background": {
"scripts": ["background.js"],
"persistent": false
@simonfongnt
simonfongnt / DriveAPIAuth.js
Last active October 19, 2020 03:29
Drive API Auth Javascript in Chrome Extension
// function within window
window.onload = function() {
// button behaviours
document.querySelector('button')
.addEventListener(
'click',
function() {
// get Auth Token
chrome.identity.getAuthToken({interactive: true}, function(token) {
console.log(token);
@simonfongnt
simonfongnt / DriveAPIWriteFile.js
Last active October 19, 2020 02:53
Drive API Write File Javascript
var DriveBaseUrl = 'https://www.googleapis.com/';
var DriveWriteUrl = 'upload/drive/v3/files/';
// write file - update with Array Buffer
fetch(
DriveBaseUrl + DriveWriteUrl + fileId,
{
method: 'PATCH',
headers: {
Authorization: 'Bearer ' + token,
'Accept': 'text/plain',
@simonfongnt
simonfongnt / DriveAPIRenameFile.js
Last active October 19, 2020 02:53
Drive API Write File Javascript
const DriveRenameUrl = 'https://content.googleapis.com/drive/v3/files/';
// rename file - fetch
fetch(
DriveRenameUrl + fileId + '?alt=json',
{
method: 'PATCH',
headers: {
Authorization: 'Bearer ' + token,
'Accept': 'application/json',
'Content-Type': 'application/json'