Skip to content

Instantly share code, notes, and snippets.

View geekyorion's full-sized avatar
👽
Invading JavaScript

Shashank Sharma geekyorion

👽
Invading JavaScript
View GitHub Profile
@geekyorion
geekyorion / create_counter_array.js
Created January 18, 2023 15:28
create a counter array in ascending order from an array of numbers
const random = (upto = 20, offset = 1) => {
const correction = Math.max(upto, upto * 1000);
return ~~(Math.random() * correction) % upto + offset;
};
const populateArr = (count = 20) => {
const numbers = [];
for (let i = 0; i < count; i++) {
numbers.push(random());
}
@geekyorion
geekyorion / userFoundDiscordSnippet.js
Created January 8, 2023 15:35
Check whether user is found or not using forEach and Promises
// think of this as a DB
const users = [
{ username: "name1234", password: "password" },
{ username: "user1234", password: "pass" }
];
// username and password of the user
const username = "name1234";
const password = "password";
@geekyorion
geekyorion / randomID.js
Created January 7, 2023 06:24
get random ID using simple methods
const getRandomHex = () => Math.random().toString(16).substring(2);
const getTimeHex = () => Date.now().toString(16);
const getUniqueID = () => `${getRandomHex()}-${getTimeHex()}`;
console.log(getUniqueID()); // c3767dde3c52b-1858ae49650
console.log(getUniqueID()); // afea12d2bf3ee-1858ae49b2e
console.log(getUniqueID()); // c935374b52dc4-1858ae49e6b
@geekyorion
geekyorion / GLSL-Noise.md
Created December 30, 2022 10:16 — forked from patriciogonzalezvivo/GLSL-Noise.md
GLSL Noise Algorithms

Generic 1,2,3 Noise

float rand(float n){return fract(sin(n) * 43758.5453123);}

float noise(float p){
	float fl = floor(p);
  float fc = fract(p);
	return mix(rand(fl), rand(fl + 1.0), fc);
}
@geekyorion
geekyorion / sqrt.js
Created November 27, 2022 20:06 — forked from animatedlew/sqrt.js
Here is an implementation of a square root function in JavaScript using Newton's method.
var sqrt = function(x) {
var isGoodEnough = function(guess) {
return Math.abs(guess * guess - x) / x < 0.001;
};
var improve = function(guess) {
return (guess + x / guess) / 2;
};
var sqrIter = function(guess) {
@geekyorion
geekyorion / numberToWord_en_IN.js
Created October 28, 2022 15:02
JavaScript code to convert the number to text/word in Indian format
const numberTexts = {
0: 'zero',
1: 'one',
2: 'two',
3: 'three',
4: 'four',
5: 'five',
6: 'six',
7: 'seven',
8: 'eight',
@geekyorion
geekyorion / getStatus.js
Created October 11, 2022 07:48
WhatsApp get status [need to use console and whatsapp web for this]
const logs = {
online: [],
offline: [],
typing: []
};
let currentStatus = '';
let timer = new Date();
const getDateFormat = date => {
@geekyorion
geekyorion / app.js
Created August 11, 2022 09:34
React App.js to display nested data using class Component
import { Component } from 'react';
import data from './data';
class App extends Component {
constructor(props) {
super(props);
this.state = {
flowData: []
}
}
@geekyorion
geekyorion / promise_with_callbacks.js
Created June 28, 2022 18:59
Promise with callback for success and error functions
const getValue = (value, successFn, errorFn) => {
new Promise((res, rej) => {
if (value > 100) {
res(value * 2);
} else {
rej(value / 2);
}
})
.then(data => {
successFn(data);
@geekyorion
geekyorion / array-item-count.js
Created June 17, 2022 15:20
Count a name in an array of a string
const names = ['Antonia Lane', 'Reya Castillo', 'Ayla Owen', 'Ahmed Adams', 'Gerrard Douglas', 'Kaif Greenwood', 'Piper Redmond', 'Jago Decker', 'Reya Castillo'];
const selectedName = 'Reya Castillo';
let count = 0;
// using for loop [the most efficient]
for (let i = 0; i < names.length; i++) {
count += selectedName === names[i];
}