Skip to content

Instantly share code, notes, and snippets.

View Pet3ris's full-sized avatar
🎯
Focusing

Peteris Erins Pet3ris

🎯
Focusing
View GitHub Profile
@Pet3ris
Pet3ris / XBankLendingVault.cairo
Created April 4, 2023 16:12
Yagi XBank Lending Vault Code
# SPDX-License-Identifier: AGPL-3.0-or-later
%lang starknet
from starkware.cairo.common.bool import TRUE, FALSE
from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.starknet.common.syscalls import get_caller_address, get_contract_address
from starkware.cairo.common.uint256 import ALL_ONES, Uint256, uint256_check, uint256_eq
from openzeppelin.token.erc20.interfaces.IERC20 import IERC20
@Pet3ris
Pet3ris / packing.cairo
Created December 26, 2021 18:57
Bitwise packing & unpacking in cairo
%lang starknet
%builtins pedersen range_check bitwise
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin, HashBuiltin
from starkware.cairo.common.bitwise import bitwise_and
from starkware.cairo.common.math import assert_nn_le
const WORD = 2 ** 16
const MASK = WORD - 1
const MASK2 = MASK * WORD
@Pet3ris
Pet3ris / ComptrollerExcerpt.sol
Last active September 6, 2021 10:20
Buggy setCompSpeedInternal
/**
* @notice Set COMP speed for a single market
* @param cToken The market whose COMP speed to update
* @param compSpeed New COMP speed for market
*/
function setCompSpeedInternal(CToken cToken, uint compSpeed) internal {
uint currentCompSpeed = compSpeeds[address(cToken)];
if (currentCompSpeed != 0) {
// note that COMP speed could be set to 0 to halt liquidity rewards for a market
Exp memory borrowIndex = Exp({mantissa: cToken.borrowIndex()});
  • 1978
  • The City and Man consists of provocative essays by the late Leo Strauss on Aristotle's Politics, Plato's Republic, and Thucydides' Peloponnesian Wars. Together, the essays constitute a brilliant attempt to use classical political philosophy as a means of liberating modern political philosophy from the stranglehold of ideology. The essays are based on a long and intimate familiarity with the works, but the essay on Aristotle is especially important as one of Strauss's few writings on the philosopher who largely shaped Strauss's conception of antiquity. The essay on Plato is a full-scale discussion of Platonic political philosophy, wide in scope yet compact in execution. When discussing
@Pet3ris
Pet3ris / PromiseQueue.re
Created August 14, 2020 22:15
Lazy promise queue implementation in ReasonML
// Lazy PromiseQueue implementation
type pair('a) = ('a, t('a))
and t('a) = {next: Lazy.t(Js.Promise.t(option(pair('a))))};
let build = promise => {next: promise};
let empty: t('a) = lazy(Js.Promise.resolve(None)) |> build;
@Pet3ris
Pet3ris / yulast.json
Created August 11, 2020 11:54
YUL ast output from Solidity
{
"AST": {
"nodeType": "YulBlock",
"src": "355:175:0",
"statements": [
{
"nodeType": "YulVariableDeclaration",
"src": "369:22:0",
"value": {
"arguments": [
@Pet3ris
Pet3ris / list.txt
Created July 14, 2020 17:16
Webpack npm list
npm list
awesome-project@2.0.0 /Users/p/Dev/misc/webpack-parser
├─┬ @fullhuman/postcss-purgecss@1.1.0
│ └─┬ purgecss@1.1.0
│ ├── glob@7.1.2 deduped
│ ├─┬ postcss@7.0.14
│ │ ├─┬ chalk@2.4.2
│ │ │ ├─┬ ansi-styles@3.2.1
│ │ │ │ └── color-convert@1.9.0 deduped
@Pet3ris
Pet3ris / dydx.sol
Created June 8, 2020 11:25
dYdX solo in one file
/*
Copyright 2019 dYdX Trading Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
@Pet3ris
Pet3ris / idea.scala
Created December 25, 2012 09:46
Typed type tensors in scala
sealed trait Tensor[V] {
val n, m: Int
def apply(vs: List[V], vds: List[V => Double]): Double
}
case class TUnit[V](v: V) extends Tensor[V] {
val n = 1
val m = 0
def apply(vs: List[V], vds: List[V => Double]): Double = vds head(v)
}
; Temporal logic programming with explicit time using core.logic
; we assume relations s, <o and constants zero, one, four are defined as in
; https://github.com/frenchy64/Logic-Starter/blob/master/src/logic_introduction/numbers.clj
; we start by using 'next' to define a Fibonacci relation
; that is equal to F(n) at time n
; We use the small trick that if a number
; has a predecessor and then another, then it is at least 2
(defn fib [v t]