Skip to content

Instantly share code, notes, and snippets.

View l1x's full-sized avatar
🏠
Working from home

Istvan l1x

🏠
Working from home
View GitHub Profile
let rec spiral m =
match m with
| [] -> []
| x::xs -> x @ spiral (List.rev (List.transpose xs))
[<EntryPoint>]
let main argv =
System.Console.WriteLine(sprintf "%A" (spiral [[1;2;3];[8;9;4];[7;6;5]])) // 1 2 3 4 5 6 7 8 9
System.Console.WriteLine(sprintf "%A" (spiral [[1; 2; 3; 4]; [5; 6; 7; 8]; [9; 10; 11; 12]; [13; 14; 15; 16]])) // 1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10
System.Console.WriteLine(sprintf "%A" (spiral [[1;2;3;4;5;6]; [7;8;9;10;11;12];[13;14;15;16;17;18]])) // 1 2 3 4 5 6 12 18 17 16 15 14 13 7 8 9 10 11
@l1x
l1x / ntp.erl
Last active March 1, 2023 08:14
NTP client in Erlang
-module(ntp).
-export([get_time/1, get_time/0]).
-define(NTP_PORT, 123). % udp
-define(SERVER_TIMEOUT, 5000). % ms
-define(EPOCH, 2208988800). % offset yr 1900 to unix epoch
ntp_servers() ->
[ "0.europe.pool.ntp.org",
@l1x
l1x / convert.sh
Last active April 25, 2020 22:09
Converting MKV or AVI to MP4 (h264, aac)
# with handbrake cli
for i in *.mkv; do
handbrake --preset-import-file fast.json --ab 192 -i "$i" -o "${i%.mkv}".mp4;
done
# or with ffmpeg
for f in *.avi; do
ffmpeg -i "$f" -c:v libx264 -c:a aac "${f%.avi}".mp4;
done
@l1x
l1x / Spiral.hs
Last active May 10, 2020 10:06
Spiral print in Haskell
module Main where
transpose :: [[Int]] -> [[Int]]
transpose m =
case m of
[] -> []
([]:_) -> []
x -> (map head x) : transpose (map (drop 1) x)
spiralPrintShort :: [[Int]] -> [Int]
@l1x
l1x / DateTime.elm
Last active April 8, 2020 22:35
Displaying Date and Time (zero padded values)
-- Show the current time in your time zone.
--
-- Read how it works:
-- https://guide.elm-lang.org/effects/time.html
import Browser
import Html exposing (..)
import Task
import Time exposing (..)
@l1x
l1x / raspberry.provision.sh
Last active April 5, 2020 17:57
Some provisioning for a default installation Raspbian
sudo apt update -y && sudo apt upgrade -y
sudo systemctl enable ssh
sudo systemctl start ssh
@l1x
l1x / rocksdb.build.centos7.sh
Last active March 31, 2020 11:38
CentOS 7 build script for RocksDB
#!/bin/bash
set -ex
ROCKSDB_VERSION="6.7.3"
ZSTD_VERSION="1.4.4"
echo "This script configures CentOS with everything needed to build and run RocksDB"
yum update -y && yum install epel-release -y
@l1x
l1x / safari.history.md
Last active October 5, 2023 09:06
SQL structure of Safari's history tables
sqlite3 ~/Library/Safari/History.db
sqlite> .tables
history_client_versions  history_items            history_tombstones
history_event_listeners  history_items_to_tags    history_visits
history_events           history_tags             metadata
Query failed (#20200116_080226_04202_txkag) in Presto:
Query exceeded per-node user memory limit of 20GB
[ Allocated: 20.00GB,
Delta: 688.14kB,
Top Consumers:
{ OrderByOperator=20.00GB,
TableScanOperator=260.90MB,
ExchangeOperator=5.71MB } ]
@l1x
l1x / aws_lambda_fsharp_dotnet_2.2.md
Last active December 2, 2019 09:16
Installing the environment for AWS Lambda and F# (Fsharp)

Installing .NET SDK

brew tap isen-ng/dotnet-sdk-versions
brew cask install dotnet-sdk-2.2.400

Creating Serverless Service

I think it is a good option to have separate dev and prod services in separate folders so we cannot accidentally deploy to prod, that is a problem when relying on environment variables.