Skip to content

Instantly share code, notes, and snippets.

View themegabyte's full-sized avatar

Shayan themegabyte

View GitHub Profile
@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 / 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 / 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 / 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 / .drone.yml
Created March 26, 2023 19:16
my drone CI config with Minio as Cache.
---
kind: pipeline
type: docker
name: default
steps:
- name: ubuntu-ls
image: ubuntu
commands:
- ls -la
@themegabyte
themegabyte / directus.js
Created June 4, 2023 18:53
Directus SDK with Axios Interceptors.
import { Directus } from "@directus/sdk";
const DIRECTUS_ENDPOINT = process.env.DIRECTUS_HOST || "";
const DIRECTUS_TOKEN = process.env.DIRECTUS_TOKEN || "";
const directus = new Directus(DIRECTUS_ENDPOINT, {
auth: {
staticToken: DIRECTUS_TOKEN,
},
});
@themegabyte
themegabyte / commands.sh
Last active June 27, 2023 10:10
AWS SSM Migration
aws ssm get-parameters-by-path --recursive --path "/CodeBuild/" --max-items 100
@themegabyte
themegabyte / 01-multistage-build.sh
Created July 11, 2023 06:33 — forked from evadne/01-multistage-build.sh
Build & Cache multi-stage Docker images (with Build Specification for AWS CodeBuild)
# the general idea
ImageTag="git"
FilePath="/Dockerfile"
RepoURI="123456789012.dkr.ecr.eu-west-1.amazonaws.com/repo"
Stages=$(cat $FilePath | grep -oP '^FROM .+ (AS|as) \K(.+)$')
CacheArgs=$(for Stage in $Stages; do echo "--cache-from $RepoURI:cache-$Stage"; done | paste -sd ' ')
BuildArgs="--file $FilePath $CacheArgs"
for Stage in $Stages; do docker pull $RepoURI:cache-$Stage || true; done
for Stage in $Stages; do docker build $BuildArgs --tag $RepoURI:cache-$Stage --target $Stage . || break; done
docker build $BuildArgs --tag $RepoURI:$ImageTag .
@themegabyte
themegabyte / keybindings.json
Created August 27, 2023 21:22
This JSON keybinding configuration sets up a key combination (Ctrl+Shift+L) to insert a snippet that creates a console.log statement containing the selected text, if any, alongside its value, in a VSCODE
// Place your key bindings in this file to override the defaults
[
{
"key": "ctrl+shift+l",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "console.log(\"${TM_SELECTED_TEXT}\", ${TM_SELECTED_TEXT});"
}
}
@themegabyte
themegabyte / replace-apt-mirror.md
Created October 18, 2023 15:03 — forked from yusufhm/replace-apt-mirror.md
replace default apt with au mirror using Vim or sed