Skip to content

Instantly share code, notes, and snippets.

@munanadi
munanadi / README.md
Created July 13, 2021 16:28
Get a local instance of mongodb running with docker.

Steps to follow:

  • docker pull mongo:latest -> to get the images from docker hub
  • docker run -p 2717:27017 -v "ABSOLUTEPATH TO SOME DIR":/data/db --name mymongo mongo -> This would run it in attached mode by deafult
  • docker exec -it mymongo mongo -> Gives you the shell to interact with

Can install docker compass and connect to localhost:2717 to see this as in GUI

🎉

@munanadi
munanadi / call.js
Last active August 31, 2021 16:11
This works but only for sollet wallet
import { useState, useEffect, useMemo } from "react";
import * as anchor from "@project-serum/anchor";
import { Provider } from "@project-serum/anchor";
import Wallet from "@project-serum/sol-wallet-adapter";
import { PublicKey, Connection } from "@solana/web3.js";
import * as web3 from "@solana/web3.js";
import idl from "./idl.json";
const Home = (props) => {
const [isConnected, setIsConnected] = useState(false);
@munanadi
munanadi / mintTokens.js
Created September 1, 2021 16:06
Create and Mint tokens for a given wallet.
import React, { useState, useEffect } from 'react'
import { Connection, PublicKey, Keypair, LAMPORTS_PER_SOL, SystemProgram, TransactionInstruction, SYSVAR_RENT_PUBKEY, Transaction } from '@solana/web3.js';
import { ASSOCIATED_TOKEN_PROGRAM_ID, MintLayout, AccountLayout, Token, TOKEN_PROGRAM_ID, u64 } from '@solana/spl-token';
import bs58 from 'bs58';
import { Buffer } from 'buffer';
import * as BufferLayout from 'buffer-layout';
// Need to deploy the contract and figure out how to create the account for data storage
const VOTING_CONTRACT_PROGRAMID = "";
@munanadi
munanadi / index.js
Created October 27, 2021 23:00
To close Associated Accounts
/*
THIS IS NOT THE IDEAL WAY OF DOING THIS.
SHOULD ONLY RUN THIS IN A LOCAL SECURE ENV
WE ARE EXPLICITLY USING OUR PRIVATE KEY HERE, WHICH IS NOT ADVISABLE.
*/
import { Connection, PublicKey, Keypair, Transaction } from "@solana/web3.js";
import { TOKEN_PROGRAM_ID, Token } from "@solana/spl-token";
const connection = new Connection("https://solana-api.projectserum.com");
@munanadi
munanadi / tokenBalance.js
Created December 23, 2021 15:22
Fetches token balances same as solscan API
import { Connection, PublicKey } from "@solana/web3.js";
// var JSON_parse = require("uint8array-json-parser").JSON_parse;
import { TOKEN_PROGRAM_ID, Token } from "@solana/spl-token";
const connection = new Connection("https://solana-api.projectserum.com");
// token account here
const owner = new PublicKey("---------------------");
connection
@munanadi
munanadi / app.js
Created May 6, 2022 13:59
Watches the latest txns for SwapEvents and adds them to the table
const express = require("express");
const axios = require("axios");
const { Connection, Keypair, PublicKey } = require("@solana/web3.js");
const { IDL } = require("@cykura/sdk");
const anchor = require("@project-serum/anchor");
const { buildCoderMap } = require("@saberhq/anchor-contrib");
const { Program, Provider, Wallet } = anchor;
const PROGRAM_ADD = new PublicKey(
@munanadi
munanadi / index.js
Created July 14, 2022 00:16
Script to manipulate line by line
// TO swithc amt0 and amt1 that got switched up when creating this file
const fs = require('fs');
const readline = require('readline');
const { EOL } = require('os');
async function processLineByLine() {
const fileStream = fs.createReadStream(__dirname + '/manipulate.txt');
const writeStream = fs.createWriteStream(__dirname + '/good_manipulate.txt', {
encoding: 'utf8',
@munanadi
munanadi / scrapeApartmentdata.js
Created June 15, 2023 20:39
Scrapes Apartment data from BAF website
// Head to https://baf.org.in/baf_members
// Open Console, Copy paste the script
// Copy your data from `result` variable
let result = ""
for(let i=0; i<62;i++){
tbody = document.querySelectorAll('tbody')[2]
allRows = new Array(tbody.querySelectorAll('tr'))
allRows = Array.from(allRows[0])
result += allRows.map(r => r.innerText)
result += "\n"
@munanadi
munanadi / Fundme.sol
Created January 10, 2024 08:24
Fund me contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import {PriceConvertor} from "./PriceConvertor.sol";
error NotOwner();
contract FundMe {
using PriceConvertor for uint256;