Skip to content

Instantly share code, notes, and snippets.

View hellwolf's full-sized avatar

Miao ZhiCheng hellwolf

View GitHub Profile
@hellwolf
hellwolf / rtoken-snippet.sol
Created August 6, 2019 11:25
rtoken sinippet
/**
* @notice Sender supplies assets into the market and receives rTokens in exchange
* @param mintAmount The amount of the underlying asset to supply
* @return uint 0=success, otherwise a failure
*/
function mint(uint256 mintAmount) external returns (bool);
/**
* @notice Sender redeems rTokens in exchange for the underlying asset
* @param redeemTokens The number of rTokens to redeem into underlying
pragma solidity >=0.4.21 <0.6.0;
// converted from cDAI.json
contract cDAI {
function name() external returns (
string memory
);
function approve(
address spender,
@hellwolf
hellwolf / abi-to-sol.js
Last active June 9, 2023 15:14
Convert ABI to solidity file
/**
* Convert ABI json file to solidity interface contract
*/
const fs = require('fs');
const args = process.argv.slice(2);
function convert(inputFilename) {
const abi = JSON.parse(fs.readFileSync(inputFilename, 'utf8'));
@hellwolf
hellwolf / mail.php
Last active January 20, 2021 17:20
mail.php
<?php
$SECRET = '....';
header("Content-type: application/json");
if ($_GET["secret"] != $SECRET) {
http_response_code(401);
echo json_encode(array(
"success" => false,
"status_code" => 401
@hellwolf
hellwolf / test-ecdh1-derive.sh
Created April 7, 2019 09:21
test ecdh1 derive mechanism
#!/bin/bash
openssl pkeyutl -derive -inkey new-secp384r1-private-key.pem -peerkey XXXXXXXX-pin1-public-key.pem | xxd -p | tr '\n' '|' | sed 's/|//g'
echo
pkcs11-tool --derive --token-label PIN1 --login --id 01 -m ECDH1-DERIVE --input-file new-secp384r1-public-key.der --output-file >(xxd -p | tr '\n' '|' | sed 's/|//g')
@hellwolf
hellwolf / gen-secp384r1-keypairs.sh
Created April 7, 2019 09:20
Generate secp384r1 key pairs
openssl ecparam -name secp384r1 -genkey -noout -out new-secp384r1-private-key.pem
openssl ec -in new-secp384r1-private-key.pem -pubout -outform DER -out new-secp384r1-public-key.der
@hellwolf
hellwolf / eesti-same-birthday.sh
Last active October 25, 2019 06:36
Estonian residents of the same birthday
YOUR_BIRTHDAY=YYMMDD;for a in 3 4;do
for i in `seq 9999`;do
kood=${a}${YOUR_BIRTHDAY}$(printf %04d $i)
# https://www.sk.ee/en/repository/ldap
found=$(ldapsearch -x -H ldaps://esteid.ldap.sk.ee -b c=EE "(serialNumber=PNOEE-$kood)" | sed -n 's/cn::\? \(.*\)$/\1/p' | uniq)
[ -z "${found%%*=}" ] && found=`echo $found|base64 -d`;[ ! -z "$found" ] && echo $kood $found;
done;
done
@hellwolf
hellwolf / truffle-minimize.sh
Created February 19, 2019 14:39
Truffle minimize json artifacts
#!/usr/bin/env bash
# Notes:
# - Shchema: https://github.com/trufflesuite/truffle/tree/develop/packages/truffle-contract-schema
# - bytecode vs deployedBytecode: https://ethereum.stackexchange.com/questions/32234/difference-between-bytecode-and-runtime-bytecode
for i in "$1"/*.json;do
[ -z "${i%%*.min.json}" ] && continue # already minified
m=${i%%.json}.min.json
echo "Minimizing truffle json artifact: $i"
echo "Original size: $(wc -c "$i")"
@hellwolf
hellwolf / truffle-json-inspect-sizes.sh
Last active February 19, 2019 14:19
jq sort truffle contract json artifact
jq -r '[
. as $root | keys[] as $k | $root[$k] | @json | length as $len | { key: $k, length: $len }
] | sort_by(.length) | reverse | map("\(.key) \(.length)")[]' $CONTRACT_JSON_FILE
@hellwolf
hellwolf / encstream.html
Last active October 21, 2018 16:42
Example crypto.subtle encrypt/decrypt with AES-CTR
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example crypto.subtle encrypt/decrypt with AES-CTR</title>
<meta name="description" content="The HTML5 Herald">
<meta name="author" content="SitePoint">