Skip to content

Instantly share code, notes, and snippets.

View jemikanegara's full-sized avatar

Jemika Negara jemikanegara

View GitHub Profile
@Kartones
Kartones / postgres-cheatsheet.md
Last active July 30, 2024 09:33
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@detrohutt
detrohutt / initClient.js
Last active January 23, 2020 02:21
zeit/next.js/examples/with-apollo/lib/initClient.js -- changed to support subscriptions
import { ApolloClient, createNetworkInterface } from 'react-apollo'
import { SubscriptionClient, addGraphQLSubscriptions } from 'subscriptions-transport-ws'
const uri = 'http://localhost:4000/graphql'
const subscriptionsURI = 'ws://localhost:4000/'
let apolloClient = null
function _initClient (headers, initialState, subscriptionsInterface) {
return new ApolloClient({
initialState,
@ereli
ereli / countries.sql
Last active July 30, 2024 12:39 — forked from adhipg/countries.sql
Sql dump of all the Countries, Country Codes, Phone codes. PostgreSQL compatible
CREATE SEQUENCE country_seq;
CREATE TABLE IF NOT EXISTS country (
id int NOT NULL DEFAULT NEXTVAL ('country_seq'),
iso char(2) NOT NULL,
name varchar(80) NOT NULL,
nicename varchar(80) NOT NULL,
iso3 char(3) DEFAULT NULL,
numcode smallint DEFAULT NULL,
phonecode int NOT NULL,
@soulmachine
soulmachine / jwt-expiration.md
Last active June 21, 2024 14:09
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:

@heri16
heri16 / 0-s3-multiple-get.html
Last active October 22, 2020 10:50
Browser Download Multiple Files into ZIP with S3 GetObject (Pure Client-side)
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Saving multiple files as zip</title>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.773.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/amazon-cognito-identity-js@4.4.0/dist/amazon-cognito-identity.min.js"></script>
<script src="https://gist.githubusercontent.com/heri16/d4e325a13c3e57f7e24ada1f7c459843/raw/events.js"></script>
@heri16
heri16 / secure-random-legacy.js
Last active October 31, 2020 11:07
Shortest secure mixed-password generator - Easy to audit CSPRNG crypto.getRandomValues() with no bias
// Special chars from https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-policies.html
const validUppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const validLowercase = 'abcdefghijklmnopqrstuvwxyz';
const validNumber = '0123456789';
const validSpecial = '^$*.[]{}()?"!@#%&/\\,><\':;|_~\`';
const validChars = validSpecial + validUppercase + validLowercase + validNumber;
// See: https://javascript.info/regular-expressions
const regexpUppercase = new RegExp(`[${validUppercase}]`, 'g');
const regexpLowercase = new RegExp(`[${validLowercase}]`, 'g');
@heri16
heri16 / s3-bucket-cors.xml
Last active October 20, 2020 14:03
Complete CORS Config for AWS S3 Bucket
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>https://*</AllowedOrigin>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
@heri16
heri16 / s3-bucket-cors.xml
Last active November 18, 2020 05:28
S3 Fetch Folder to Zip file with aws-sdk-js
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>https://*</AllowedOrigin>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
@heri16
heri16 / filter.js
Last active October 30, 2020 12:33
AWS Lambda to filter CloudTrail management logs in S3 (before Athena)
const { chain } = require('stream-chain');
const { parser } = require('stream-json');
const { pick } = require('stream-json/filters/Pick');
const { filter } = require('stream-json/filters/Filter');
const { streamValues } = require('stream-json/streamers/StreamValues');
const { disassembler } = require('stream-json/Disassembler');
const { stringer } = require('stream-json/Stringer');
const ST = require('stream-template');
@heri16
heri16 / App.jsx
Last active November 12, 2020 13:10
Lightweight Authenticator Component for Aws-Amplify
import React from 'react'
import { Switch, Route } from 'react-router-dom'
import { Amplify } from '@aws-amplify/core'
import { amplifyConfig } from './config'
import { AllContextProvider } from './context'
import {