snippets added

This commit is contained in:
sankalp committed 2024-05-05 15:24:18 +05:45
1 parent 6c10ae3461
commit 2080230313
18 files changed
+1083 -16

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
snippet qq "qq"
q.Q(${1:})
${2}
snippet httphandler "http handler"
func $1(${2:w} http.ResponseWriter, ${3:r} *http.Request){
$0
}
snippet httpredir "http redirect"
http.Redirect(${1:w}, ${2:r}, \"${3:/}\", ${4:http.StatusFound})
snippet httperr "http error"
http.Error(${1:w}, ${2:err}.Error(), ${3:http.StatusInternalServerError})
snippet httpboil "http boilerplate"
package main
import (
"fmt"
"net/http"
"time"
)
func greet(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World! %s", time.Now())
}
func main() {
http.HandleFunc("/", greet)
http.ListenAndServe(":8080", nil)
}
snippet testfn "test function"
func Test$1(t *testing.T) {
$0
}
snippet testfnt "test table"
func Test$1(t *testing.T) {
testCases := []struct {
desc string
$2
}{
{
desc: \"$3\",
$4
},
}
for _, tC := range testCases {
tt.Run(tC.desc, func(t *testing.T) {
$0
})
}
}
snippet benchfn "benchmark"
func Benchmark$1(b *testing.B) {
for ${2:i} := 0; ${2:i} < b.N; ${2:i}++ {
$0
}
}
+25
View File
@@ -0,0 +1,25 @@
snippet boil "boilerplate"
<!DOCTYPE html>
<html lang="en">
<head>
<title>App</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script defer type="module" src="app.js"></script>
<link rel="stylesheet" type="text/css" href="style.css"></link>
</head>
<body>
$0
</body>
</html>
snippet basic
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
</body>
</html>
+298
View File
@@ -0,0 +1,298 @@
## Access Modifiers
snippet po
protected ${0}
snippet pu
public ${0}
snippet pr
private ${0}
##
## Annotations
snippet before
@Before
static void ${1:intercept}(${2:args}) { ${0} }
snippet mm
@ManyToMany
${0}
snippet mo
@ManyToOne
${0}
snippet om
@OneToMany${1:(cascade=CascadeType.ALL)}
${0}
snippet oo
@OneToOne
${1}
##
## Basic Java packages and import
snippet im
import ${0}
snippet j.b
java.beans.
snippet j.i
java.io.
snippet j.m
java.math.
snippet j.n
java.net.
snippet j.u
java.util.
##
## Class
snippet cl
class ${1:`vim_snippets#Filename("$1", "untitled")`} ${0}
snippet pcl
public class ${1:`vim_snippets#Filename("$1", "untitled")`} ${0}
snippet in
interface ${1:`vim_snippets#Filename("$1", "untitled")`} ${2:extends Parent}
snippet tc
public class ${1:`vim_snippets#Filename("$1")`} extends ${0:TestCase}
##
## Class Enhancements
snippet ext
extends ${0}
snippet imp
implements ${0}
##
## Comments
snippet /*
/*
* ${0}
*/
##
## Constants
snippet co
static public final ${1:String} ${2:var} = ${3};
snippet cos
static public final String ${1:var} = "${2}";
##
## Control Statements
snippet case
case ${1}:
${0}
snippet def
default:
${0}
snippet el
else
snippet eif
else if (${1}) ${0}
snippet if
if (${1}) ${0}
snippet sw
switch (${1}) {
${0}
}
##
## Create a Method
snippet m
${1:void} ${2:method}(${3}) ${4:throws }
##
## Create a Variable
snippet v
${1:String} ${2:var}${3: = null}${4};
##
## Declaration for ArrayList
snippet d.al
List<${1:Object}> ${2:list} = new ArrayList<$1>();${0}
## Declaration for HashMap
snippet d.hm
Map<${1:Object}, ${2:Object}> ${3:map} = new HashMap<$1, $2>();${0}
## Declaration for HashSet
snippet d.hs
Set<${1:Object}> ${2:set} = new HashSet<$1>();${0}
## Declaration for Stack
snippet d.st
Stack<${1:Object}> ${2:stack} = new Stack<$1>();${0}
##
## Singleton Pattern
snippet singlet
private static class Holder {
private static final ${1:`vim_snippets#Filename("$1")`} INSTANCE = new $1();
}
private $1() { }
public static $1 getInstance() {
return Holder.INSTANCE;
}
##
## Enhancements to Methods, variables, classes, etc.
snippet ab
abstract ${0}
snippet fi
final ${0}
snippet st
static ${0}
snippet sy
synchronized ${0}
##
## Error Methods
snippet err
System.err.print("${0:Message}");
snippet errf
System.err.printf("${1:Message}", ${0:exception});
snippet errln
System.err.println("${0:Message}");
##
## Exception Handling
snippet as
assert ${1:test} : "${2:Failure message}";
snippet ae
assertEquals("${1:Failure message}", ${2:expected}, ${3:actual});
snippet aae
assertArrayEquals("${1:Failure message}", ${2:expecteds}, ${3:actuals});
snippet af
assertFalse("${1:Failure message}", $2);
snippet at
assertTrue("${1:Failure message}", $2);
snippet an
assertNull("${1:Failure message}", ${2:object});
snippet ann
assertNotNull("${1:Failure message}", ${2:object});
snippet ass
assertSame("${1:Failure message}", ${2:expected}, ${3:actual});
snippet asns
assertNotSame("${1:Failure message}", ${2:expected}, ${3:actual});
snippet fa
fail("${1:Failure message}");
snippet ca
catch(${1:Exception} ${2:e}) ${0}
snippet thr
throw ${0}
snippet ths
throws ${0}
snippet try
try {
${0:${VISUAL}}
} catch(${1:Exception} ${2:e}) {
}
snippet tryf
try {
${0:${VISUAL}}
} catch(${1:Exception} ${2:e}) {
} finally {
}
##
## Find Methods
snippet findall
List<${1:listName}> ${2:items} = $1.findAll();
snippet findbyid
${1:var} ${2:item} = $1.findById(${3});
##
## Javadocs
snippet /**
/**
* ${0}
*/
snippet @au
@author `system("grep \`id -un\` /etc/passwd | cut -d \":\" -f5 | cut -d \",\" -f1")`
snippet @br
@brief ${0:Description}
snippet @fi
@file ${0:`vim_snippets#Filename("$1")`}.java
snippet @pa
@param ${0:param}
snippet @re
@return ${0:param}
##
## Logger Methods
snippet debug
Logger.debug(${1:param});
snippet error
Logger.error(${1:param});
snippet info
Logger.info(${1:param});
snippet warn
Logger.warn(${1:param});
##
## Loops
snippet enfor
for (${1} : ${2}) ${0}
snippet for
for (${1}; ${2}; ${3}) ${0}
snippet wh
while (${1:true}) ${0}
snippet wht
while (true) ${0}
##
## Main method
snippet psvm
public static void main (String[] args) {
${0}
}
snippet main
public static void main (String[] args) {
${0}
}
##
## Print Methods
snippet sout
System.out.println("${0}");
snippet serr
System.err.println(${0});
snippet print
System.out.print("${0:Message}");
snippet printf
System.out.printf("${1:Message}", ${0:args});
snippet println
System.out.println(${0});
snippet printlna
System.out.println(Arrays.toString(${0}));
##
## Render Methods
snippet ren
render(${1:param});
snippet rena
renderArgs.put("${1}", ${2});
snippet renb
renderBinary(${1:param});
snippet renj
renderJSON(${1:param});
snippet renx
renderXml(${1:param});
##
## Setter and Getter Methods
snippet set
${1:public} void set${3:}(${2:String} ${0:}){
this.$4 = $4;
}
snippet get
${1:public} ${2:String} get${3:}(){
return this.${0:};
}
##
## Terminate Methods or Loops
snippet re
return ${0}
snippet br
break;
##
## Test Methods
snippet t
public void test${1:Name}() throws Exception {
${0}
}
snippet test
@Test
public void test${1:Name}() throws Exception {
${0}
}
##
## Utils
snippet Sc
Scanner
##
## Miscellaneous
snippet action
public static void ${1:index}(${2:args}) { ${0} }
snippet rnf
notFound(${1:param});
snippet rnfin
notFoundIfNull(${1:param});
snippet rr
redirect(${1:param});
snippet ru
unauthorized(${1:param});
snippet unless
(unless=${1:param});
+19
View File
@@ -0,0 +1,19 @@
snippet bvstory "vue story"
import $1 from './$1.vue';
export default {
title: 'Components/$1',
component: $1,
};
const Template = (_, { argTypes }) => ({
components: { $1 },
props: Object.keys(argTypes),
template: '<$1 v-bind="$$props" />',
});
export const Default = Template.bind({});
Default.args = {
$0
};
+27
View File
@@ -0,0 +1,27 @@
extends javascript
snippet component
export default function $1(){
return <>$0</>;
}
snippet el
<$1>
$0
</$1>
snippet us "useState()"
const [$1, set${1/(.)/${1:/upcase}/}] = useState($0);
snippet ur "useRef()"
const $0 = useRef(null);
snippet ue "useEffect()"
useEffect(() => $0, []);
snippet um "useMemo()"
const $1 = useMemo(() => $0, []);
snippet uc "useCallback()"
const $1 = useCallback(() => $0, []);
+24
View File
@@ -0,0 +1,24 @@
snippet #!
#!/usr/bin/env lua
$1
snippet for
for ${1:i}=${2:1},${3:10} do
${0:print(i)}
end
snippet forp
for ${1:i},${2:v} in pairs(${3:table_name}) do
${0:-- body}
end
snippet fori
for ${1:i},${2:v} in ipairs(${3:table_name}) do
${0:-- body}
end
snippet fn "Create a local function"
local $1 = function($2)
$0
end
+54
View File
@@ -0,0 +1,54 @@
snippet boil "boilerplate"
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.ONESHELL:
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
.RECIPEPREFIX = >
.DEFAULT_GOAL = help
HOME := \${HOME}
UNAME = \$(shell uname -s | tr A-Z a-z)
HOSTNAME = \$(shell hostname)
SOURCE = \$(realpath \$(dir \$(realpath \$(lastword \$(MAKEFILE_LIST)))))
BLACK = \$(shell tput -Txterm setaf 0)
RED = \$(shell tput -Txterm setaf 1)
GREEN = \$(shell tput -Txterm setaf 2)
YELLOW = \$(shell tput -Txterm setaf 3)
BLUE = \$(shell tput -Txterm setaf 4)
MAGENTA = \$(shell tput -Txterm setaf 5)
CYAN = \$(shell tput -Txterm setaf 6)
WHITE = \$(shell tput -Txterm setaf 7)
RESET = \$(shell tput -Txterm sgr0)
define print_mod_start
@echo "╭── \$(1)"
endef
define print_mod
@echo "│ • \$(1)"
endef
define print_mod_end
@echo "╰──────"
endef
define link
\$(eval REL_SRC=\$(strip \$(1)))
\$(eval SRC=\$(SOURCE)/\$(strip \$(1)))
\$(eval LOG="\${RED}link\${RESET} \${MAGENTA}\$(REL_SRC)\${RESET} -> \${YELLOW}\$(strip \$(2)\${RESET})")
\$(call print_mod,"\$(LOG)")
@ln -fns \$(SRC) \$(2)
endef
help: ## help
> @grep --no-filename -E '^[a-zA-Z_0-9%-]+:.*?## .*\$\$' \$(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\${BLUE}%-20s\${RESET} %s\n", \$\$1, \$\$2}'
.PHONY: help
build: ## build
> @echo " 🔥 Building on \${YELLOW}☯ \$(HOSTNAME)\${RESET} \${MAGENTA}(\$(UNAME))\${RESET}"
> $(call print_mod_start,Link)
> \$(call link,src_path,dest_path)
> \$(call print_mod_end)
.PHONY: build
+34
View File
@@ -0,0 +1,34 @@
extends tex
snippet boil
---
layout: "@layouts/ArticleLayout.astro"
title: "$1"
description: "$1"
date: ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}
---
# $1
There I was, sitting in my chair, thinking about $1.
snippet te "Create an inline TeX block"
$$1$$0
snippet tex "Create a TeX block"
$$
$0
$$
snippet bo
__$1__$0
snippet it
_$1_$0
snippet link
[$1]($0)
snippet img
![$1]($0)
+2
View File
@@ -0,0 +1,2 @@
extends tex
+11
View File
@@ -0,0 +1,11 @@
snippet derive
#[derive(Debug$0)]
snippet les
let $1 = $2 else {
return $0;
}
snippet uvec
Vec::new()
+151
View File
@@ -0,0 +1,151 @@
snippet boil "boilerplace"
#!/usr/bin/env bash
set -uf -o pipefail
IFS=$'\n\t'
$0
snippet boil2 "Boilerplate" b
#!/usr/bin/env bash
set -euf -o pipefail
IFS=$'\n\t'
#/ Usage:
#/ Description:
#/ Examples:
#/ Options:
#/ --help: Display this help message
usage() {
grep '^#/' "\$0" | cut -c4-
exit 0
}
expr "$*" : ".*--help" > /dev/null && usage
echoerr() { printf "%s\n" "$*" >&2; }
info() { echoerr "[INFO] $*"; }
warning() { echoerr "[WARNING] $*"; }
error() { echoerr "[ERROR] $*"; }
fatal() {
echoerr "[FATAL] $*"
exit 1
}
cleanup() {
info "... cleaned up"
}
if [[ "\${BASH_SOURCE[0]}" = "\$0" ]]; then
trap cleanup EXIT
$0
fi
snippet scriptdir "get dir of current script"
DIR="$( cd "$(dirname "\${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
snippet arg_default "argument with default value"
ARG=\$\{1:-default\}
snippet arg_switch "getopts switch"
while getopts "hv" arg; do
case "\$arg" in
h) # help
show_help
exit 0
;;
v) # version
printf "%s\\n" "\$version"
exit 0
;;
*)
exit 1
esac
done
snippet if_empty "if empty"
if [ -z "$VAR" ]; then
true
fi
snippet if_not_empty "if not empty"
if [ -n "$VAR" ]; then
true
fi
snippet if_file "if file exists"
if [[ -f "$PATH" ]]; then
$0
fi
snippet if_dir "if dir exists"
if [[ -d "$PATH" ]]; then
$0
fi
snippet if_grep "if file contains"
if grep -q "$1" "$2"; then
$0
fi
snippet if_argc "if argument count"
if [ "$#" -eq $1 ]; then
$0
fi
echo $#
snippet if_not_argc "if not argument count"
if [ "$#" -ne $1 ]; then
$0
fi
echo $#
snippet if_numeric "check if numeric"
if printf "%s" "$1" | grep -Eq '^[+-]?[0-9]+$'; then
$0
fi
snippet if_tmux "if in tmux"
if printf "%s" "$TERM" | grep -Fq screen && test "$TMUX" ; then
$0
fi
snippet if_root "if not running as root"
if [[ $EUID -eq 0 ]]; then
$0
fi
snippet if_not_root "if not running as root"
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
snippet for_line_in_var "for line in variable"
while read -r LINE; do
printf 'line: %s\n' "$LINE"
done <<< "$VAR"
snippet for_file_rg "for file in rg match"
FILES=$(rg -e "^<<<<<<")
while IFS=: read -r FILE _; do
printf 'file: %s\n' "$FILE"
done <<< "$FILES"
snippet confirm "prompt user to confirm action"
read -p "$1" -n 1 -r
echo
if [[ \$REPLY =~ ^[Yy]$ ]]
then
$0
fi
snippet colors "use colors"
BLACK = $(shell tput -Txterm setaf 0)
RED = $(shell tput -Txterm setaf 1)
GREEN = $(shell tput -Txterm setaf 2)
YELLOW = $(shell tput -Txterm setaf 3)
BLUE = $(shell tput -Txterm setaf 4)
MAGENTA = $(shell tput -Txterm setaf 5)
CYAN = $(shell tput -Txterm setaf 6)
WHITE = $(shell tput -Txterm setaf 7)
RESET = $(shell tput -Txterm sgr0)
+305
View File
@@ -0,0 +1,305 @@
# -- SNIPPETS --
#
# new glossary entry
snippet gloss "Glossary Entry" b
\newglossaryentry{${1:entry}}{
name = {${2:name}},
symbol = {\ensuremath{${3:symbol}}},
description = {${4:description}}
}
#
# custom theorem enviornment
snippet customthm "Custom Theorem" b
\vspace{.1in}
\begin{customthm}{(${1:label})}
${2:claim}
\end{customthm}
\begin{Answer}
${0}
\end{Answer}
#
# framed text enviornment
snippet textbox "Text Box" b
\begin{tcolorbox}
${0}
\end{tcolorbox}
#
# new command
snippet nc "New Command" b
\newcommand{${1:cmd}}[${2:opt}]{${3:realcmd}} ${0}
#
#usepackage
snippet up "Use Package" b
\usepackage[${1:options}]{${2:package}} ${0}
#
# \begin{}...\end{}
snippet begin "Begin End"
\begin{${1:env}}
${2:${VISUAL}}
\end{$1}${0}
#
# Align(ed)
snippet align "Align Env" b
\begin{align${1:ed}}
\label{${2:name}}
${0}
\end{align$1}
#
# Quote
snippet quote "Quotation" b
\vspace{-.1in}
\begin{quote}\singlespacing\small
${0}
\hfill(p.~${1})
\end{quote}
\vspace{.1in}
#
# Labelalign
snippet labelalign "Label Align" b
\vspace{.05in}
\begin{labelalign} %\small\onehalfspacing
\item[${2:\it} ${3:Label:}] ${0}
\end{labelalign}
\vspace{.05in}
#
# Enumerate
snippet enum "Enumerate" b
\begin{enumerate}
\item[${1:\it }${2:Label:}] ${0}
\end{enumerate}
#
# Itemize
snippet item "Itemize" b
\begin{itemize}
\item[${1:\it} ${2:Label:}] ${0}
\end{itemize}
#
#Item
snippet i "Item"
\item[${1:\it} ${2:Label:}] ${0}
#
# Cases
snippet case "Cases"
${1:LHS}=
\begin{cases}
${2:Value}, &\text{ if } ${3:case}\\
${4:Value}, &\text{ otherwise.} ${5:otherwise}.
\end{cases}${0}
#
# Section
snippet sec "Section" b
\section{${1:Name}}%
\label{sec:${2:$1}}
${0}
#
# Sub Section
snippet sub "Sub Section" b
\subsection{${1:Name}}%
\label{sub:${2:$1}}
${0}
#
# Sub Sub Section
snippet ssub "Sub Sub Section" b
\subsubsection{${1:Name}}%
\label{sub:${2:$1}}
${0}
#
# Hyper Section
snippet hsec "Hyper Section" b
\hypsection{${1:Name}}%
\label{sec:${2:$1}}
${0}
#
# Hyper Sub Section
snippet hsub "Hyper Sub Section" b
\hypsubsection{${1:Name}}%
\label{sub:${2:$1}}
${0}
#
# Hyper Sub Sub Section
snippet hssub "Hyper Sub Sub Section" b
\hypsubsubsection{${1:Name}}%
\label{sub:${2:$1}}
${0}
#
#Formating text: italic, bold, underline, small capital, emphase ..
snippet it "Italics" wi
\textit{${1}}${0}
#
snippet tt "Teletype" wi
\texttt{${1}}${0}
#
snippet bf "Bold" wi
\textbf{${1}}${0}
#
snippet sc "Small Caps" wi
\textsc{${1}}${0}
#
snippet tsub "Subscripted" i
\textsubscript{${1}}${0}
#
snippet tsup "Superscripted" i
\textsuperscript{${1}}${0}
#
#Math font
snippet mf "Mathfrak" w
\mathfrak{${1}}${0}
#
snippet mc "Mathcal" w
\mathcal{${1}}${0}
#
snippet ms "Mathscr" w
\mathscr{${1}}${0}
#
#misc
snippet fproof "Footnote Proof" bi
\footnote{\textit{Proof:} ${1:Begin} \qed}${0}
#
snippet lab "Label" wi
\label{${1:LABEL}}${0}
#
snippet fn "Footnote" wi
\footnote{${1:FOOTNOTE}}${0}
#
snippet fig "Figure environment" b
\begin{figure}
\begin{center}
\includegraphics[scale=${1}]{Figures/${2}}
\end{center}
\caption{${3}}
\label{fig:${4}}
\end{figure}
${0}
#
snippet tikz "Tikz environment" b
\begin{figure}[htpb]
\begin{center}
\begin{tikzpicture}[scale=${1:1}, transform shape]
${2}
\end{tikzpicture}
\end{center}
\caption{${3}}%
\label{fig:${4}}
\end{figure}
${0}
snippet lemma "Lemma" bi
\begin{lemma}
${0:${VISUAL}}
\end{lemma}
snippet prop "Proposition" bi
\begin{prop}[$1]
${0:${VISUAL}}
\end{prop}
snippet thrm "Theorem" bi
\begin{theorem}[$1]
${0:${VISUAL}}
\end{theorem}
snippet prf "Proof" bi
\begin{myproof}[$1]
${0:${VISUAL}}
\end{myproof}
snippet def "Definition" bi
\begin{definition}[$1]
${0:${VISUAL}}
\end{definition}
snippet prob "Problem" bi
\begin{problem}[$1]
${0:${VISUAL}}
\end{problem}
snippet corl "Corollary" bi
\begin{corollary}[$1]
${0:${VISUAL}}
\end{corollary}
snippet example "Example" bi
\begin{example}[$1]
${0:${VISUAL}}
\end{example}
snippet matrix
\begin{bmatrix}$0\end{bmatrix}
snippet vec
\vec{$0}
snippet frac
\frac{$1}{$0}
snippet ra "→"
\rightarrow
snippet la "←"
\leftarrow
snippet det "det(A)"
\text{det}($1)$0
snippet hat
\hat{$1}$0
snippet it
\textit{$1}$0
snippet bo
\textbf{$1}$0
snippet bq
\begin{quote}
$0
\end{quote}
snippet ci
\cite{$1}$0
snippet pc
\parencite{$1}$0
snippet cy
\cite*{$1}$0
snippet pcy
\parencite*{$1}$0
snippet se
\section{$1}$0
+1
View File
@@ -0,0 +1 @@
extends javascript
+40
View File
@@ -0,0 +1,40 @@
snippet boil "react component"
import React from "react";
interface $1Props {
}
const $1 = ({$2}: $1Props) => {
return $0;
};
export { $1 };
export default $1;
snippet bstory "react fixture"
import React from "react";
import { ComponentStory, ComponentMeta } from '@storybook/react';
import $1 from "./$1";
export default {
title: '$1',
component: $1,
argTypes: {
// https://storybook.js.org/docs/react/api/argtypes
backgroundColor: { control: 'color' },
onClick: { action: "clicked" },
},
} as ComponentMeta<typeof $1>;
// https://storybook.js.org/docs/react/writing-stories/introduction#using-args
const Template: ComponentStory<typeof $1> = (args) => <$1 {...args} />;
export const Default = Template.bind({});
// https://storybook.js.org/docs/react/writing-stories/args
Default.args = {
primary: true,
label: '$1',
};
+14
View File
@@ -0,0 +1,14 @@
snippet boil "boilerplate"
<template>
<div>$0</div>
</template>
<script>
export default {
name: "$1"
}
</script>
<style lang="scss" scoped>
</style>