Skip to content

Instantly share code, notes, and snippets.

View themegabyte's full-sized avatar

Shayan themegabyte

View GitHub Profile
@themegabyte
themegabyte / SaveToPDF.vba
Created August 8, 2022 20:27
Microsoft Word Save to PDF Shortcut Macro
Sub Save_to_PDF()
'
' Save_to_PDF Macro
'
'
With Dialogs(wdDialogFileSaveAs)
.Format = wdFormatPDF
.Show
End With
@themegabyte
themegabyte / handleChangeSnippet.js
Created August 7, 2022 12:06
handleChange for MUI DropDown with multiple enabled. Limits the number of entries to a maximum of 3
const handleChange = (event, selectedChildNode) => {
const {
target: { value },
} = event;
console.log(event.target.value);
// allow a maximum of 3 values only
if (annualCompensationProp.length > 2) {
// make a copy so not to mutate original state
let newArray = annualCompensationProp.slice();
// removes the incoming newItem if it already is in the array
@themegabyte
themegabyte / json_dump.py
Created June 22, 2022 06:58
A quick function to dump python list to .json file.
def json_dump(data: list):
t = []
for idx, row in enumerate(data):
_t = {'id': idx, 'data': row}
t.append(_t)
with open('test.json', 'w', encoding='utf-8') as f:
json.dump(t, f,
ensure_ascii=False, indent=4)
// Course Eval
// Set all to 5
let myElem = document.querySelector("#divStudentCouseForm");myElem.children[0].childNodes[1].childNodes.forEach((e)=>{console.log(e.childNodes[2]);if (e.childNodes[2] && e.childNodes[2].children[0]) console.log(e.childNodes[6].childNodes[0].checked = true)})
// Set all to 1
let myElem = document.querySelector("#divStudentCouseForm");myElem.children[0].childNodes[1].childNodes.forEach((e)=>{console.log(e.childNodes[2]);if (e.childNodes[2] && e.childNodes[2].children[0]) console.log(e.childNodes[2].childNodes[0].checked = true)})
// Teacher Eval
// Set all to 5
let myElem = document.querySelector("#divTeacherEvaluationForm");myElem.children[0].childNodes[1].childNodes.forEach((e)=>{if (e.childNodes[2].children[0]) console.log(e.childNodes[2].childNodes[0].checked = true)})
// Set all to 1
@themegabyte
themegabyte / describeSchema.js
Created May 29, 2022 09:43
Small function to describe mongoose schema.
const describeSchema = (obj) => {
let describeSchema = {};
for (const key of Object.keys(obj.schema.paths)) {
describeSchema[key] = obj.schema.paths[key].instance;
}
return describeSchema;
};
module.exports = describeSchema;
@themegabyte
themegabyte / Lookup_concat.vba
Created March 8, 2022 11:58
A function to lookup a value and concatenate all the resulting results. This is useful if you have a list of emails in a row that have a common identifier such as an "account name" and you want to mail merge all of them in the "to" field.
' https://www.get-digital-help.com/excel-udf-lookup-and-return-multiple-values-concatenated-into-one-cell/
' 03/08/2022
' Minor changes to fix my needs.
'Name user defined function and define parameters
Function Lookup_concat(Search_string As String, _
Search_in_col As Range, Return_val_col As Range, delim_in_return As String)
'Dimension variables and declare data types
Dim i As Long
@themegabyte
themegabyte / getQueryVariable.js
Last active February 27, 2022 15:29
Get a variable from the URL parameters, similar to PHP $_GET
function getQueryVariable(variable) {
var svalue = location.search.match(
new RegExp("[?&]" + variable + "=([^&]*)(&?)", "i")
);
return svalue ? svalue[1] : svalue;
}
// ?page=1
getQueryVariable("page"); // 1
@themegabyte
themegabyte / bookmark.js
Created January 30, 2022 18:55
PTCL Auto Toggle DSL Mode to Reconnect Internet without Rebooting Router.
javascript: (() => {
function checkLogin() {
username = document.getElementById("Frm_Username");
password = document.getElementById("Frm_Password");
loginButton = document.getElementById("LoginId");
if (username == null) {
first();
} else {
if (username.value === "") {
username.value = "admin";
@themegabyte
themegabyte / fix.ps1
Created November 26, 2021 16:31
Fix Permissions for private key in OpenSSH ssh-add for Windows 10
# Courtesy: https://superuser.com/a/1329702
# Set Key File Variable:
New-Variable -Name Key -Value "$env:UserProfile\.ssh\id_rsa"
# Remove Inheritance:
Icacls $Key /c /t /Inheritance:d
# Set Ownership to Owner:
Icacls $Key /c /t /Grant $env:UserName:F
@themegabyte
themegabyte / GetURL.bas
Last active June 13, 2021 13:37
Excel function to extract HyperLinks from linked cell.
Function GetURL(rng As Range) As String
On Error Resume Next
GetURL = rng.Hyperlinks(1).Address
End Function
' Usage: GetURL(Cell Number)
' Output: Associated address with Cell Number