This file contains hidden or 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
// OPEN CTRL+SHIFT+P | |
// type in open settings and go to open user settings json | |
// paste this there | |
{ | |
// Shows the inferred type for variables. This is the main one you want. | |
"typescript.inlayHints.variableTypes.enabled": "all", | |
// Shows the inferred return type for functions. Super helpful in tests. | |
"typescript.inlayHints.functionLikeReturnTypes.enabled": "all", |
This file contains hidden or 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
fn main() { | |
//EXAMPLE OF USING THE NEWTON RAPHSON | |
let x = 1_000_000.0; // e.g., USDC | |
let y = 1_000_000.0; // e.g., USDT | |
let amp = 100.0; // Amplification coefficient | |
let d = compute_invariant(x, y, amp); | |
println!("Invariant D: {:.10}", d); | |
// simulate adding 1000 to x and calculating new y |
This file contains hidden or 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
fn main() { | |
let mut arr1 = [5,2,6, 12,234,68, -21, -600]; | |
println!("{:?}", bubble_sort(&mut arr1)); | |
} | |
pub fn bubble_sort<T: Ord + Clone>(arr: &mut [T])-> Vec<T>{ | |
if arr.is_empty(){ | |
return Vec::new(); | |
} | |
for i in 0.. arr.iter().count(){ | |
for j in 0..arr.len() - i -1{ |
This file contains hidden or 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 core::panic; | |
use std::io::ErrorKind; | |
pub use std::fs::File; | |
fn main() { | |
// let file = File::open( | |
// "/home/konquest/home/konquest/rust/Rust-for-practice/floating_point/src/hello.md", | |
// ); | |
let file = File::open("hello.js"); |
This file contains hidden or 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 crate::common::PumpAmmError; | |
use anchor_lang::error; | |
use anchor_spl::token_2022::spl_token_2022::extension::transfer_fee::MAX_FEE_BASIS_POINTS; | |
pub fn ceil_div(numerator: u128, denominator: u128) -> anchor_lang::Result<u128> { | |
numerator | |
.checked_add(denominator) | |
.ok_or_else(|| error!(PumpAmmError::Overflow))? | |
.checked_sub(1) | |
.ok_or_else(|| error!(PumpAmmError::Overflow))? |
This file contains hidden or 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
// TO FIND A MATCHING NAME IN AN ARRAY FROM A STRUCT | |
fn main(){ | |
get_quantity("Apple"); | |
} | |
struct GrocItem{ | |
name: String, | |
// price: f64, | |
quantity: u32, | |
} | |
fn get_quantity(item_name: &str)->Option<u32>{ |
This file contains hidden or 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 std::io::{self,Write}; | |
// TO USE THE .flush().unwrap() TO IMMEDIATELY DISPLAY THE PRINTLN MACRO AND USING .MAP_ERR TO PROPERLY HANDLE ERROR WITH THE "?" | |
//THIS IS FOR RETURNING A RESULT TYPE | |
// HAD TO USE LOOP/MATCH TO HANDLE ERROR SO THE PROGRAM WON'T PANIC AFTER ENCOUNTERING AN ERROR | |
let mut age = String::new(); | |
println!("Input your age"); | |
io::stdout().flush().unwrap(); | |
io::stdin().read_line(&mut age).map_err(|e|format!("Could not read age: {}", e))?; | |
let person_age: u32 = age.trim().parse().expect("Pls input a valid number"); |
This file contains hidden or 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::*; | |
// use anchor_spl::token::{Mint,TokenAccount}; | |
declare_id!("B79TnXm2vponTSgXgnDLe5R1hPthTwwApFq2uGBQgV9r"); | |
#[program] | |
pub mod pda_program { | |
use super::*; | |
pub fn initialize(ctx: Context<InitializePda>, amount : u64) -> Result<()> { |
This file contains hidden or 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
[package] | |
name = "lyra_game" | |
version = "0.1.0" | |
description = "Created with Anchor" | |
edition = "2021" | |
[lib] | |
crate-type = ["cdylib", "lib"] | |
name = "lyra_game" |