Skip to content

Instantly share code, notes, and snippets.

View lucasvo's full-sized avatar

Lucas Vogelsang lucasvo

View GitHub Profile
@lucasvo
lucasvo / install.sh
Created October 17, 2021 19:50
NixOS with ZFS
#!/usr/bin/env bash
#
# NixOS install script synthesized from:
#
# - https://gist.github.com/mx00s/ea2462a3fe6fdaa65692fe7ee824de3e
# - Erase Your Darlings (https://grahamc.com/blog/erase-your-darlings)
# - OpenZFS NixOS manual (https://openzfs.github.io/openzfs-docs/Getting%20Started/NixOS/Root%20on%20ZFS/0-overview.html)
# - ZFS Datasets for NixOS (https://grahamc.com/blog/nixos-on-zfs)
# - NixOS Manual (https://nixos.org/nixos/manual/)
@lucasvo
lucasvo / validator-0 log
Created July 22, 2020 10:00
substrate-logs
Jul 22 11:54:09 validator-0 centrifuge-chain[69503]: 2020-07-22 11:54:09 Discovered new external address for our node: /ip6/IP6/tcp/30333/p2p/NODE_KEY
Jul 22 11:54:12 validator-0 centrifuge-chain[69503]: 2020-07-22 11:54:12 Imported #1514364 (0x4c8c…2a7f)
Jul 22 11:54:12 validator-0 centrifuge-chain[69503]: 2020-07-22 11:54:12 Reorg from #1514364,0x4c8c…2a7f to #1514364,0xa4a7…db98, common ancestor #1514363,0x2fb1…12d8
Jul 22 11:54:12 validator-0 centrifuge-chain[69503]: 2020-07-22 11:54:12 Imported #1514364 (0xa4a7…db98)
Jul 22 11:54:13 validator-0 centrifuge-chain[69503]: 2020-07-22 11:54:13 Idle (2 peers), best: #1514364 (0xa4a7…db98), finalized #1514360 (0x6176…82f9), ⬇ 33.3kiB/s ⬆ 30.3kiB/s
Jul 22 11:54:18 validator-0 centrifuge-chain[69503]: 2020-07-22 11:54:18 Idle (2 peers), best: #1514364 (0xa4a7…db98), finalized #1514361 (0x9844…682c), ⬇ 31.6kiB/s ⬆ 31.4kiB/s
Jul 22 11:54:18 validator-0 centrifuge-chain[69503]: 2020-07-22 11:54:18 Imported #1514365 (0x27ef…d776)
Jul 22 11:54:23 validator-0 centrifug
@lucasvo
lucasvo / returning_structs.md
Last active January 10, 2020 17:29
Gas usage when returning Structs

Mapping of Structs in Solidity

Structs in solidity are implemented as a hash map. They key of a map is hashed with keccak and the storage slot. A costly part of accessing a map is hashing the key to find the slot. When storing a struct in a mapping as opposed to multiple mappings of primitive types you can save the cost of multiple hashes. However when frequently only reading part of the struct, returning an entire struct to a call leads to overhad in memory usage. Below are a few test cases illustrating the different options and their gas usage.

Result

As expected, the most simple, test_map() uses the least amount of gas. The worst option is if you have an external call that returns the entire struct even though only one element is needed (test_structmap_no_getter). Therefore if you have external methods access only partial data from a struct always create a getter for it.

