Skip to content

Instantly share code, notes, and snippets.

@n1snt
n1snt / Oh my ZSH with zsh-autosuggestions zsh-syntax-highlighting zsh-fast-syntax-highlighting and zsh-autocomplete.md
Last active April 24, 2025 13:33
Oh my ZSH with zsh-autosuggestions zsh-syntax-highlighting zsh-fast-syntax-highlighting and zsh-autocomplete.md

Oh my zsh.

Oh My Zsh

Install ZSH.

sudo apt install zsh-autosuggestions zsh-syntax-highlighting zsh

Install Oh my ZSH.

@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();
@susimsek
susimsek / ExecutionTimeAdvice.java
Last active September 6, 2024 17:21
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();
@Tynael
Tynael / README.md
Last active April 11, 2025 07:03
How to use npx to run gist based scripts
@soulmachine
soulmachine / jwt-expiration.md
Last active April 10, 2025 12:28
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:

@lucasscariot
lucasscariot / model-user.js
Last active October 27, 2024 00:48
Composite Primary Key in Sequelize
/*
* Migration
*/
'use strict';
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.createTable('Users', {
firstName: {
type: Sequelize.STRING
},
@beaucharman
beaucharman / throttle.js
Last active November 12, 2022 15:39
An ES6 implementation of the throttle function. "Throttling enforces a maximum number of times a function can be called over time. As in 'execute this function at most once every 100 milliseconds.'" - CSS-Tricks (https://css-tricks.com/the-difference-between-throttling-and-debouncing/)
function throttle(callback, wait, immediate = false) {
let timeout = null
let initialCall = true
return function() {
const callNow = immediate && initialCall
const next = () => {
callback.apply(this, arguments)
timeout = null
}
@lagner
lagner / percentile.js
Created May 16, 2016 18:23 — forked from IceCreamYou/percentile.js
Utility functions to calculate percentiles and percent ranks in a JavaScript array.
// Returns the value at a given percentile in a sorted numeric array.
// "Linear interpolation between closest ranks" method
function percentile(arr, p) {
if (arr.length === 0) return 0;
if (typeof p !== 'number') throw new TypeError('p must be a number');
if (p <= 0) return arr[0];
if (p >= 1) return arr[arr.length - 1];
var index = arr.length * p,
lower = Math.floor(index),
@hasantayyar
hasantayyar / netcat-pv.sh
Last active February 17, 2025 10:00
send files over netcat with progressbar
# sudo apt-get install pv
$ pv app.js | nc 192.168.1.123 10000
@msbaek
msbaek / ConvertFromOneObjectToAnotherTest.java
Created November 14, 2015 09:01
convert one object to another object by using Function in guava
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;
import lombok.Data;
import org.junit.Test;
import java.math.BigDecimal;
import java.util.List;
@Data