Skip to content

Instantly share code, notes, and snippets.

View themegabyte's full-sized avatar

Shayan themegabyte

View GitHub Profile
@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;
// 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 / 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)
@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 / 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 / MYAdder.vba
Last active August 9, 2022 12:15
[WORD] Adds tables and appropriate formatting for calculating MY pricing.
Sub MYAdder()
'
' MYAdder Macro
'
'
Selection.Cells.Split NumRows:=1, NumColumns:=4, MergeBeforeSplit:=False
Selection.InsertRowsBelow 3
Selection.MoveLeft Unit:=wdCell
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.ColumnSelectMode = True
@themegabyte
themegabyte / PremiumAdderFC.VBA
Created August 9, 2022 14:14
Adds Premium support to Direct Quote.
Sub PremiumAdderFC()
'
' PremiumAdderFC
' Adds Premium support to Direct Quote.
'
Dim PlatPrice As Integer
PlatPrice = 299
FormattedPlatPrice = Format(PlatPrice, "$##,##0.00")
Selection.InsertRowsBelow 1
Selection.MoveLeft Unit:=wdCell
Sub ResellerDiscount()
' Define Discount multiplier
' Discount Deductor
DiscountM = 0.7
DiscountD = 1 - DiscountM
Selection.SelectCell
CurrentPrice = Val(Replace(Replace(Selection.Text, "$", ""), ",", ""))
NewD = CurrentPrice * DiscountD
NewPrice = CurrentPrice * DiscountM
@themegabyte
themegabyte / next.config.js
Last active November 20, 2022 19:21
next config if you get client side errors in next js production build. This will generate an unminified version which is easier to debug.
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
output: "standalone",
serverRuntimeConfig: {
PROJECT_ROOT: __dirname,
},
webpack: (config) => {
config.optimization.minimize = false;
@themegabyte
themegabyte / Shopify Impulse Expanse Image Variant Image dynamic change with variant change.md
Last active December 30, 2022 20:03
Shopify Impulse Expanse Image Variant Image dynamic change with variant change

So basically this theme has a "stacked Images" feature. where you can use the alt text field to include a tag that will help the theme to stack the images according to a variant.

Stacked images do work well if I add an alt text to it.

But if we need to mimic default shopify functionality, I had to add an exlamation mark at line 8985 of theme.js. Line 13 in my gist example above.

Because Line 13 always resorted to go to the else part of the if statement, and for some reason Array.from(target.parentElement.children).indexOf(target) always returned a data index of zero. i think this is by design because the theme always expects images to be stacked. So my ! disabled the stack. stack feature

Now I am trying to find the stacked image setting and how its computed.