Skip to content

Instantly share code, notes, and snippets.

View eAmin's full-sized avatar
:octocat:

Amin Akbari eAmin

:octocat:
View GitHub Profile
@eAmin
eAmin / README.md
Last active November 25, 2022 14:19 — forked from JLarky/README.md
Ultimate example of react context hook with nice type-safe (TypeScript) wrappers and reduced boilerplate by using `ReturnType`
@eAmin
eAmin / index.jsx
Created November 21, 2022 11:54 — forked from abinavseelan/index.jsx
(Full) Github-style user suggestions using react-input-trigger
import React, { Component } from 'react';
import { render } from 'react-dom';
import InputTrigger from 'react-input-trigger';
class App extends Component {
constructor() {
this.state = {
top: null,
left: null,
showSuggestor: false,
@eAmin
eAmin / nginxproxy.md
Created October 24, 2020 22:06 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@eAmin
eAmin / perfectelementary.bash
Created October 13, 2020 05:26 — forked from ezeeyahoo/perfectelementary.bash
HowTo Install the perfect Elementary-OS
#Download Elementary OS from here:
#https://elementary.io/
#Clean-up System
sudo apt-get purge midori-granite -y
sudo apt-get purge yelp -y
sudo apt-get purge evince -y
sudo apt-get purge gnome-orca -y
sudo apt-get autoremove -y
sudo apt-get autoclean -y
@eAmin
eAmin / prng.js
Created May 6, 2020 09:15 — forked from lpinca/prng.js
Pseudorandom number generator based on crypto.randomBytes
var crypto = require('crypto')
, rrange = 4294967296;
/**
* Return an integer, pseudo-random number in the range [0, 2^32).
*/
var nextInt = function() {
return crypto.randomBytes(4).readUInt32BE(0);
};
@eAmin
eAmin / jwt-expiration.md
Created March 7, 2020 23:30 — forked from soulmachine/jwt-expiration.md
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:

@eAmin
eAmin / util.js
Last active August 12, 2019 22:19
Tweet sized English number to Persian converter and vice versa.
/**
* Tweet sized English number to Persian converter and vice versa.
* You can find out old and obsolete version in here: https://gist.github.com/eAmin/786108
* by Amin Akbari
* MIT License
*/
/**
* Convert English numbers to Persian
*
@eAmin
eAmin / random.md
Created December 16, 2018 23:23 — forked from joepie91/random.md
Secure random values (in Node.js)

Not all random values are created equal - for security-related code, you need a specific kind of random value.

A summary of this article, if you don't want to read the entire thing:

  • Don't use Math.random(). There are extremely few cases where Math.random() is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.
  • Don't use crypto.getRandomBytes directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.
  • If you want to generate random tokens or API keys: Use uuid, specifically the uuid.v4() method. Avoid node-uuid - it's not the same package, and doesn't produce reliably secure random values.
  • If you want to generate random numbers in a range: Use random-number-csprng.

You should seriously consider reading the entire article, though - it's

@eAmin
eAmin / disable-suspend.md
Created December 15, 2018 09:54 — forked from bzerangue/disable-suspend.md
Disable Sleep/Suspend and WiFi in Ubuntu 16.04 LTS

On Ubuntu 16.04 LTS, I successfully used the following to disable suspend:

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

And this to re-enable it:

sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

@eAmin
eAmin / download.js
Created August 22, 2018 22:46 — forked from falkolab/download.js
Download file by http with progress (NodeJS)
function download(fileUrl, apiPath, callback) {
var url = require('url'),
http = require('http'),
p = url.parse(fileUrl),
timeout = 10000;
var file = fs.createWriteStream(apiPath);
var timeout_wrapper = function( req ) {
return function() {