Skip to content

Instantly share code, notes, and snippets.

View nathan-lapinski's full-sized avatar
💭
♦️s and 🦀

Nate Lapinski nathan-lapinski

💭
♦️s and 🦀
View GitHub Profile
@nathan-lapinski
nathan-lapinski / level5.sol
Created June 18, 2023 05:54
Ethernaut Level 5 (Telephone)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// Define an interface for the telephone contract
interface ITelephone {
function changeOwner(address _owner) external;
}
contract MyContract {
// The address of the telephone contract
@nathan-lapinski
nathan-lapinski / block_value.py
Created March 5, 2023 00:07
Eth block value
from web3 import Web3
infura_url = # your infura or alchemy api here. You can use a public one as well.
web3 = Web3(Web3.HTTPProvider(infura_url))
web3
#<web3.main.Web3 object at 0x103cbf280>
print(web3.isConnected())
#True
print(web3.eth.blockNumber)
#16753992
block = web3.eth.getBlock(16753992)
{
"name": "XtraCheapSwap",
"logoURI": "https://ipfs.io/ipfs/QmaypvtnoXGQo4gSGHjgXaMUY98hf2FotQRfXgdLL4jo4i",
"keywords": [
"defi"
],
"timestamp": "2021-02-10T16:00:00.809+00:00",
"tokens": [
{
"chainId": 1,
@nathan-lapinski
nathan-lapinski / app.module.ts
Created August 10, 2019 09:54
Simple App with Routing
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { Component, Input } from '@angular/core';
/**
* Normally, this would be split over multiple files.
* Everything is placed into one file here to make it
* easier to read.
*/
@nathan-lapinski
nathan-lapinski / basic_routing.ts
Created August 5, 2019 12:01
Very basic routing setup
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { Component, Input } from '@angular/core';
import { AppComponent } from './app.component';
@Component({
template: `<h1>This is Component A</h1>`
})
export class ComponentA {
@nathan-lapinski
nathan-lapinski / mybind.js
Created July 24, 2019 13:41
a quick bind
function myBind(fn, context, ...args) {
return function(...moreArgs) {
return fn.call(context, ...(args.concat(moreArgs)));
}
}
// test
function add(a,b,c) {
return a + b + c;
}
function curry(fn) {
const arity = fn.length;
return function $curry(...args) {
if (args.length < arity) {
return $curry.bind(null, ...args);
}
return fn.call(null, ...args);
};
}
function createNode(
routeReuseStrategy: RouteReuseStrategy, curr: TreeNode<ActivatedRouteSnapshot>,
prevState?: TreeNode<ActivatedRoute>): TreeNode<ActivatedRoute> {
// reuse an activated route that is currently displayed on the screen
if (prevState && routeReuseStrategy.shouldReuseRoute(curr.value, prevState.value.snapshot)) {
const value = prevState.value;
value._futureSnapshot = curr.value;
const children = createOrReuseChildren(routeReuseStrategy, curr, prevState);
return new TreeNode<ActivatedRoute>(value, children);
@nathan-lapinski
nathan-lapinski / should_reuse.ts
Created December 29, 2018 15:50
should reuse example
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
return future.routeConfig === curr.routeConfig;
}
@nathan-lapinski
nathan-lapinski / route_reuse_strategy.ts
Last active December 29, 2018 15:45
The router's default reuse strategy
/**
* Does not detach any subtrees. Reuses routes as long as their route config is the same.
*/
export class DefaultRouteReuseStrategy implements RouteReuseStrategy {
shouldDetach(route: ActivatedRouteSnapshot): boolean { return false; }
store(route: ActivatedRouteSnapshot, detachedTree: DetachedRouteHandle): void {}
shouldAttach(route: ActivatedRouteSnapshot): boolean { return false; }
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle|null { return null; }
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
return future.routeConfig === curr.routeConfig;