Skip to content

Instantly share code, notes, and snippets.

View 28's full-sized avatar
🌴

Dejan Josifović 28

🌴
View GitHub Profile
@danielsz
danielsz / http.clj
Last active May 23, 2024 15:04
Ring-compliant web server from scratch
(ns socket.http
(:require
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.logging :as log])
(:import [java.net ServerSocket]
[java.net SocketException]
[java.nio.file Files]
[java.io File]
[java.io InputStream OutputStream]))

20 million digits of pi in under a minute with Julia

I recently discovered a relatively obscure algorithm for calculating the digits of pi: https://en.wikipedia.org/wiki/Gauss–Legendre_algorithm. Well, at least obscure compared to Chudnovsky's. Wikipedia notes that it is "memory-intensive" but is it really? Let's compare to the MPFR pi function:

function gauss_legendre(prec)
    setprecision(BigFloat, prec, base=10)
    GC.enable(false)
@dracometallium
dracometallium / gmi2html.awk
Last active February 12, 2025 12:56
Another `text/gemini` to html translator, but this time it's AWK!
#!/usr/bin/gawk -f
BEGIN{
# Printing header!
print "<!DOCTYPE html>\n\
<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"\" xml:lang=\"\">\n\
<head>\n\
<meta charset=\"utf-8\" />\n\
<style type=\"text/css\">\n\
body{\n\
@28
28 / pretty-spit.clj
Last active June 29, 2022 21:09
A simple way to pretty print Clojure data/code to a file.
(require '[clojure.pprint :as pp]
'[clojure.edn :as edn])
(def collection-to-print {:a 1
:b 2
:c 3
:d [1 2 3 4 5]})
(defn pretty-spit
[file-name collection]
(spit (java.io.File. file-name)
@raysan5
raysan5 / custom_game_engines_small_study.md
Last active December 2, 2025 17:16
A small state-of-the-art study on custom engines

CUSTOM GAME ENGINES: A Small Study

a_plague_tale

WARNING: Article moved to separate repo to allow users contributions: https://github.com/raysan5/custom_game_engines

A couple of weeks ago I played (and finished) A Plague Tale, a game by Asobo Studio. I was really captivated by the game, not only by the beautiful graphics but also by the story and the locations in the game. I decided to investigate a bit about the game tech and I was surprised to see it was developed with a custom engine by a relatively small studio. I know there are some companies using custom engines but it's very difficult to find a detailed market study with that kind of information curated and updated. So this article.

Nowadays lots of companies choose engines like [Unreal](https:

@28
28 / partition.js
Created February 19, 2019 14:26
Multiple implementations of partition function in JavaScript.
function partition(array, partitionSize) {
if (partitionSize >= array.length)
return array;
var result = [];
var partition = [];
for (var i = 0; i < array.length; i++) {
if (partition.length < partitionSize) {
partition.push(array[i]);
console.log(partition);
}
(defn maze [n]
(->> (repeatedly (* n n) #(rand-nth "╱╲"))
(partition n)
(transduce
(comp
(map #(apply str %))
(interpose "\n"))
str)))
@28
28 / change_mac_address.sh
Created January 9, 2019 21:32
Change your MAC address to a random value
#!/usr/bin/env bash
a=$(ifconfig en0 | grep ether | sed -e 's/^[[:space:]]*ether//')
echo "Current MAC address:$a"
r=$(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//')
echo "New MAC address: $r"
echo $r | xargs sudo ifconfig en0 ether
import numpy as np
class NeuralNetwork:
def __init__(self, x, y):
self.input = x
self.weights1 = np.random.rand(self.input.shape[1],4)
self.weights2 = np.random.rand(4,1)
self.y = y
self.output = np.zeros(self.y.shape)
@johnhw
johnhw / umap_sparse.py
Last active May 11, 2025 07:18
1 million prime UMAP layout
### JHW 2018
import numpy as np
import umap
# This code from the excellent module at:
# https://stackoverflow.com/questions/4643647/fast-prime-factorization-module
import random