Skip to content

Instantly share code, notes, and snippets.

View negarjf's full-sized avatar
🤓

Negar negarjf

🤓
View GitHub Profile
@negarjf
negarjf / .htaccess
Created February 17, 2019 08:41
.htaccess config for local cross origin problem
# .htaccess config for local cross origin problem
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header always set Access-Control-Max-Age "1000"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token, cache-control"
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
@negarjf
negarjf / UserProvider.jsx
Last active January 1, 2021 22:51
UserProvider step 1
import React, {createContext, useReducer} from 'react';
import initialState from "./initialState";
import reducer from "./reducer";
import useActions from "./useActions";
export const UserContext = createContext();
export const UserProvider = ({children}) => {
const value = {user: null};
@negarjf
negarjf / string-id-generator.js
Last active July 21, 2020 20:54
Generating unique random strings with optional prefix and postfix.
/**
* Generates random string id
*
* @param prefix
* @param postfix
* @returns {string}
*/
function generateId(prefix, postfix) {
prefix = prefix || "";
postfix = postfix || "";
@negarjf
negarjf / text-color-detector.js
Created September 14, 2018 13:27
Auto Text Color Detector
// Converts color code to RGB
//====================================
function colorCodeToRGB(colorCode){
var c;
var rgbaValidation = (/([R][G][B][A]?[(]\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\s*,\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\s*,\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])(\s*,\s*((0\.[0-9]{1})|(1\.0)|(1)))?[)])/i.test(colorCode)) ;
var hexValidation = (/^#([A-Fa-f0-9]{3}){1,2}$/.test(colorCode));
if(hexValidation){
c= colorCode.substring(1).split('');
@negarjf
negarjf / Timer.js
Last active November 3, 2019 06:24
Timer for count-down and count-up
/**
* Timer class for count-down and count-up
*/
class Timer {
constructor (duration = 0, countDown = true, step = 1) {
this.duration = duration;
this.countDown = countDown;
this.step = step;
this.opr = countDown ? -1 : 1;
this.currentTime = this.freshCurrentTime;
@negarjf
negarjf / keybase.md
Created October 26, 2019 19:04
Keybase

Keybase proof

I hereby claim:

  • I am negarjf on github.
  • I am negar (https://keybase.io/negar) on keybase.
  • I have a public key ASARovy66SnbNXqFxtOo766-ahZYD6nUfJgcMOOBei3fxgo

To claim this, I am signing this object:

class Stack{
constructor(){
this.top = null;
this.size = 0;
}
get isEmpty(){
return this.top === null;
}
class Queue {
constructor(){
this.head = null;
this.tail = null;
this.size = 0;
}
get length(){
return this.size;
}
class circularQueue{
constructor(max){
this.array = [];
this.max= max;
this.length = 0;
class DynamicArray{
constructor(capacity){
this.arr = [];
this.capacity = capacity;
this.length = 0;
for(let i = 0; i < capacity; i++){
this.arr[i] = null;
}