This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use { | |
anchor_lang::prelude::*, | |
anchor_spl::{associated_token, token_2022}, | |
}; | |
declare_id!("11111111111111111111111111111111"); | |
#[program] | |
pub mod contract { | |
use super::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* AutoLink in React | |
* @author JSX Clan <jsxclan.dev@gmail.com> | |
*/ | |
function AutoLink({ text }) { | |
const delimiter = /((?:https?:\/\/)?(?:(?:[a-z0-9]?(?:[a-z0-9\-]{1,61}[a-z0-9])?\.[^\.|\s])+[a-z\.]*[a-z]+|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})(?::\d{1,5})*[a-z0-9.,_\/~#&=;%+?\-\\(\\)]*)/gi; | |
return ( | |
<React.Fragment> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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')) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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(''); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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(' '); | |
} |