Skip to content

Instantly share code, notes, and snippets.

View phatnguyenuit's full-sized avatar
💪
Working on ReactJS and TypeScript.

Phát Nguyễn (Fast) phatnguyenuit

💪
Working on ReactJS and TypeScript.
View GitHub Profile
#include<stdio.h>
typedef struct process
{
int id, at, bt, ct=0, rt=0, tat=0, wt=0,at1=0;/* at=arrival time,bt=burst time,ct=completed time,rt=respond time,tat= turn around time ,wt=waiting time*/
int pri=0;
}pro;
void swap(pro &a, pro &b)
{
pro temp = a;
@phatnguyenuit
phatnguyenuit / MyContract.sol
Created July 1, 2019 17:24
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.8+commit.23d335f2.js&optimize=false&gist=
pragma solidity ^0.5.8;
contract MyContract {
string value;
// expose publicValue can be called outside of the contract
string public publicValue = "publicValue";
// declare constant property
string public constant constantValue = "constantValue";
@phatnguyenuit
phatnguyenuit / validation.js
Last active August 7, 2019 14:43
Multiple validation conditions
const isTruthy = param => !!param;
const isString = param => typeof (param) === 'string';
const isNumeric = param => /^\d+$/.test(param);
const makeConditionalMethod = (method, required = false) => (...params) => {
const res = method(...params);
const valid = isTruthy(...params);
if (required) {
return valid && res;
@phatnguyenuit
phatnguyenuit / convert_object_keys.js
Created August 16, 2019 03:04
Convert Object Keys In JavaScript
const convertObjectKeys = (obj, convertFn) => {
let result = {};
for (const key in obj){
result[convertFn(key)] = obj[key];
}
return result;
}
const upperCase = str => str.toUpperCase();
@phatnguyenuit
phatnguyenuit / convert_object_keys.js
Created August 16, 2019 03:04
Convert Object Keys In JavaScript
const convertObjectKeys = (obj, convertFn) => {
let result = {};
for (const key in obj){
result[convertFn(key)] = obj[key];
}
return result;
}
const upperCase = str => str.toUpperCase();
import jwt_decode from 'jwt-decode';
export const isExpiredToken = token => {
if (!token) return false;
var decoded_jwt = jwt_decode(token);
var current_time = new Date().getTime() / 1000;
return current_time > decoded_jwt.exp;
};
@phatnguyenuit
phatnguyenuit / remove_adjacent_duplicates.js
Created September 18, 2019 03:12
Recursively remove all adjacent duplicates
function remove_adjacent_duplicates(str) {
return str.replace(/(\w)\1+/g, '');
}
remove_adjacent_duplicates("geeksforgeek") //gksforgk
@phatnguyenuit
phatnguyenuit / requiredParameter.js
Created September 27, 2019 15:59
Enforce required parameters for functions
/**
Enforce required params for functions
@author Tauqeer Awan
*/
// Define a function and throw an error from it
const isRequiredParameter = parameterName => {
throw new Error(`Missing parameter ${parameterName}`);
}
@phatnguyenuit
phatnguyenuit / update_file_name.sh
Created October 4, 2019 03:38
Update file name with bash script
for filename in **/__test__/*.test.tsx; do
mv $filename ${filename/.test/}
echo Updated $filename => ${filename/.test/}
done
@phatnguyenuit
phatnguyenuit / EnhanceCountDown.tsx
Last active October 6, 2019 16:05
Enhance Count Down Component in ReactJS with Typescript
import * as React from 'react';
import { EnhanceCountDownPropsType, EnhanceCountDownStateType } from './types';
class EnhanceCountDown extends React.PureComponent<
EnhanceCountDownPropsType,
EnhanceCountDownStateType
> {
countDownInterval?: number;
constructor(props: EnhanceCountDownPropsType) {