Skip to content

Instantly share code, notes, and snippets.

@arifmahmudrana
arifmahmudrana / joi-locale.ts
Created January 21, 2020 13:05
joi localization internationalization error messages
import { object, string, number, ValidationError } from '@hapi/joi';
const schema = object({
searchCode: string()
.required()
.label('Search code'),
id: number().required()
}),
messages = {
'alternatives.all': '{{#label}} does not match all of the required types',
@slashthinking
slashthinking / jwtparser.js
Created June 20, 2015 09:39
Extracting claims from a JWT
// Helper function to extract claims from a JWT. Does *not* verify the
// validity of the token.
// credits: https://github.com/firebase/angularFire/blob/master/angularFire.js#L370
// polyfill window.atob() for IE8: https://github.com/davidchambers/Base64.js
// or really fast Base64 by Fred Palmer: https://code.google.com/p/javascriptbase64/
function deconstructJWT(token) {
var segments = token.split(".");
if (!segments instanceof Array || segments.length !== 3) {
throw new Error("Invalid JWT");
}
@tevino
tevino / fix_virtualenv
Last active March 24, 2024 09:41
Fix python virtualenv after python update
#!/usr/bin/env bash
ENV_PATH="$(dirname "$(dirname "$(which pip)")")"
SYSTEM_VIRTUALENV="$(which -a virtualenv|tail -1)"
BAD_ENV_PATHS="/usr/local"
echo "Ensure the root of the broken virtualenv:"
echo " $ENV_PATH"
@darklow
darklow / celery_tasks_error_handling.py
Last active April 20, 2024 16:25
Celery tasks error handling example
from celery import Task
from celery.task import task
from my_app.models import FailedTask
from django.db import models
@task(base=LogErrorsTask)
def some task():
return result
class LogErrorsTask(Task):