Skip to content

Instantly share code, notes, and snippets.

View themegabyte's full-sized avatar

Shayan themegabyte

View GitHub Profile
@themegabyte
themegabyte / NumberComponent.jsx
Created March 24, 2023 17:35
React Number Component.
export const NumberComponent = (props) => {
const [myVal, setMyVal] = useState(props.value);
// update myVal if props.value changes on a rerender. useState only updates on initial render
if (myVal != props.value) setMyVal(props.value);
const onValChange = (e) => {
const { value, validity } = e.target;
if (myVal != props.value) setMyVal(props.value);
else setMyVal(value);
if (validity.valid) props.onChangeFunction(e);
};
@themegabyte
themegabyte / bucket-cutom-policy.json
Last active May 16, 2023 09:46
Amazon S3 Access Key Policy to scope access key to a single bucket
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
@themegabyte
themegabyte / convert.sh
Created January 7, 2023 18:27
Convert a Joplin export to PDF using that template
#!/bin/bash
for filename in *.md; do
CREATED=$(yq '.created |= with_dtf("2006-01-02 15:04:05Z"; tz("Asia/Karachi") | format_datetime("02-Jan-06 at 3:04:05PM")) | .created' --front-matter=extract "$filename")
NEWFILENAME=$(yq '.created |= with_dtf("2006-01-02 15:04:05Z"; tz("Asia/Karachi") | format_datetime("2006-01-02 150405")) | .created' --front-matter=extract "$filename")
echo "${filename} created on: ${CREATED}"
cp "${filename}" "markdown/${NEWFILENAME}.md"
pandoc -o "pdfs/${NEWFILENAME}.pdf" -V date:"${CREATED}" --template ./eisvogel --pdf-engine=xelatex --variable mainfont=DejaVuSerif "${filename}"
done
# -V geometry:"left=1cm,right=1cm,top=1cm,bottom=1cm"
# pandoc -o result.pdf --pdf-engine=xelatex --variable mainfont=DejaVuSerif
@themegabyte
themegabyte / .gitignore
Created January 7, 2023 17:24
Exclude a single directory and include the rest or selective
/*
!.gitignore
!Readme.md
!*.sh
!markdown/
!pdfs/
@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.

@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;
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 / 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
@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 / 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