Skip to content

Instantly share code, notes, and snippets.

View cryptocoderkkk's full-sized avatar

Satoshi cryptocoderkkk

View GitHub Profile
@cryptocoderkkk
cryptocoderkkk / Queue.sol
Created August 3, 2024 22:18
Queue like contract written in solidity (not tested)
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;
contract Queue {
uint256[] public data;
uint256 public maxCapacity; //mutable
// might consider making them private
uint256 public front;
uint256 public back;
--- clone using CREATE opcode ---
function _cloneWithV1(address _contract)
private
returns (address result)
{
bytes20 addressBytes = bytes20(_contract);
// solhint-disable-next-line no-inline-assembly
assembly {
let clonePlaceholder := mload(0x40)
function _swapTokenToEth(
address[] memory swapPath,
uint256 exchangeAmount,
uint256 deadline,
uint256 slippage,
uint256 ethPerToken
) internal returns (uint256) {
uint256[] memory amounts =
sushiswapRouter.getAmountsOut(exchangeAmount, swapPath);
uint256 sushiAmount = amounts[amounts.length - 1]; //amount of ETH
@cryptocoderkkk
cryptocoderkkk / gist:ed71524a5c76ce8f32445591344b8991
Created October 17, 2021 02:22
Move from polygon - example
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.callTest = exports.testMoveFromPolygon = void 0;
const sdk_1 = require("@composable-finance/sdk");
const vaults_1 = require("@composable-finance/sdk/dist/src/config/vaults");
const L2Vault_json_1 = __importDefault(require("@composable-finance/sdk/dist/src/utils/abi/L2Vault.json"));
const ethers_1 = require("ethers");
@cryptocoderkkk
cryptocoderkkk / 0_reuse_code.js
Created September 24, 2015 10:54
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@cryptocoderkkk
cryptocoderkkk / prefix array jquery
Last active September 24, 2015 11:07
jquery prefix integer with 0s
function PrefixInteger(num, length) {
return (Array(length).join('0') + num).slice(-length);
}
@cryptocoderkkk
cryptocoderkkk / get date
Last active September 24, 2015 11:07
Milliseconds since epoch
+new Date()
@cryptocoderkkk
cryptocoderkkk / jquery concat arrays
Last active September 24, 2015 11:07
jquery append array to another array
var a = [4,5,6];
var b = [7,8,9];
Array.prototype.push.apply(a, b);
@cryptocoderkkk
cryptocoderkkk / jquery prototype
Last active September 24, 2015 11:07
jquery prototyping
Every JavaScript object has an internal property called [[Prototype]]. If you look up a property via obj.propName or obj['propName'] and the object does not have such a property - which can be checked via obj.hasOwnProperty('propName') - the runtime looks up the property in the object referenced by [[Prototype]] instead. If the prototype-object also doesn't have such a property, its prototype is checked in turn, thus walking the original object's prototype-chain until a match is found or its end is reached.
Some JavaScript implementations allow direct access to the [[Prototype]] property, eg via a non-standard property named __proto__. In general, it's only possible to set an object's prototype during object creation: If you create a new object via new Func(), the object's [[Prototype]] property will be set to the object referenced by Func.prototype.
------------------------------------------------------------------------------
var obj = new Object();
obj.test = function() { alert('Hello?'); };
In
@cryptocoderkkk
cryptocoderkkk / jquery recursivity
Last active September 24, 2015 11:07
jquery recursivity
$.fn.goDeep = function(levels, func){
var iterateChildren = function(current, levelsDeep){
func.call(current, levelsDeep);
if(levelsDeep > 0)
$.each(current.children(), function(index, element){
iterateChildren($(element), levelsDeep-1);
});
};