Skip to content

Instantly share code, notes, and snippets.

View hanzlahabib's full-sized avatar
:electron:
I may be slow to respond.

hanzla habib hanzlahabib

:electron:
I may be slow to respond.
View GitHub Profile
@hanzlahabib
hanzlahabib / readme.md
Created November 4, 2024 09:03 — forked from slava-vishnyakov/readme.md
How to upload images with TipTap editor
  1. Create a file Image.js from the source below (it is almost a copy of Image.js from tiptap-extensions except that it has a constructor that accepts uploadFunc (function to be called with image being uploaded) and additional logic if(upload) { ... } else { ... previous base64 logic .. } in the new Plugin section.
import {Node, Plugin} from 'tiptap'
import {nodeInputRule} from 'tiptap-commands'

/**
 * Matches following attributes in Markdown-typed image: [, alt, src, title]
 *
@hanzlahabib
hanzlahabib / auth.ts
Last active October 2, 2024 12:37
NextJS Keycloak Auth provider configuration
import {
GetServerSidePropsContext,
NextApiRequest,
NextApiResponse,
} from 'next'
import { getServerSession, type NextAuthOptions } from 'next-auth'
import { JWT } from 'next-auth/jwt'
import KeycloakProvider from 'next-auth/providers/keycloak'
async function refreshAccessToken(token: JWT) {
@hanzlahabib
hanzlahabib / private_fork.md
Created October 25, 2022 09:37 — forked from 0xjac/private_fork.md
Create a private fork of a public repository

The repository for the assignment is public and Github does not allow the creation of private forks for public repositories.

The correct way of creating a private frok by duplicating the repo is documented here.

For this assignment the commands are:

  1. Create a bare clone of the repository. (This is temporary and will be removed so just do it wherever.)

git clone --bare [email protected]:usi-systems/easytrace.git

@hanzlahabib
hanzlahabib / event-handler.js
Created February 21, 2021 17:58 — forked from eh3rrera/event-handler.js
Code for the event handler of a PubNub Block that returns the base64 representation of the QR code of an URL
/*
SAMPLE PAYLOAD
{
"url": "https://google.com"
}
*/
// https://gist.github.com/jonleighton/958841
const base64ArrayBuffer = function(arrayBuffer) {
var base64 = '';
var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
@hanzlahabib
hanzlahabib / Socket.io-load-test.js
Last active August 9, 2020 16:52 — forked from jmyrland/test.js
Socket-io load test?
/**
* Modify the parts you need to get it working.
*/
var should = require('should');
var request = require('../node_modules/request');
var io = require('socket.io-client');
var serverUrl = 'http://localhost';
import VeeValidate from 'vee-validate';
Vue.use(VeeValidate);
VeeValidate.Validator.extend('verify_password', {
getMessage: field => `The password must contain at least: 1 uppercase letter, 1 lowercase letter, 1 number, and one special character (E.g. , . _ & ? etc)`,
validate: value => {
var strongRegex = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})");
return strongRegex.test(value);
}
});
@hanzlahabib
hanzlahabib / axios-catch-error.js
Created June 20, 2020 14:45 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
@hanzlahabib
hanzlahabib / namespaceComponent1.vue
Last active March 29, 2020 21:06 — forked from hootlex/Component.vue
How to use a namespaced action in a Vue.js component
<template>
<div>
<button @click="actionMethod">Increment</button>
</div>
</template>
<script>
import { mapActions } from 'vuex'
export default{
methods: {
@hanzlahabib
hanzlahabib / pre-commit-hook
Created February 7, 2020 16:42
my pre-commit implementation of linting and formatting code
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by git-commit with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, make this file executable.
# This is slightly modified from Andrew Morton's Perfect Patch.
@hanzlahabib
hanzlahabib / generators.js
Created February 7, 2020 16:37
tried to explain how `yield` keyword play role in javaScript Generator functions
function *getMeDrink() {
let question1 = yield 'soda or beer' // execution will pause here because of yield
if (question1 == 'soda') {
return 'here you get your soda'
}
if (question1 == 'beer') {
let question2 = yield 'Whats your age' // execution will pause here because of yield
if (question2 > 18) {