Skip to content

Instantly share code, notes, and snippets.

View peheje's full-sized avatar

Peter peheje

View GitHub Profile
@peheje
peheje / Automata.fs
Last active May 20, 2023 22:09
Simple automata
// http://atlas.wolfram.com/01/01/
let on = 1uy
let off = 0uy
let print xs =
for x in xs do if x = on then printf "X" else printf " "
printf "\n"
let rule0 p _ r = (p + r) % 2uy
let rule51 _ q _ = (on + q) % 2uy
from mindstorms import MSHub, Motor, MotorPair, ColorSensor, DistanceSensor, App
from mindstorms.control import wait_for_seconds, wait_until, Timer
from mindstorms.operator import greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to, equal_to, not_equal_to
import math
hub = MSHub()
motors = MotorPair('E', 'A')
roll_target = 89
kp = 15.0
@peheje
peheje / jobWrapping.kt
Created August 27, 2020 18:32
Wrap job multiple times
import kotlin.random.Random
import kotlin.system.measureTimeMillis
fun main() {
val basicJob = BasicJob()
val delayedJob = DelayedJob(basicJob, 1000)
val measuredAndDelayedJob = MeasuredJob(delayedJob)
val measuredDelayedAndSynchronizedJob = SynchronizedJob(measuredAndDelayedJob, "lock")
measuredDelayedAndSynchronizedJob.run()
}
import java.lang.Exception
import java.nio.ByteBuffer
import java.security.MessageDigest
import java.util.*
import kotlin.math.abs
fun main() {
val filterSize = 1_000_000
val numberOfEntries = 100_000
import pyautogui
import time
time.sleep(2)
def record():
while True:
currentMouseX, currentMouseY = pyautogui.position()
print("(" + str(currentMouseX) + "," + str(currentMouseY) + ")")
time.sleep(3)
@peheje
peheje / main.kt
Created May 22, 2017 20:40
kotlin genetic
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.runBlocking
import kotlinx.coroutines.experimental.sync.Mutex
import java.util.*
import kotlin.system.measureTimeMillis
// BY peheje@github
fun stringToIntArray(str: String): IntArray {
; Seems to not work in Chrome browser.
; Tuborg clamps
<+<!8::SendInput {Raw}{
<+<!9::SendInput {Raw}}
; Brackets
<!8::SendInput {Raw}[
<!9::SendInput {Raw}]
@peheje
peheje / client.js
Created April 4, 2017 21:16
Node.js client-server timings.
const http = require("http");
const NanoTimer = require("nanotimer"); // Documentation: https://github.com/Krb686/nanotimer
function getNanoTime() {
const t = process.hrtime(); // Documentation: https://nodejs.org/api/process.html#process_process_hrtime_time
return t[0] * 1e9 + t[1]; // [seconds, nanoseconds]
}
const options = {
hostname: '127.0.0.1',
@peheje
peheje / Heap Swif 3.0
Last active August 28, 2018 05:45
Generic Heap in Swift with Min/Max implementation and tree printing
//: [Previous](@previous)
// Created by Peter Helstrup Jensen on 06-07-2015
// Copyright (c) 2015 Peter Helstrup Jensen. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
// version.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
@peheje
peheje / JSONSerializer.swift
Last active October 26, 2015 23:24
A JSON Serializer without inheritance
MOVED TO GITHUB PAGE https://github.com/peheje/JsonSerializerSwift