Skip to content

Instantly share code, notes, and snippets.

@axic
axic / linux-timestamp.rb
Created October 6, 2010 20:45
Turn the Linux kernel timestamp (from dmesg) into a date
input = ARGV.to_s.match(/^\[?([\d.]+)\]?/)
input = input[1] if input
uptime = File.new("/proc/uptime").gets
uptime = uptime.match(/^([\d.]+)/).to_a.first if uptime
if input and uptime then
puts(Time.now - uptime.to_f + input.to_f)
else
puts "unable to parse"
@axic
axic / gist:6675759231013e484c01
Created November 28, 2015 16:17
Onion Omega motd + dmesg (Kickstarter version)
BusyBox v1.23.2 (2015-09-13 17:56:41 UTC) built-in shell (ash)
____ _ ____
/ __ \___ (_)__ ___ / __ \__ _ ___ ___ ____ _
/ /_/ / _ \/ / _ \/ _ \ / /_/ / ' \/ -_) _ `/ _ `/
\____/_//_/_/\___/_//_/ \____/_/_/_/\__/\_, /\_,_/
W H A T W I L L Y O U I N V E N T ? /___/
-----------------------------------------------------
CHAOS CALMER (Chaos Calmer, r46849)
-----------------------------------------------------
@axic
axic / safer_ethereum_address.js
Created March 11, 2016 21:06
ERC: Safer Ethereum Address Format - Generator tool
var ethUtil = require('ethereumjs-util')
var fixtures = [
{
name: 'ethbase-1 ',
alphabet: 'abcdefghjklmnopqrstvwxyz',
magic: [ ]
},
{
name: 'ethbase-2 ',
@axic
axic / ecverify.sol
Last active April 13, 2024 09:01
Ethereum ECVerify
//
// The new assembly support in Solidity makes writing helpers easy.
// Many have complained how complex it is to use `ecrecover`, especially in conjunction
// with the `eth_sign` RPC call. Here is a helper, which makes that a matter of a single call.
//
// Sample input parameters:
// (with v=0)
// "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad",
// "0xaca7da997ad177f040240cdccf6905b71ab16b74434388c3a72f34fd25d6439346b2bac274ff29b48b3ea6e2d04c1336eaceafda3c53ab483fc3ff12fac3ebf200",
// "0x0e5cb767cce09a7f3ca594df118aa519be5e2b5a"
@axic
axic / stringaskey.sol
Last active July 10, 2019 00:10
How to use string as a key in a mapping in Solidity aka. how to store short strings cheape
//
// In Solidity, a mapping is like a hashmap and works with `string` like this:
// mapping (string => uint) a;
//
// However it doesn't support accessors where string is a key:
// mapping (string => uint) public a;
//
// "Internal compiler error: Accessors for mapping with dynamically-sized keys not yet implemented."
//
// An accessor returns uint when called as `a(string)`.
@axic
axic / README.md
Last active April 27, 2016 11:46
Ethereum HD KDF

There's a long discussion about using BIP32 (the Bitcoin HD wallet KDF) and BIP44 (the KDF path standard) for Ethereum.

It was raised that perhaps a different scheme could be useful.

How Bitcoin HD wallets work?

  1. A mnemonic (i.e. a list of memorable words) is generated (see BIP39)

  2. This mnemonic is converted to a seed using PBKDF2 (see BIP39)

@axic
axic / ETON.md
Created April 27, 2016 22:31
A very old proposal from November 2015

Ethereum Object Notation (ETON)

A simple ABI structure to replace JSON's object when passed between contracts. It is especially useful when interacting with outside oracles, where a JSON would be converted into this notation.

A JSON supports the following object types:

  • number (double precision floating point)
  • string (double quoted unicode string)
  • boolean (true or false)
  • array (ordered sequence)
  • null
@axic
axic / BigInt.sol
Created May 9, 2016 18:29
Big number library in Solidity (for modexp)
//
// Big number library in Solidity for the purpose of implementing modexp.
//
// Should have a similar API to https://github.com/ethereum/EIPs/issues/101
//
// Internally bignumbers are represented as an uint array of 128 bit values.
//
// NOTE: it assumes usage with "small" (<256bit) exponents (such as in RSA)
//
@axic
axic / README.md
Last active May 25, 2016 21:41
How to get started with Trezor-Ethereum (for developers only!)

Ethereum support in Trezor is in early development. The following steps can help you to get started.

First of all have a read at the protocol discussion thread.

To summarize the key decisions:

  • Transaction data is taken as raw binary, all fields of the transaction separately (in order they appear).
  • Every field is optional and it defaults to 0 if something is not supplied.
  • Trezor will internally recreate the RLP of those fields, hash it and create a signature.
  • The above is in a streaming manner and thus no RLP data is kept nor returned to the client.
  • Only the signature fields (v, r, s) are returned. The callee then needs to recreate the RLP structure and include the signature fields.
@axic
axic / swarmdemo.js
Created July 15, 2016 16:24
Web3 demo code for Swarm
//
// Needs web3.js from https://github.com/axic/web3.js/tree/swarm
//
var Web3 = require('web3')
var url = require('url')
var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'))
try {
web3.eth.defaultAccount = web3.eth.coinbase