Skip to content

Instantly share code, notes, and snippets.

@andelf
andelf / estimate_energy.py
Last active Mar 5, 2021
TRON estimate energy
View estimate_energy.py
#!/bin/env python3
import collections
import statistics
import sys
import requests
import base58
View parse_event.py
from tronpy import Tron
from tronpy.keys import keccak256
from pprint import pprint
client = Tron()
txn_id = 'e010654f48b5f94a4ea0305273bac3310b273979e1df61c8fd2334c52686ba6e'
txn_info = client.get_transaction_info(txn_id)
@andelf
andelf / README.md
Last active Feb 22, 2021
2-Step Random number for TRON(TVM)
View README.md

Output

function currentRequestId() view returns (uint256 )
function fulfillRandomRequest(uint256 reqId) returns (uint256 )
function isRequestIdFulfilled(uint256 ) view returns (bool )
function randomResult(uint256 ) view returns (uint256 )
function requestRandom() returns (uint256 requestId)
Current reqId: 10
req_id: 11  rand: 2
@andelf
andelf / font.py
Created Jan 16, 2021
CJK Font for Rust embedded-graphics
View font.py
from PIL import Image, ImageDraw, ImageFont
import PIL.features
# ! brew install libraqm
print('libraqm:', PIL.features.check('raqm'))
size = (320, 16)
"""
FORMAT = "RGB"
@andelf
andelf / STM32_HID_Bootloader.diff
Created Jan 12, 2021
STM32_HID_Bootloader path for a STM32F407VGT board
View STM32_HID_Bootloader.diff
diff --git a/bootloader/F4/Inc/main.h b/bootloader/F4/Inc/main.h
index a095644..e57185f 100644
--- a/bootloader/F4/Inc/main.h
+++ b/bootloader/F4/Inc/main.h
@@ -95,11 +95,11 @@
-#define BOOT_1_PIN GPIO_PIN_15 //DIYMROE STM32F407VGT board (Button PD15, LED PE0)
-#define BOOT_1_PORT GPIOD
@andelf
andelf / crop-blue30.py
Last active Jan 15, 2021
Generate Chinese font for waveshare-epd
View crop-blue30.py
from PIL import Image, ImageDraw, ImageFont, ImageFilter
im = Image.open("./blue30.png")
POS = (1, 4)
X = POS[0] * 80
Y = POS[1] * 80
im1 = im.crop((X, Y, X + 30, Y + 30))
@andelf
andelf / bmp085.rs
Created Nov 27, 2020
BMP085 Rust embedded-hal-driver
View bmp085.rs
use embedded_hal::blocking::delay::DelayMs;
use embedded_hal::blocking::i2c::{Write, WriteRead};
// BMP085 default address.
const BMP085_I2CADDR: u8 = 0x77;
// Operating Modes
pub const BMP085_ULTRALOWPOWER: u8 = 0;
pub const BMP085_STANDARD: u8 = 1;
pub const BMP085_HIGHRES: u8 = 2;
@andelf
andelf / calculate_pll_register_value.rs
Created Nov 11, 2020
calculate_pll_register_value for k210
View calculate_pll_register_value.rs
// nrx, nfx, no, nb
// clkr, clkf, clkod, bwad
#[allow(warnings)]
fn calculate_pll_register_value(freq_in: u32, freq_out: u32) -> Option<(u8, u8, u8, u8)> {
/* constants */
const vco_min: f64 = 3.5e+08;
const vco_max: f64 = 1.75e+09;
const ref_min: f64 = 1.36719e+07;
const ref_max: f64 = 1.75e+09;
const nr_min: i32 = 1;
@andelf
andelf / main.rs
Created Nov 7, 2020
Non-alloc string formatter for embedded Rust
View main.rs
use core::fmt::{self, Write};
use core::str;
fn main() {
// For LCD 160 / 8 = 20 chars
let mut buf = [0u8; 20];
let mut buf = ByteMutWriter::new(&mut buf[..]);
buf.clear();
write!(&mut buf, "Hello {}!", "Rust").unwrap();
@andelf
andelf / test.html
Created Oct 23, 2020
trezor-connect test
View test.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Trezor Test</title>
<meta name="description" content="The HTML5 Herald">
<meta name="author" content="SitePoint">