Skip to content

Instantly share code, notes, and snippets.

View tnlogy's full-sized avatar

Tobias Teleman tnlogy

View GitHub Profile
@tnlogy
tnlogy / micrograd.lua
Last active March 22, 2024 13:17
micrograd.lua
--# Main
-- NN
function setup()
-- Neural Network of 3 layers with 3 inputs
local x = {Value(1), Value(1), Value(1)}
local layer1 = Layer(3, 4) -- layer of 4 neurons with 3 inputs
local layer2 = Layer(4, 4) -- layer of 4 neurons with 4 inputs
local layer3 = Layer(4, 1) -- layer of 1 neuron with 4 inputs
@tnlogy
tnlogy / Networkgame.lua
Created May 30, 2023 21:43
Network game in Codea using socket.udp and msgpack.lua with entity component system
--# Main
-- Rymdskepp
function setup()
viewer.mode = FULLSCREEN
setupMenu()
end
function setupMenu()
@tnlogy
tnlogy / advent_2022.py
Last active December 12, 2022 18:49
advent of code 2022 - don't look unless you have completed it :)
import numpy as np
def one(part=2):
"""Find the maximum sum, or the three maximum sums for rows of values"""
with open('input.txt', 'r') as f:
data = [np.sum(np.fromstring(d, sep="\n", dtype=int)) for d in f.read().split("\n\n")]
if part == 2:
print("one:2:", np.sum(np.sort(data)[-3:]))
else:
@tnlogy
tnlogy / pine.py
Created April 14, 2022 17:58
Connect to PineTime on ios with bluetooth on Pythonista 3
import cb
import struct
MOTION_SERVICE = "00030000-78fc-48fe-8e23-433b3a1942d0"
HR_SERVICE = '180d'
STEP = "00030001-78fc-48fe-8e23-433b3a1942d0"
RAW_MOTION = "00030002-78fc-48fe-8e23-433b3a1942d0"
HEART_RATE = '2a37'
CHARACTERISTICS = [STEP, RAW_MOTION, HEART_RATE]
@tnlogy
tnlogy / OutlineSimplify.lua
Created February 6, 2021 22:25
Lua code for Codea to create a physics polygon for a sprite
--# Main
function setup()
viewer.mode = FULLSCREEN
walls = {
physics.body(EDGE, vec2(0, 0), vec2(WIDTH, 0)),
physics.body(EDGE, vec2(0, 0), vec2(0, HEIGHT)),
physics.body(EDGE, vec2(WIDTH, HEIGHT), vec2(WIDTH, 0))
}
for k, v in ipairs(walls) do
@tnlogy
tnlogy / Editor.lua
Last active June 2, 2020 21:23
Tilemap editor for Codea
--# Main
function setup()
displayMode(FULLSCREEN)
s = Scene()
e = Editor(64)
s:add(Background())
s:add(e)
s:add(DPad(e))
s:add(SelectTile(e))
--# Main
-- Picker
-- Use this function to perform your initial setup
function setup()
p = Picker()
end
-- This function gets called once every frame
--# Main
-- Voronoi
function draw()
background(40, 40, 50)
startVoronoi()
end
--# Main
-- March
function setup()
local function sp(p)
return p:len() * p:dist(vec3(5,3,0))
end
local st = os.clock()
local vs = volume(sp, 9, .5, 6)
print(os.clock() - st)
--# Main
function setup()
parameter.boolean("FILL")
parameter.integer("RANGE", 1,20,3)
parameter.boolean("LINE")
parameter.boolean("FOV")
parameter.boolean("MOVE")
hs = Hexagons():createMesh():set(0,0,color(207, 67, 67))
u = Unit(hs:pos(0,0))