Skip to content

Instantly share code, notes, and snippets.

View markgk629's full-sized avatar

Mark Guo markgk629

  • Idealian
  • Australia
View GitHub Profile
@markgk629
markgk629 / encryption.js
Created September 28, 2022 12:09 — forked from anned20/encryption.js
Encrypting files with NodeJS
const crypto = require('crypto');
const algorithm = 'aes-256-ctr';
let key = 'MySuperSecretKey';
key = crypto.createHash('sha256').update(String(key)).digest('base64').substr(0, 32);
const encrypt = (buffer) => {
// Create an initialization vector
const iv = crypto.randomBytes(16);
// Create a new cipher using the algorithm, key, and iv
const cipher = crypto.createCipheriv(algorithm, key, iv);
@markgk629
markgk629 / UniswapAdd.sol
Created April 29, 2022 10:00 — forked from QuantSoldier/UniswapAdd.sol
Uniswap V2: Gas Efficient Contract to add Liquidity to any ETH/ERC-20 LP Pair with ETH
pragma solidity ^0.7.0;
import {SafeMath} from '@openzeppelin/contracts/math/SafeMath.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {IUniswapV2Router02} from '@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol';
interface IWETH9 {
function deposit() external payable;
}
@markgk629
markgk629 / 00-svelte.config.js
Created April 28, 2022 07:37 — forked from shynome/00-svelte.config.js
Run Svelte preprocessors in the sequence they are declared
// Example usage
import { sequence } from './sequence.mjs'
import cssModules from "svelte-preprocess-cssmodules";
export default {
preprocess: sequence([sveltePreprocess(), cssModules()]),
}
@markgk629
markgk629 / deploy.js
Created April 27, 2022 13:01 — forked from tuncatunc/deploy.js
Hardhat deploy script to deploy UniswapV2Factory, and create token pairs.
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
async function main() {
// Hardhat always runs the compile task when running scripts with its command
// line interface.
@markgk629
markgk629 / example.js
Created March 12, 2022 04:55 — forked from amlwwalker/example.js
compiling and sending ehter to a payable function from nodejs
import ethers, {
Contract,
providers as Providers,
utils as Utils,
Wallet,
ContractFactory
} from "ethers"
import path from "path"
import fs from "fs"
@markgk629
markgk629 / MultiSwap.sol
Created March 3, 2022 08:46 — forked from gorgos/MultiSwap.sol
Example for how to swap multiple tokens in one on Ropsten
// SPDX-License-Identifier: MIT
pragma solidity =0.7.6;
pragma abicoder v2;
import "https://github.com/Uniswap/uniswap-v3-periphery/blob/main/contracts/interfaces/ISwapRouter.sol";
import "https://github.com/Uniswap/uniswap-v3-periphery/blob/main/contracts/interfaces/IQuoter.sol";
import {IERC20, SafeERC20} from "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.4-solc-0.7/contracts/token/ERC20/SafeERC20.sol";
interface IUniswapRouter is ISwapRouter {
@markgk629
markgk629 / bb.js
Created December 25, 2021 15:12 — forked from rafaeljesus/bb.js
Bluebird .each vs .mapSeries vs .map
var Promise = require('bluebird');
var funcs = Promise.resolve([500, 100, 400, 200].map((n) => makeWait(n)));
funcs
.each(iterator) // logs: 500, 100, 400, 200
.then(console.log) // logs: [ [Function], [Function], [Function], [Function] ]
funcs
.mapSeries(iterator) // logs: 500, 100, 400, 200
# Luke's config for the Zoomer Shell
# Enable colors and change prompt:
autoload -U colors && colors
PS1="%B%{$fg[red]%}[%{$fg[yellow]%}%n%{$fg[green]%}@%{$fg[blue]%}%M %{$fg[magenta]%}%~%{$fg[red]%}]%{$reset_color%}$%b "
# History in cache directory:
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=~/.cache/zsh/history
@markgk629
markgk629 / express_postgress_knex.md
Created May 25, 2020 10:51 — forked from laurenfazah/express_postgress_knex.md
Cheat Sheet: Setting up Express with Postgres via Knex

Express & Postgres via Knex

Note: <example> is meant to denote text replaced by you (including brackets).

Setup

// global dependencies
npm install -g knex
@markgk629
markgk629 / puppeteer-tor.js
Created April 13, 2019 10:18 — forked from stephonchen/puppeteer-tor.js
puppeteer + tor + polipo
#!/usr/bin/node
// use puppeteer 0.12.0
// since puppeteer has problems in socks5
// use polipo as a http proxy, which parent proxy is tor (localhost:9050)
var time = require('time');
var sleep = require('sleep');
const random_max = 10;