Skip to content

Instantly share code, notes, and snippets.

View Vectorized's full-sized avatar
🎡

Vectorized Vectorized

🎡
View GitHub Profile
@0xfoobar
0xfoobar / Lambert.sol
Created November 8, 2023 00:05
Lambert W0(x) Function Approximation
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import {wadLn, unsafeWadMul, unsafeWadDiv} from "solmate/utils/SignedWadMath.sol";
/// @notice Approximated principal branch of [Lambert W function](https://en.wikipedia.org/wiki/Lambert_W_function)
/// @dev Only supports the [1/e, 3+1/e] and [3+1/e, inf] interval
/// @dev Approximate [1/e, 3+1/e] with a lookup table weighted average
/// @dev Approximate and [3+1/e, inf] with ln(x) - ln(ln(x)) + ln(ln(x))/ln(x)
contract Lambert {
@ahbanavi
ahbanavi / contract.sol
Last active May 19, 2022 19:49
ECDSA Sign off-chain and Validate on-chain
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
using ECDSA for bytes32;
// verify signature
if (
keccak256(abi.encodePacked(msg.sender, address(this))).toEthSignedMessageHash().recover(signature) !=
owner()
) revert InvalidSignature();
@hofmannsven
hofmannsven / README.md
Created December 6, 2017 00:32
Increase key repeat rate on macOS

Increase key repeat rate on macOS

Settings: System Preferences » Keyboard » Key Repeat/Delay Until Repeat

Use the commands below to increase the key repeat rate on macOS beyond the possible settings via the user interface. The changes aren't applied until you restart your computer.

Source: https://apple.stackexchange.com/a/83923

@u01jmg3
u01jmg3 / session-readonly.php
Created October 21, 2016 12:14
Session locking - non-blocking read-only sessions in PHP
<?php
function session_readonly(){
if(version_compare(PHP_VERSION, '7.0.0') >= 0){
session_start(array('read_and_close' => true));
} else {
$session_name = preg_replace('/[^\da-z]/i', '', $_COOKIE[session_name()]);
$session_data = file_get_contents(session_save_path() . '/sess_' . $session_name);
$return_data = array();
$offset = 0;
@nvictus
nvictus / loadnpy.js
Last active July 4, 2024 09:10
NumPy binary file parser for javascript
// Client-side parser for .npy files
// See the specification: http://docs.scipy.org/doc/numpy-dev/neps/npy-format.html
var NumpyLoader = (function () {
function asciiDecode(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
}
function readUint16LE(buffer) {
var view = new DataView(buffer);
var val = view.getUint8(0);
@rezoo
rezoo / numpy.hpp
Last active April 14, 2024 17:37
Reimplementation of libnpy. This library is header-only and compatible with any environment including MSVC.
/*
* Copyright (c) 2012 Masaki Saito
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@arq5x
arq5x / test.sh
Last active November 30, 2023 12:50
Compress and then Decompress a string with zlib.
# compile
$ g++ zlib-example.cpp -lz -o zlib-example
# run
$ ./zlib-example
Uncompressed size is: 36
Uncompressed string is: Hello Hello Hello Hello Hello Hello!
----------