Skip to content

Instantly share code, notes, and snippets.

Avatar
⌨️
I am jumping on the keyboard

Sergey Tolmachev Tolsi

⌨️
I am jumping on the keyboard
View GitHub Profile
@Tolsi
Tolsi / two_mono_wav_to_stereo.py
Last active Dec 14, 2021
Converts two mono wav files to one stereo
View two_mono_wav_to_stereo.py
import wave, array
# changed from https://stackoverflow.com/a/43163543/699934
def make_stereo(file1, file2, output):
ifile1 = wave.open(file1)
ifile2 = wave.open(file2)
print(ifile1.getparams())
# (1, 2, 44100, 2013900, 'NONE', 'not compressed')
(nchannels, sampwidth, framerate, nframes, comptype, compname) = ifile1.getparams()
assert ifile1.getparams() == ifile2.getparams()
@Tolsi
Tolsi / ring.sh
Created May 11, 2021
Ring a bell in the command line
View ring.sh
echo -e \\a
@Tolsi
Tolsi / ctypes.py
Created Feb 21, 2020
handy ctypes examples
View ctypes.py
from ctypes import c_uint, c_int
print(c_uint(c_int(-49).value).value)
print(hex(c_uint(c_int(-49).value).value))
print(c_int(c_uint(0x7fffffcf).value).value)
print(hex(c_int(c_uint(0x7fffffcf).value).value))
# 4294967247
# 0xffffffcfL
View balenos_ble.asc

Ledger Nano X : Bluetooth Low Energy Communication

1.0

  • Public release

About

@Tolsi
Tolsi / twos_complement.py
Created Jan 21, 2020
Python twos_complement useful functions without ctypes
View twos_complement.py
def twos_complement(val, bits):
"""compute the 2's complement of int value val"""
if (val & (1 << (bits - 1))) != 0: # if sign bit is set e.g., 8bit: 128-255
val = val - (1 << bits) # compute negative value
return val
def twos_complement_string(val, bits, f):
if val >= 0:
return f(twos_complement(val, bits))
else:
@Tolsi
Tolsi / permutations.kt
Created Dec 17, 2019
Kotlin List permutations
View permutations.kt
fun <T> List<T>.permutations(): Sequence<List<T>> {
if (this.size == 1) return sequenceOf(this)
val list = this
return sequence {
val sub = list.get(0)
for (perm in list.drop(1).permutations())
for (i in 0..perm.size) {
val newPerm = perm.toMutableList()
newPerm.add(i, sub)
yield(newPerm)
View keybase.md

Keybase proof

I hereby claim:

  • I am tolsi on github.
  • I am tolsi (https://keybase.io/tolsi) on keybase.
  • I have a public key ASA0CeTgUKQhTLd-uw2sGJ9r8dBNvuXpKyS5jm2bQESQ5Ao

To claim this, I am signing this object:

@Tolsi
Tolsi / Base58Length.scala
Created May 21, 2018
Scala base58 bytes array size by string and string length by bytes array size
View Base58Length.scala
object Base58Length {
private val BytesMaxValue = 256
private val Base58MaxValue = 58
private val BytesLog = math.log(BytesMaxValue)
private val BaseLog = math.log(Base58MaxValue)
def base58Length(byteArrayLength: Int): Int = math.ceil(BytesLog / BaseLog * byteArrayLength).toInt
def bytesLength(base58Length: Int): Int = math.ceil(BaseLog / BytesLog * base58Length).toInt
}
@Tolsi
Tolsi / convert-cryptopro.sh
Created Mar 13, 2018
Export CryptoPro keys from Windows Regedit format
View convert-cryptopro.sh
#!/bin/bash
# Конвертация выгрузки ключей CryptoPro из реестра Windows в папочку с бинарными ключами
# Из реестра выгружать ветку HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Crypto Pro\Settings\Users\<кто-то>\Keys
# Converting the exported CryptoPro keys from the Windows registry to the container folder with binary keys
# Dump regedit path from the registry HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Crypto Pro\Settings\Users\<username>\Keys
curpath=./
temp=$curpath/temp
@Tolsi
Tolsi / SignAsWaves.scala
Created Feb 14, 2018
Sign Ed25519 As Whisper Systems Curve25519 used at Waves
View SignAsWaves.scala
package test
import com.muquit.libsodiumjna.SodiumLibrary
import scorex.crypto.encode.Base58
import scorex.crypto.signatures.Curve25519
object SignAsWaves extends App {
SodiumLibrary.setLibraryPath("/usr/local/Cellar/libsodium/1.0.16/lib/libsodium.dylib")
val message = "message"