Skip to content

Instantly share code, notes, and snippets.

Avatar
🇭🇰

Lio李歐 lionello

🇭🇰
View GitHub Profile
@lionello
lionello / parseder.d
Created May 5, 2017
Parse a DER or PEM (base64) encoded ASN.1 file (certificates, keys, ...)
View parseder.d
import std.file : read;
import std.stdio;
import std.base64;
import std.string;
import std.conv;
import std.algorithm : map;
enum DerTag {
EndOfContent = 0x0,
Bool = 0x1,
@lionello
lionello / countingkeywords.d
Created May 5, 2017
Count/detect popular words in social media messages
View countingkeywords.d
#!/usr/bin/env dmd -run
import std.range;
struct Words(R,int maxWordLen = 4)
{
int wordLen;
R inner;
dchar[maxWordLen] buffer;
this(R inner) {
this.inner = inner.save;//refRange(&inner);
foreach (ref d; buffer) {
@lionello
lionello / robo.ino
Created May 5, 2017
A simple wall-following robot in Arduino (from Xinchejian roborace)
View robo.ino
#define MOTOR_L_F 6
#define MOTOR_L_B 5
#define MOTOR_R_B 9
#define MOTOR_R_F 10
#define SENSOR_L 11
#define SENSOR_F 12
void left(int speed)
{
@lionello
lionello / mrz.d
Last active Sep 7, 2017
MRZ (Machine Readable Zone) checksum calculator
View mrz.d
// Copyright Lionello Lunesu, placed in the public domain.
import std.algorithm;
import std.range;
ubyte charCode(dchar c) pure {
switch (c) {
case '<': return 0;
case 'A': .. case 'Z': return cast(ubyte)(c - 'A' + 10);
case '0': .. case '9': return cast(ubyte)(c - '0');
default: assert(0);
@lionello
lionello / imageset2mipmap.js
Last active Aug 22, 2017
Node.JS script to losslessly convert an iOS .imageset to an Android mipmap
View imageset2mipmap.js
#!/usr/bin/env node
const FS = require('fs')
const Path = require('path')
const FolderMap = {
"1x": "mipmap-mdpi",
"2x": "mipmap-xhdpi",
"3x": "mipmap-xxhdpi",
}
@lionello
lionello / optimize_eagle.d
Created Sep 17, 2017
Optimize paths in Eagle PCB files for faster CAM processing of GERBER files
View optimize_eagle.d
import std.xml;
import std.file;
import std.stdio;
import std.conv;
import std.math;
real EPSILON = 1e-2;
real distance_to_line(real fx, real fy, real tx, real ty, real px, real py) {
@lionello
lionello / androiduml.d
Last active Oct 20, 2017
Create PlantUML/graphviz dot activity diagram for an Android project
View androiduml.d
#!/usr/bin/env dmd -run
import std.xml;
import std.file;
import std.stdio;
Element getElementByTagName(Element parent, string name) {
foreach (child; parent.elements) {
if (child.tag.name == name) {
return child;
@lionello
lionello / ModExp.sol
Last active Mar 17, 2022
Solidity wrapper for Ethereum Byzantium's BigInt `modexp` built-in contract 0x5
View ModExp.sol
pragma solidity ^0.4.17;
contract ModExp {
// Wrapper for built-in bigint_modexp (contract 0x5) as described here https://github.com/ethereum/EIPs/pull/198
function modexp(bytes memory _base, bytes memory _exp, bytes memory _mod) public view returns(bytes memory ret) {
uint256 bl = _base.length;
uint256 el = _exp.length;
uint256 ml = _mod.length;
@lionello
lionello / base64url
Last active Feb 21, 2018
base64url: wrapper script for base64
View base64url
#!/usr/bin/env bash
ignore=0
decode=0
dashdash=0
args=()
files=()
while [ $# -gt 0 ]; do
if [ $dashdash -eq 1 ]; then
@lionello
lionello / repro181.sol
Last active Mar 14, 2018
Repro for Geth 1.8.x `eth.call` regression
View repro181.sol
#!/usr/bin/env node
const Child_process = require('child_process')
const Web3 = require('web3')
const Assert = require('assert')
const SOL = `
contract BS {
function isValidSignature(
address signer,
bytes32 hash,