Skip to content

Instantly share code, notes, and snippets.

@soulmachine
soulmachine / jwt-expiration.md
Last active April 9, 2024 04:12
How to deal with JWT expiration?

First of all, please note that token expiration and revoking are two different things.

  1. Expiration only happens for web apps, not for native mobile apps, because native apps never expire.
  2. Revoking only happens when (1) uses click the logout button on the website or native Apps;(2) users reset their passwords; (3) users revoke their tokens explicitly in the administration panel.

1. How to hadle JWT expiration

A JWT token that never expires is dangerous if the token is stolen then someone can always access the user's data.

Quoted from JWT RFC:

@mitchwongho
mitchwongho / dynamodb.java
Created May 8, 2021 09:48
#DynamoDB #JavaSDK #AWS
private Result getPeopleByGSI(@NotNull final String indexedReference, final String... attributes) {
// make reference the index
final DynamoDbIndex<People> index = DynamoUtil.peopleTable.index("someIndexedAttribute-index");
// Apply value to the indexed attribute (as the PartitionKey)
final QueryConditional queryConditional = QueryConditional.keyEqualTo(
Key.builder().partitionValue(indexedReference).build());
// Compose Filter expressions
final List<String> expressions = new ArrayList<>();
final Expression.Builder expressionBuilder = Expression.builder();
@diorahman
diorahman / client.html
Created December 26, 2011 03:34
Ajax, call jQuery POST to node.js expressjs
<html>
<head>
<title>jsonp test</title>
<script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(function(){
$('#select_link').click(function(e){
e.preventDefault();
console.log('select_link clicked');
@karmi
karmi / movie-titles.rb
Created January 13, 2013 20:42
Multiple analyzers and query fields in Elasticsearch for auto-completion
require 'tire'
# Tire.configure { logger STDERR, level: 'debug' }
Tire.index('movie-titles') do
delete
create \
settings: {
index: {
analysis: {
@kitek
kitek / gist:1579117
Created January 8, 2012 17:50
NodeJS create md5 hash from string
var data = "do shash'owania";
var crypto = require('crypto');
crypto.createHash('md5').update(data).digest("hex");
@avinashacco
avinashacco / rabbitMqInstallation
Created June 10, 2015 17:31
Install Rabbit MQ Server and GUI on Windows
Install Guide:
1. Download Rabbit MQ Server from
https://www.rabbitmq.com/download.html
2. Install the RabbitMQ Server
3. Open Console (set environment variable or open RabbitMQ CMD) and run the following command
rabbitmq-plugins enable rabbitmq_management
@DavidAnson
DavidAnson / common-markdown-mistakes.md
Last active March 7, 2024 04:57
A few common Markdown mistakes

The following snippets show some common Markdown mistakes.

Click the Raw button to see the source text and understand the author's intent.

GitHub's parser handles some of these cases; other parsers do not.

To catch these problems automatically:

@yyx990803
yyx990803 / nl.sh
Last active March 5, 2024 01:24
npm list only top level modules.
alias ng="npm list -g --depth=0 2>/dev/null"
alias nl="npm list --depth=0 2>/dev/null"
@joshnuss
joshnuss / app.js
Last active March 4, 2024 00:01
Express.js role-based permissions middleware
// the main app file
import express from "express";
import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db)
import authenticate from "./authentication"; // middleware for doing authentication
import permit from "./authorization"; // middleware for checking if user's role is permitted to make request
const app = express(),
api = express.Router();
// first middleware will setup db connection
@susimsek
susimsek / ExecutionTimeAdvice.java
Last active January 26, 2024 22:27
Spring Boot Measure Execution Time using Spring AOP
@Aspect
@Component
@Slf4j
@ConditionalOnExpression("${aspect.enabled:true}")
public class ExecutionTimeAdvice {
@Around("@annotation(TrackExecutionTime)")
public Object executionTime(ProceedingJoinPoint point) throws Throwable {
long startTime = System.currentTimeMillis();
Object object = point.proceed();