Skip to content

Instantly share code, notes, and snippets.

View nhuxhr's full-sized avatar
🎯
Focusing

Rapheal nhuxhr

🎯
Focusing
View GitHub Profile
use {
anchor_lang::prelude::*,
anchor_spl::{associated_token, token_2022},
};
declare_id!("11111111111111111111111111111111");
#[program]
pub mod contract {
use super::*;
@nhuxhr
nhuxhr / AutoLink.js
Created November 26, 2021 09:01
AutoLink in React
@nhuxhr
nhuxhr / handleEmptyArgs.js
Created July 21, 2021 22:50
Handle empty args that's passed to a function in JavaScript
/**
* Handle empty args that's passed to a function in JavaScript
* @author JSX Clan <jsxclan.dev@gmail.com>
*/
const isRequired = (name) => {
throw Error(`${name} is missing.`);
}
const setUsername = (username = isRequired('Username')) => {
@nhuxhr
nhuxhr / async_await.js
Created July 21, 2021 22:48
Synchronous fetch using async/await in JavaScript
/**
* Synchronous fetch using async/await in JavaScript
* @author JSX Clan <jsxclan.dev@gmail.com>
*/
// Usual way
const data = fetch('URL').then(res => res.json()).then(json => console.log(json));
// Using await
const data = await fetch('URL').then(res => res.json());
@nhuxhr
nhuxhr / removeArrayDuplicates.js
Created July 21, 2021 22:47
Remove duplicates from an Array in JavaScript
/**
* Remove duplicates from an Array in JavaScript
* @author JSX Clan <jsxclan.dev@gmail.com>
*/
const array = [0, 1, 0, 'foo', 'bar', 'bar', true, true, false];
const filteredArray = [...new Set(array)];
console.log(filteredArray);
@nhuxhr
nhuxhr / performance.js
Created July 21, 2021 22:47
Calculate Time taken by a Program to Execute in JavaScript
/**
* Calculate Time taken by a Program to Execute in JavaScript
* @author JSX Clan <jsxclan.dev@gmail.com>
*/
// Starting time
const start = performance.now();
// Some codes
for (let i = 1; i <= 10; i++) {
console.log(i)
@nhuxhr
nhuxhr / binary2Text.js
Created July 20, 2021 02:02
Convert Binary to Text
/**
* Convert Binary to Text
* @author JSX Clan <jsxclan.dev@gmail.com>
*/
const binary2Text = (str = '') => {
return str.split(' ').map(x => {
return String.fromCharCode(parseInt(x, 2));
}).join('');
}
@nhuxhr
nhuxhr / text2Binary.js
Created July 20, 2021 02:01
Convert Text to Binary
/**
* Convert Text to Binary
* @author JSX Clan <jsxclan.dev@gmail.com>
*/
const text2Binary = (str = '') => {
return str.split('').map((char) => {
return char.charCodeAt(0).toString(2);
}).join(' ');
}