Skip to content

Instantly share code, notes, and snippets.

View codewithgun's full-sized avatar

kampung-tech codewithgun

  • Kuala Lumpur, Malaysia
View GitHub Profile
import AmmImpl, { MAINNET_POOL } from "@mercurial-finance/dynamic-amm-sdk";
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
import { Wallet, AnchorProvider } from "@project-serum/anchor";
import { TokenListProvider } from "@solana/spl-token-registry";
import Decimal from "decimal.js";
interface JupPriceResponse {
data: {
[address: string]: {
id: String;
@codewithgun
codewithgun / main.rs
Last active April 22, 2024 04:53
DLMM account subscribe and decode
use std::env;
use anchor_client::anchor_lang::AccountDeserialize;
use anyhow::Result;
use base64::Engine;
use futures::{SinkExt, StreamExt};
use lb_clmm::state::position::PositionV2;
use serde_json::{json, Value};
use tokio_tungstenite::{connect_async, tungstenite::Message};
@codewithgun
codewithgun / README.md
Created March 2, 2024 17:15 — forked from progrium/README.md
Setting up M1 Macs for x86 development with Homebrew

Key Points

  • In general, binaries built just for x86 architecture will automatically be run in x86 mode
  • You can force apps in Rosetta 2 / x86 mode by right-clicking app, click Get Info, check "Open using Rosetta"
  • You can force command-line apps by prefixing with arch -x86_64, for example arch -x86_64 go
  • Running a shell in this mode means you don't have to prefix commands: arch -x86_64 zsh then go or whatever
  • Don't just immediately install Homebrew as usual. It should most likely be installed in x86 mode.

Homebrew

Not all toolchains and libraries properly support M1 arm64 chips just yet. Although

function test_getFeeAmount() public {
// Configuration was copied from BTC.b/USDC pair
bytes32 params;
uint16 binStep = 10;
params = params.setStaticFeeParameters(10000, 30, 600, 5000, 40000, 1000, 350000);
// Set volatility accumulator to the max
params = params.setVolatilityAccumulator(350000);
// 5900000000000000 => 0.59%
@codewithgun
codewithgun / example-typeorm-jest.test.ts
Created September 19, 2021 09:59 — forked from Ciantic/example-typeorm-jest.test.ts
Example of testing TypeOrm with Jest and Sqlite in-memory database
import { createConnection, getConnection, Entity, getRepository } from "typeorm";
import { PrimaryGeneratedColumn, Column } from "typeorm";
@Entity()
export class MyEntity {
@PrimaryGeneratedColumn()
id?: number;
@Column()
name?: string;
{
"printWidth": 180,
"tabWidth": null,
"useTabs": true,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "always"
}
@codewithgun
codewithgun / nodejs-tcp-example.js
Created July 18, 2021 16:43 — forked from tedmiston/nodejs-tcp-example.js
Node.js TCP client and server example
/*
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it. I added an
example at the bottom.
Save the following server in example.js:
*/
var net = require('net');
@codewithgun
codewithgun / postgres.md
Last active May 17, 2021 18:24
How to configure postgres to receive external/remote request

Unable to connect Postgresql from client

There was several reasons causes client unable to connect to Postgres database.

First, run sudo systemctl status postgresql to check whether the database is running.

If the output shows status: active, it shows that the database is up and running. The problems might due to authentication, listening port, or firewall.

In Postgres, there was few type of authentication methods. However, most of the time, the authentication will be password authentication or local socket authentication.

@codewithgun
codewithgun / laravel-local-pusher.md
Created April 22, 2021 15:40
Laravel web socket with local pusher and custom authentication

Laravel local websocket

Customized authentication will be used in this gist instead of default Auth facade provided by Laravel

Create project

composer create-project laravel-laravel your-project-name
cd your-project-name
@codewithgun
codewithgun / leveldb-laravel-ubuntu.md
Last active April 20, 2021 05:34
LevelDB for laravel

Install LevelDB for Laravel

Install LevelDB

You can install leveldb from repository

sudo apt-get install libleveldb-dev

Install phpize