Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢
I may be slow to respond.

Vaibhav Pandey vaibhavpandeyvpz

🐢
I may be slow to respond.
View GitHub Profile
@vaibhavpandeyvpz
vaibhavpandeyvpz / certificates.sh
Last active Mar 17, 2021
Generate SHA-256 hashes from SSL's chain of trust for a domain.
View certificates.sh
#!/bin/bash
CERTIFICATES=`openssl s_client -servername $1 -host $1 -port 443 -showcerts </dev/null 2>/dev/null | sed -n '/Certificate chain/,/Server certificate/p'`
CURSOR=$CERTIFICATES
while [[ "$CURSOR" =~ '-----BEGIN CERTIFICATE-----' ]]
do
CERTIFICATE="${CURSOR%%-----END CERTIFICATE-----*}-----END CERTIFICATE-----"
CURSOR=${CURSOR#*-----END CERTIFICATE-----}
echo `echo "$CERTIFICATE" | grep 's:' | sed 's/.*s:\(.*\)/\1/'`
@vaibhavpandeyvpz
vaibhavpandeyvpz / pu2s3.php
Last active Mar 17, 2021
Upload files from public (or any) disk to AWS S3 in Laravel without using any external tools.
View pu2s3.php
<?php
use Illuminate\Support\Facades\Storage;
$public = Storage::disk('public');
$s3 = Storage::disk('s3');
$files = $public->files(null, true);
foreach ($files as $file) {
@vaibhavpandeyvpz
vaibhavpandeyvpz / TimelineView.java
Last active Apr 21, 2021
Class that display video frames in a timeline-like manner. To be used at later point in time when developing a video trimmer.
View TimelineView.java
package com.vaibhavpandey.trimview;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.media.MediaMetadataRetriever;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Build;
@vaibhavpandeyvpz
vaibhavpandeyvpz / GifBuilder.kt
Last active Jul 26, 2020
Create animated GIFs using square/gifencoder
View GifBuilder.kt
import android.graphics.Bitmap
import com.squareup.gifencoder.*
import java.io.File
import java.io.OutputStream
import java.util.concurrent.TimeUnit
class GifBuilder(file: File,
width: Int,
height: Int,
private val delay: Long = 250,
@vaibhavpandeyvpz
vaibhavpandeyvpz / ResumableTimer.kt
Created Jul 14, 2020
Countdown timer for Android, support pause & resume functions.
View ResumableTimer.kt
import android.os.Handler
import java.util.concurrent.TimeUnit
class ResumableTimer(
private var duration: Long, // in milliseconds
private var delay: Long = TimeUnit.SECONDS.toMillis(1), // in milliseconds
private val listener: OnCountDownListener?
) {
View SwipeableCameraView.kt
import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import com.otaliastudios.cameraview.CameraView
import kotlin.math.abs
class SwipeableCameraView(context: Context, attributes: AttributeSet) : CameraView(context, attributes) {
View WavHeader.kt
import java.io.IOException
import java.io.OutputStream
class WavHeader (
private val format: Int = 0,
private val channels: Int = 0,
private val hertz: Int = 0,
private val bitrate: Int = 0,
private val size: Int = 0
) {
@vaibhavpandeyvpz
vaibhavpandeyvpz / ContentUriUtil.kt
Created Jul 12, 2020
Get file path from Uri when using Intent.ACTION_GET_CONTENT
View ContentUriUtil.kt
package the.example.app
import android.content.ContentUris
import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.DocumentsContract
import android.provider.MediaStore
@vaibhavpandeyvpz
vaibhavpandeyvpz / encrypt.cpp
Last active Apr 27, 2020
AES-256-CBC encryption in Qt with OpenSLL
View encrypt.cpp
#include <QCryptographicHash>
#include <QRandomGenerator>
#include <QStringList>
#include <openssl/conf.h>
#include <openssl/evp.h>
#include "SecurityUtil.h"
static char *bytes2chara(const QByteArray &bytes) {
auto size = bytes.size() + 1;
auto data = new char[size];
@vaibhavpandeyvpz
vaibhavpandeyvpz / facebook.py
Created Apr 19, 2020
Use Facebook's Graph API with Python.
View facebook.py
import facebook
import os
import requests
APP_ID = os.getenv('FACEBOOK_APP_ID')
APP_SECRET = os.getenv('FACEBOOK_APP_SECRET')
LLT_ENDPOINT = 'https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id=%s&client_secret' \
'=%s&fb_exchange_token=%s '