@lucasvo
lucasvo / nft.code.py
Last active July 16, 2019 17:10
Centrifuge ZK NFT Demo
# See: https://github.com/centrifuge/zk-nft-demo-contract/blob/5ef74b64a9500937a26a0a3abc4db7539c39c2b8/src/circuit/nft.code#L45-L82
def main(field[2] creditRatingRootHashField, field buyerRatingField, privatefield[160] buyerID, privatefield[256] buyerPubkey, privatefield[2] directionCreditRatingTree, privatefield[256] creditRatingTreeDigest0, privatefield[256] creditRatingTreeDigest1, field nftAmount, field[2] documentRootHashField, privatefield[256] invoiceAmountValue, privatefield[64] invoiceAmountProperty, privatefield[256] invoiceAmountSalt, privatefield[8] invoiceAmountTreeDirection, privatefield[256] invoiceAmountTreeDigests0, privatefield[256] invoiceAmountTreeDigests1, privatefield[256] invoiceAmountTreeDigests2, privatefield[256] invoiceAmountTreeDigests3, privatefield[256] invoiceAmountTreeDigests4, privatefield[256] invoiceAmountTreeDigests5, privatefield[256] invoiceAmountTreeDigests6, privatefield[256] invoiceAmountTreeDigests7, privatefield[160] invoiceBuyerValue, privatefield[64] invoiceBuyer
### Keybase proof
I hereby claim:
* I am lucasvo on github.
* I am lucasvo (https://keybase.io/lucasvo) on keybase.
* I have a public key ASDRA1cQdlFqOFA0k_3f3J33S0lzuaX7opUjcsTufqtQ0wo
To claim this, I am signing this object:
@lucasvo
lucasvo / example.go
Last active April 23, 2018 20:25
Precise Proofs Example
// ExampleDocument is a protobuf message
document := documents.ExampleDocument{
Value1: 1,
ValueA: "Foo",
ValueB: "Bar",
ValueBytes1: []byte("foobar"),
}
// The FillSalts method is a helper function that fills all fields with 32
// random bytes. SaltedExampleDocument is a protobuf message that has the
@lucasvo
lucasvo / CLA.md
Last active April 3, 2018 23:24
Centrifuge CLA

Centrifuge Individual Contributor License Agreement

This CLA is taken from http://harmonyagreements.org

Thank you for your interest in contributing to Centrifuge ("We" or "Us"). This contributor agreement ("Agreement") documents the rights granted by contributors to Us. To make this document effective, please sign it and send it to Us by electronic submission, following the instructions at github pull request. This is a legally binding document, so please read it carefully before agreeing to it. The Agreement may cover more than one software project managed by Us.

1. Definitions

"You" means the individual who Submits a Contribution to Us.

from inspirator import subscriberservice
from inspirator.models import Subscriber, DeliveryPreference
from pytz import timezone
from datetime import datetime, timedelta
import unittest
from freezegun import freeze_time
class TestDetermineNextSendDate(unittest.TestCase):
tz = timezone('Europe/Zurich')
now = datetime.now(tz).replace(hour=9)
@lucasvo
lucasvo / sys.out.sh
Created November 11, 2013 21:05
gradle runRequireJS
...
13:01:07.494 [DEBUG] [org.gradle.api.internal.externalresource.transport.http.JavaSystemPropertiesHttpProxySettings] Found java system property 'http.nonProxyHosts': local|*.local|169.254/16|*.169.254/16. Will ignore proxy settings for these hosts.
13:01:07.495 [DEBUG] [org.gradle.api.internal.externalresource.transport.http.HttpClientConfigurer] Using Credentials [username: reader] and NTLM Credentials [user: reader, domain: , workstation: MBLAV] for authenticating against 'null:-1'
13:01:07.497 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.memcache.InMemoryDependencyMetadataCache] Reusing in-memory cache for repo 'maven5' [25c6b342e2c18a4d2edfaf79658d6b1f].
13:01:07.501 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder] Visiting configuration com.jam:loginApp:0.1(rhino).
13:01:07.502 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder] Visiting dependency com.jam:loginApp:0.1(rhino) -> org.mozilla:rhino:1.
@lucasvo
lucasvo / gist:7200769
Created October 28, 2013 17:13
compileSass
MBLAV ➜ creamcheese (develop*) gradle watchSass
:installCompass UP-TO-DATE
:watchSass
BUILD SUCCESSFUL
Total time: 1.053 secs
MBLAV ➜ creamcheese (develop*) ps aux | grep sass
lucasvo 55333 2.5 0.6 3000824 107416 s001 S 10:09AM 0:04.70 /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -client -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Dfile.encoding=MacRoman -cp /Users/lucasvo/.gradle/caches/artifacts-26/filestore/org.jruby/jruby-complete/1.7.3/jar/2273e4c2a2abdd4b25a21bc513bfc05cfba31f3b/jruby-complete-1.7.3.jar org.jruby.Main -X-C -S compass watch --sass-dir /Users/lucasvo/Code/dundermifflin/creamcheese/src/scss --css-dir /Users/lucasvo/Code/dundermifflin/creamcheese/web-app/css/compiled --images-dir /Users/lucasvo/Code/dundermifflin/creamcheese/src/scss/sprites --app stand_alone --environment development --output-style compact --debug-info
lucasvo 55351 0.4 0.6 3001872 105904 s001 S 10:10AM 0:04.35 /System/Library/Java/JavaVirtualMachines