Skip to content

Instantly share code, notes, and snippets.

View highfestiva's full-sized avatar

highfestiva highfestiva

View GitHub Profile
@highfestiva
highfestiva / int2float.py
Created August 23, 2022 14:35
Binary convert argument integers to doubles
#!/usr/bin/env python3
import struct
import sys
for i in sys.argv[1:]:
i = int(i[2:], 16) if i.lower().startswith('0x') else int(i)
d = struct.unpack('!d', struct.pack('!Q', i))[0]
print(d)
@highfestiva
highfestiva / torus.html
Last active July 14, 2022 17:52
Rotating WebGL Donut
<html>
<head>
</head>
<body>
<canvas style="width:100%; height:100%;"></canvas>
<script src="https://twgljs.org/dist/4.x/twgl-full.min.js"></script>
<script type="text/javascript">
const o = {
sectionVerts: 30,
@highfestiva
highfestiva / gen-consultancy-diary-xls.py
Last active June 13, 2023 17:39
Generates six months of consultancy diary rows
#!/usr/bin/env python3
from datetime import datetime
import pandas as pd
def prt(*args):
print('\t'.join(args), file=wf)
global line_no
line_no += 1
@highfestiva
highfestiva / py2nim.py
Last active October 31, 2021 21:59
py2nim transpiler
#!/usr/bin/env python3
'''Start of a trivial Python-to-Nim transpiler. So far, only a few
basic syntax matters are settled. Curious to see if it's hard to
get anything useful done with AST as input while hard-coding
output formatting.'''
from ast import *
from functools import reduce
ast_parse = parse
@highfestiva
highfestiva / mandelbrot2.nim
Last active September 20, 2021 08:25
nim 1.4.8 port of the java languange shootout version
# Ported from https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/mandelbrot-java-2.html
# Nim is about 29% faster than the Java 11 version.
#
# Build: nim c --threads:on -d:release --passC:-march=native mandelbrot2.nim && time ./mandelbrot2 16000 > m.pbm
# real 0m1.096s
# user 0m11.859s
# sys 0m0.141s
{.experimental, checks:off, optimization: speed.}
@highfestiva
highfestiva / mandelbrot.nim
Last active September 17, 2021 13:03
nim 1.4.8 mandelbrot
# Taken from https://github.com/def-/nim-benchmarksgame/blob/master/mandelbrot8.nim and made
# compile with v1.4.8.
#
# Build: nim c --threads:on -d:release mandelbrot.nim
# Run: time ./mandelbrot 16000 >image.pbm
# real 0m1.649s
# user 0m17.969s
# sys 0m0.172s
{.experimental.}
@highfestiva
highfestiva / time-convert.py
Created September 13, 2021 08:05
Epoch-ms conversion
import dateutil.parser
from datetime import datetime
import pytz
def local2timestamp(s):
return int(dateutil.parser.parse(s).timestamp() * 1000)
def timestamp2local(t):
return datetime.fromtimestamp(t/1000).isoformat().replace('T',' ')
@highfestiva
highfestiva / tcpserve.py
Created May 4, 2021 11:54
Check if a local TCP port is available
#!/usr/bin/env python3
import socket
import sys
host,port = sys.argv[1].split(':')
port = int(port)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host,port))
s.listen(1)
import math
import rand
const (
nan = math.nan()
)
union Data {
data_int []int
data_f64 []f64
@highfestiva
highfestiva / textsearch.v
Last active April 7, 2021 17:43
A fast grep-like cli tool, which skips the usual suspects. (My first vlang experiment.)
import os
import os.cmdline
const (
exclude_dirs = map{
'.git': 1
'.svn': 1
'__pycache__': 1
}