Skip to content

Instantly share code, notes, and snippets.

View srdjanRakic's full-sized avatar

Srdjan Rakic srdjanRakic

View GitHub Profile
@srdjanRakic
srdjanRakic / jwt-decode.cs
Created July 6, 2018 11:52
How to decode JWT token
using System.IdentityModel.Tokens;
// a sample jwt encoded token string which is supposed to be extracted from 'Authorization' HTTP header in your Web Api controller
var tokenString = "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSJ9.eyJhdWQiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC8wMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJpYXQiOiIxNDI4MDM2NTM5IiwibmJmIjoiMTQyODAzNjUzOSIsImV4cCI6IjE0MjgwNDA0MzkiLCJ2ZXIiOiIxLjAiLCJ0aWQiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJhbXIiOiJwd2QiLCJvaWQiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJlbWFpbCI6Impkb2VAbGl2ZS5jb20iLCJwdWlkIjoiSm9obiBEb2UiLCJpZHAiOiJsaXZlLmNvbSIsImFsdHNlY2lkIjoiMTpsaXZlLmNvbTowMDAwMDAwMDAwMDAwMDAwIiwic3ViIjoieHh4eHh4eHh4eHh4eHh4eC15eXl5eSIsImdpdmVuX25hbWUiOiJKb2huIiwiZmFtaWx5X25hbWUiOiJEb2UiLCJuYW1lIjoiSm9obiBEb2UiLCJncm91cHMiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJ1bmlxdWVfbmFtZSI6ImxpdmUuY29tI2pkb2VAbGl2ZS5jb2
@srdjanRakic
srdjanRakic / vsCodeUserSettings.js
Last active June 15, 2022 09:06
Personal VS Code User Settings
{
"workbench.startupEditor": "none",
"workbench.sideBar.location": "right",
"editor.fontFamily": "Fira Code, Menlo, Monaco, 'Courier New', monospace",
"editor.fontSize": 17,
"editor.suggestFontSize": 16,
"editor.suggestLineHeight": 28,
"editor.renderWhitespace": "all",
"editor.fontLigatures": true,
"editor.lineHeight": 25,
@srdjanRakic
srdjanRakic / syncMultiplePromises.js
Created August 13, 2018 18:46
Sync up multiple Promises to a single result set
fetchData = () => {
const urls = [
"https://jsonplaceholder.typicode.com/posts/1",
"https://jsonplaceholder.typicode.com/posts/2",
"https://jsonplaceholder.typicode.com/posts/3",
"https://jsonplaceholder.typicode.com/posts/4",
"https://jsonplaceholder.typicode.com/posts/5",
"https://jsonplaceholder.typicode.com/posts/6",
"https://jsonplaceholder.typicode.com/posts/7",
"https://jsonplaceholder.typicode.com/posts/8"
@srdjanRakic
srdjanRakic / docker-help.md
Created August 20, 2018 19:48
Docker Commands, Help & Tips

Docker Commands, Help & Tips

Show commands & management commands

$ docker

Docker version info

@srdjanRakic
srdjanRakic / sentryProdConfig.html
Created August 25, 2018 17:31
Sentry Prod. Config
<% if (process.env.NODE_ENV == 'production') { %>
<script src="https://cdn.ravenjs.com/3.26.2/raven.min.js" crossorigin="anonymous"></script>
<script>Raven.config('https://ba44729431a044d6915d8012e94d8a56@sentry.io/1230983', {
environment: "%NODE_ENV%",
}).install();
</script>
<% } %>

<gitlab issue id>/<type>/<name>

<gitlab issue id>

Issue id generated by Github/GitLab.

<type>

bug - Code changes linked to a known issue
@srdjanRakic
srdjanRakic / squash-all-git-history.md
Created October 4, 2018 12:07
Squash all git history into a single commit

git reset $(git commit-tree HEAD^{tree} -m 'Initial commit')

@srdjanRakic
srdjanRakic / module-development-workflow.md
Created October 8, 2018 14:54
A suggested module development workflow

Module Development Workflow

Overview

This is a suggested workflow for building npm modules locally. The particular context will be focused on building a React component lib, but the workflow can be applied for any npm module.

Linking

yarn link is a really great tool for local development. It builds a global npm module that is symlinked to your local repo. So when you make a change to the repo, the global module is automatically updated.

NOTE

_yarn link and npm link do the same thing, but store the global module in a different location.

@srdjanRakic
srdjanRakic / nextEvent.js
Last active December 28, 2018 08:05
`nextEvent()` function: gives you a promise for the next event of a certain type. Really nice in conjunction with async/await.
function nextEvent(target, name) {
return new Promise(resolve => {
target.addEventListener(name, resolve, { once: true });
});
}
// Example with getUserMedia()
const stream = await navigator.mediaDevices.getUserMedia({
video: true,
@srdjanRakic
srdjanRakic / refactor-conditionals.js
Last active January 31, 2019 13:25
Using object literals instead of long conditionals or switch statements
function getMsg(val) {
if (val === 'x') {
return 'y';
} else if (val === 'y') {
return 'x';
} else if (val === 'a') {
return 'b';
} else {
return '';
}