Skip to content

Instantly share code, notes, and snippets.

View zdila's full-sized avatar

Martin Ždila zdila

View GitHub Profile
@zdila
zdila / fridge-alarm.ino
Last active March 31, 2018 09:05
fridge-alarm.ino
#include <avr/sleep.h>
volatile unsigned long count = 0L;
unsigned long lastClosed = 0L;
int sensorPin = 0;
int buzzPin = 1;
ISR(WDT_vect) {
count++;
@zdila
zdila / snowfox.ino
Created April 3, 2018 17:31
Sigfox Snow Monitor
#include <SoftwareSerial.h>
#include <avr/sleep.h>
const int echoPin = 1;
const int trigPin = 2;
const int Rx = 3; // this is physical pin 2
const int Tx = 4; // this is physical pin 3
const int hcPin = 0;
SoftwareSerial mySerial(Rx, Tx);
// Tool for adding checksum and header (if missing) to uBlox UBX message.
// by Martin Ždila <[email protected]>
// License: CC0
const arg = process.argv[2];
if (!arg) {
console.error(`Usage: process.argv[0] process.argv[1] AABBCCDD...`);
process.exit(1);
}
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "DHT.h"
const char* ssid = "mywifi";
const char* password = "mysecret";
const char* host = "192.168.0.102";
DHT dht;
@zdila
zdila / earthExplorerDownloader.js
Last active September 7, 2018 11:30
earthexplorer.usgs.gov SRTM downloader
const fs = require('fs');
const axios = require('axios');
const parseSetCookie = require('set-cookie-parser');
const querystring = require('querystring');
class Cookies {
constructor() {
this.cookies = {};
}
@zdila
zdila / extract.sh
Created February 5, 2019 21:13
extract locus sqlitedb tiles
sqlite3 cesty_nlc_2017.sqlitedb "select writefile(z || '/' || x || '/' || y || '.png', image) from tiles"
@zdila
zdila / links.txt
Created November 2, 2019 09:59
SotM 2019 CZ+SK
@zdila
zdila / pyramid.js
Last active June 22, 2020 15:59
Generate TMS pyramid
import * as path from "https://deno.land/std/path/mod.ts";
const encoder = new TextEncoder();
const dot = encoder.encode(".");
const dash = encoder.encode("-");
for (let zz = 18; zz >= 0; zz--) {
const base = `/home/martin/ofmozaika/${zz + 1}`;
@zdila
zdila / merge_hgt.ts
Created August 26, 2020 21:25
Merge two HGT files taking nodata (-32768) into account.
const base = Deno.args[0];
const data1 = await Deno.readFile(`in1/${base}.HGT`);
const data2 = await Deno.readFile(`in2/${base}.HGT`);
const buf1 = new DataView(data1.buffer);
const buf2 = new DataView(data2.buffer);
for (let i = 0; i < buf2.byteLength - 1; i += 2) {
const val = buf2.getInt16(i, false);
@zdila
zdila / pLimit.ts
Created June 28, 2022 12:15
pLimit for modern Node
export function pLimit(concurrency: number) {
let running = 0;
let resolves: (() => void)[] = [];
return async <T>(fn: () => Promise<T>): Promise<T> => {
if (running >= concurrency) {
await new Promise<void>((resolve) => {
resolves.push(resolve);
});