Skip to content

Instantly share code, notes, and snippets.

View 1Firsts's full-sized avatar
💭
Tap to Chat!

Achmad Imannudin 1Firsts

💭
Tap to Chat!
View GitHub Profile
@1Firsts
1Firsts / Solana Program
Created February 2, 2022 03:23
Package / Crate Solana
use solana_program::{
account_info::{next_account_info, AccountInfo},
entrypoint,
entrypoint::ProgramResult,
msg,
@1Firsts
1Firsts / Mut Campaign Account Data
Created February 2, 2022 03:22
Amount left to be collected, using msg
let mut campaign_account_data = CampaignAccount::try_from_slice(&campaign_account.data.borrow())?;
msg!("{}",campaign_account_data.campaign_amount - campaign_account_data.campaign_fulfilled);
@1Firsts
1Firsts / Campaign Account Data
Created February 2, 2022 03:16
The rest of the bytes will be the string that describes this campaign.
let mut campaign_account_data= CampaignAccount::try_from_slice(&campaign_account.data.borrow())?;
campaign_account_data.campaign_amount = amount;
campaign_account_data.campaign_description = description;
campaign_account_data.campaign_fulfilled = 0;
@1Firsts
1Firsts / Amount
Created February 2, 2022 03:14
The next 4 bytes will be the amount.
let amount = rest_of_data
.get(..8)
.and_then(|slice| slice.try_into().ok())
.map(u64::from_le_bytes)
.unwrap();
@1Firsts
1Firsts / Defining Instruction
Created February 2, 2022 02:57
Defining The Instruction
let (instruction_byte, all_other_bytes) = data.split_first().unwrap();
if *i nstruction_byte == 0{
// create campaign
}
else if *instruction_byte == 1{
@1Firsts
1Firsts / Process Instruction
Last active February 2, 2022 02:55
Writing Logic
pub fun process_instruction (
program_id : &Pubkey,
accounts : &[AccountInfo],
data :&[u8],
) -> ProgramResult
@1Firsts
1Firsts / campaignacc
Created February 2, 2022 02:48
Structure Campaign Account
pub struct CampaignAccount {
pub campaign_owner: PubKey,
pub campaign_amounts: u64,
pub campaign_descriptions: String,
pub campaign_fulfilled: u64,
@1Firsts
1Firsts / for-loops.php
Created October 20, 2021 10:15
For Loops Math
<!-- Sunmation (Capital Sigma) -->
<?=
sum = 0;
for(n=0; n<=4; n++){
sum += 3*n;
}
?>
<!-- Product (Capital Pi) -->
<?=
@1Firsts
1Firsts / css-selector.html
Created October 10, 2021 13:35
CSS Selector
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> CSS Selector</title>
</head>
<body>
<style>
body{
background-color: #f1faee;
@1Firsts
1Firsts / range-slider.html
Created October 10, 2021 13:17
Range Slider
<input type="range" min="1" max="100" value="75">