Skip to content

Instantly share code, notes, and snippets.

View vaibhavpandeyvpz's full-sized avatar
🐢
I may be slow to respond.

Vaibhav Pandey vaibhavpandeyvpz

🐢
I may be slow to respond.
View GitHub Profile
@vaibhavpandeyvpz
vaibhavpandeyvpz / StrRev.java
Created June 23, 2024 08:32
One of my friend asked for a clean solution to an interview question he was asked i.e., "reverse alphabetical sequences in a string" in Java. Clean would ofcourse be using StringBuilder but I'm not if using too many built-ins (we using RegExp already) is allowed during tech interviews.
package com.vaibhavpandey;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class StrRev {
static Pattern AZ = Pattern.compile("[a-zA-Z]+");
static String reverse(String string) {
@vaibhavpandeyvpz
vaibhavpandeyvpz / embeddings.py
Created April 30, 2024 03:50
Generate word embeddings from sentences using "bge-large-en-v1.5" model.
from sentence_transformers import SentenceTransformer
EMBEDDING_MODEL = "BAAI/bge-large-en-v1.5"
model = SentenceTransformer(EMBEDDING_MODEL)
embeddings = model.encode(sentences=["Hey", "How are you?"], normalize_embeddings=True)
@vaibhavpandeyvpz
vaibhavpandeyvpz / Fingerprint.cs
Last active February 11, 2024 11:09
Generate unique device ID or fingerprint for licensing etc. on Windows based system.
using System;
using System.Linq;
using System.Management;
using System.Security.Cryptography;
using System.Text;
namespace DeviceID
{
internal class Fingerprint
{
@vaibhavpandeyvpz
vaibhavpandeyvpz / Dockerfile
Created September 22, 2023 11:16
Chromium's Docker image based on AlpineLinux
FROM alpine:3
RUN apk update && apk upgrade
RUN apk add --no-cache chromium chromium-chromedriver
RUN mkdir -p /usr/src/app \
&& adduser -D chromium \
&& chown -R chromium:chromium /usr/src/app
@vaibhavpandeyvpz
vaibhavpandeyvpz / infosec-iq-qa.js
Last active August 7, 2024 21:58
Complete a InfoSec institute course automatically.
function getCsrfToken() {
var parts = ('; ' + document.cookie)
.split("; csrf=");
if (parts.length === 2) {
const value = parts.pop().split(";").shift();
return decodeURIComponent(value);
}
}
function sendXhr(url, method, data = null, headers = {}) {
@vaibhavpandeyvpz
vaibhavpandeyvpz / e164_format.php
Last active May 26, 2022 04:24
Normalize phone number inputs from user to E.164 format.
<?php
/**
* @param string|null $number
* @return string|null
*/
function normalize_to_e164(?string $number): ?string
{
if (empty($number)) {
return null;
@vaibhavpandeyvpz
vaibhavpandeyvpz / Dockerfile.ms
Created May 13, 2022 04:27
Run Meilisearch server on Apple (M1) silicon using Docker, for Laravel
FROM ubuntu
WORKDIR /meilisearch
RUN apt-get update && \
apt-get install -y libc6-dev wget
RUN wget -O exe https://github.com/meilisearch/MeiliSearch/releases/download/v0.12.0/meilisearch-linux-armv8 && \
chmod a+x exe
@vaibhavpandeyvpz
vaibhavpandeyvpz / Button.jsx
Last active February 23, 2022 05:47
Creating themed components based on styled.div
import { darken, getLuminance } from 'polished';
import styled, { css } from 'styled-components';
const isDarkColor = color => getLuminance(color) <= .5;
const Button = styled.button`
background: white;
border: 1px solid black;
color: black;
cursor: pointer;
@vaibhavpandeyvpz
vaibhavpandeyvpz / HasUuidAsPrimaryKey.php
Created February 4, 2022 03:05
Generate and use UUIDs as primary keys in Laravel
<?php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
trait HasUuidAsPrimaryKey
{
public static function bootHasUuidAsPrimaryKey()
{
static::creating(function (Model $model) {
@vaibhavpandeyvpz
vaibhavpandeyvpz / 00-common-aws-policies.md
Last active February 22, 2022 05:01
Common policies for AWS/IAM

This Gist includes some of the common AWS/IAM policy examples to give granular access to users.