Skip to content

Instantly share code, notes, and snippets.

View sambacha's full-sized avatar
:atom:

sam bacha sambacha

:atom:
View GitHub Profile
@sambacha
sambacha / decode-dyn-uti.swift
Created August 14, 2023 12:10 — forked from jtbandes/decode-dyn-uti.swift
Dynamic UTI decoding
/// Decodes a dynamically-generated Uniform Type Identifier for inspection purposes. (**NOT FOR PRODUCTION USE!**)
/// Many, many thanks to http://alastairs-place.net/blog/2012/06/06/utis-are-better-than-you-think-and-heres-why/
///
/// <https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/understanding_utis/understand_utis_conc/understand_utis_conc.html#//apple_ref/doc/uid/TP40001319-CH202-BCGCDHIJ>
func decodeDynUTI(_ uti: String) -> String?
{
let vec = Array("abcdefghkmnpqrstuvwxyz0123456789")
let encoded = Array(uti).suffix(from: 5)
var result: [UInt8] = []
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.6.8;
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*

Trying Ezno checking today

This a short overview of some of the things you can do with Ezno today. If you find any problems, file an issue.

The following examples show some errors that have been caught using type checking, partial/const evaluation and effects.

To get started we will install oxidation-compiler which has bindings for Ezno's checker. (you can also get the binary from the releases page).

npm install -g oxidation-compiler@latest
@sambacha
sambacha / go-function-error-reporting.md
Created October 8, 2022 10:45 — forked from posener/go-function-error-reporting.md
Function Failure reporting: Error or OK

Function Failure Reporting: Error or OK

Go's "multiple return values" feature, can be used for several purposes. Among them for failure reporting to the function caller. Go has two conventions for failure reporting, but currently, no clear convention for which to use when. I've encountered different programmers that prefer different choices in different cases. In this article, we will discuss the two, and try to make the process of choosing our next function signature more conscious.

The Basics

@sambacha
sambacha / FeeEstimationHighLevel.md
Created July 29, 2022 05:47 — forked from morcos/FeeEstimationHighLevel.md
Bitcoin Core Fee Estimation Algorithm

High level description Bitcoin Core's fee estimation algorithm

The algorithm takes as input a target which represents a number of blocks within which you would like your transaction to be included in the blockchain. It returns a fee rate that you should use on your transaction in order to achieve this.

The algorithm is conceptually very simple and does not attempt to have any predictive power over future conditions. It only looks at some recent history of transactions and returns the lowest fee rate such that in that recent history a very high fraction of transactions with that fee rate were confirmed in the block chain in less than the target number of blocks.

Transactions can occur with a nearly continuous range of fee rates and so in order to avoid tracking every historical transaction independently, they are grouped into fee rate "buckets". A fee rate bucket represents a range of fee rates within which the algorithm treats all transactions as having approximately the same fee rate and the answer th

@sambacha
sambacha / create-service.sh
Created July 14, 2022 23:23 — forked from ahmedsadman/create-service.sh
Bash script to create systemd service
#!/usr/bin/bash
##
## Creates Service file based on JSON data
##
# Sample JSON file:
# {
# "service_name": "test_service",
# "description": "Netcore dev server",
@sambacha
sambacha / HeapSort.sol
Created July 11, 2022 13:14 — forked from fiveoutofnine/HeapSort.sol
Solidity implementation of max-heapsort
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract HeapSort {
function sort(uint256[] calldata _input) external pure returns (uint256[] memory) {
_buildMaxHeap(_input);
uint256 length = _input.length;
unchecked {
for (uint256 i = length - 1; i > 0; --i) {
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
library RadixSort {
uint256 internal constant ALPHABET_SIZE_LOG_2 = 7;
uint256 internal constant ALPHABET_SIZE = 1 << ALPHABET_SIZE_LOG_2;
uint256 internal constant MASK = ALPHABET_SIZE - 1;
function sort(uint256[] memory _list) internal pure {
uint256 iterations;
@sambacha
sambacha / papers.md
Created July 11, 2022 08:35 — forked from pdarragh/papers.md
Approachable PL Papers for Undergrads

Approachable PL Papers for Undergrads

On September 28, 2021, I asked on Twitter:

PL Twitter:

you get to recommend one published PL paper for an undergrad to read with oversight by someone experienced. the paper should be interesting, approachable, and (mostly) self-contained.

what paper do you recommend?

@sambacha
sambacha / advanced-memo.md
Created June 17, 2022 11:32 — forked from slikts/advanced-memo.md
Advanced memoization and effects in React

nelabs.dev

Advanced memoization and effects in React

Memoization is a somewhat fraught topic in the React world, meaning that it's easy to go wrong with it, for example, by [making memo() do nothing][memo-pitfall] by passing in children to a component. The general advice is to avoid memoization until the profiler tells you to optimize, but not all use cases are general, and even in the general use case you can find tricky nuances.

Discussing this topic requires some groundwork about the technical terms, and I'm placing these in once place so that it's easy to skim and skip over:

  • Memoization means caching the output based on the input; in the case of functions, it means caching the return value based on the arguments.
  • Values and references are unfortunately overloaded terms that can refer to the low-level implementation details of assignments in a language like C++, for example, or to memory