Skip to content

Instantly share code, notes, and snippets.

@ivoras
ivoras / simple_getopt.py
Last active April 23, 2024 12:05
A simple getopt() in Python
import re
# MIT license
RE_GETOPT_PARAM = re.compile(r"[a-zA-Z]:", re.ASCII)
RE_GETOPT_FLAG = re.compile(r"[a-zA-Z](?:[a-zA-Z]|$)", re.ASCII)
def simple_getopt(arg_list: list[str], spec: str) -> tuple[list[tuple[str, str]], list[str]]:
opts = []
args = []
all_param = [ x[0] for x in RE_GETOPT_PARAM.findall(spec) ]
@ivoras
ivoras / TestGeoHash.cs
Created February 5, 2020 15:28
A test for a geohash implementation
/*
* Created by SharpDevelop.
* User: ivoras
* Date: 05.02.2020.
* Time: 16:20
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Text;
@ivoras
ivoras / TestSign.cs
Created January 19, 2020 16:13
Digitally signing a buffer with a smart card certificate in C#
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace CertTest
{
class Program
{
public static void Main(string[] args)
@ivoras
ivoras / spatial_test.go
Created August 4, 2019 17:05
A benchmark test of four pure Go spatial indexing libraries: kdbush, go.geo/quadtree and rtreego, the latter in two variants: original and an optimized fork.
package main
import (
"math/rand"
"testing"
"github.com/MadAppGang/kdbush"
"github.com/dhconnelly/rtreego"
rtreego2 "github.com/patrick-higgins/rtreego"
geo "github.com/paulmach/go.geo"
@ivoras
ivoras / fertoken.sol
Last active April 5, 2019 12:27
A test for Ethereum web3 API with Metamask
pragma solidity >=0.4.19;
import "github.com/OpenZeppelin/zeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "github.com/OpenZeppelin/zeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";
/**
* @title FERToken is a basic ERC20 Token
*/
contract FERToken is ERC20, ERC20Detailed {
uint8 public constant DECIMALS = 4;
#!/usr/bin/env python
#-*- coding: utf-8 -*-
# Adapted from: https://github.com/vmichals/python-algos/blob/master/catmull_rom_spline.py
import numpy as np
def catmull_rom_one_point(x, v0, v1, v2, v3):
"""Computes interpolated y-coord for given x-coord using Catmull-Rom.
Computes an interpolated y-coordinate for the given x-coordinate between
@ivoras
ivoras / esp8266dash.ino
Created July 29, 2018 19:27
ESP8266 Dash button Arduino IDE sketch
// For use with this EasyEDA project: https://easyeda.com/account/project/setting/basic?project=c5413ffccb63491c831e6907e39ede2f
#include <EEPROM.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
#define PIN_POWER 2
#define PIN_LED 1
#define PIN_CONFIG 14
package main
import (
"crypto/ecdsa"
"crypto/x509"
"encoding/asn1"
"encoding/hex"
"log"
"math/big"
)
/*
* Tiny13Blinky.c
*
* Created: 21.04.2017. 11:21:09
* Author : ivoras
*/
#define F_CPU 1000000UL
#include <util/delay.h>
#include <FastLED.h>
#define PIN_PANEL 10
#define N_LEDS 64
#define BRIGHTNESS 255
#define FPS 120
CRGB leds[N_LEDS];
CRGB source_leds[N_LEDS];
CRGB target_leds[N_LEDS];