Skip to content

Instantly share code, notes, and snippets.

View sgeos's full-sized avatar
💭
Too much to do, not enough time.

Brendan A R Sechter sgeos

💭
Too much to do, not enough time.
View GitHub Profile
import Html
quote(do: markup do: text("hi")) |> Code.eval_quoted
markup do: text("hi")
@sgeos
sgeos / simplex_noise.ex
Last active August 7, 2016 11:59
Elixir implementation of simplex noise.
# Reference:
# http://webstaff.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
# Simplex noise in 2D, 3D and 4D
defmodule SimplexNoise do
@grad3 {
{1, 1, 0}, {-1, 1, 0}, {1, -1, 0}, {-1, -1, 0},
{1, 0, 1}, {-1, 0, 1}, {1, 0, -1}, {-1, 0, -1},
{0, 1, 1}, {0, -1, 1}, {0, 1, -1}, {0, -1, -1}
}
@sgeos
sgeos / classic_noise.ex
Last active August 7, 2016 12:00
Elixir implementation of classic Perlin noise.
# Reference:
# http://webstaff.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
# Classic Perlin noise in 3D, for comparison
defmodule ClassicNoise do
@grad3 {
{1, 1, 0}, {-1, 1, 0}, {1, -1, 0}, {-1, -1, 0},
{1, 0, 1}, {-1, 0, 1}, {1, 0, -1}, {-1, 0, -1},
{0, 1, 1}, {0, -1, 1}, {0, 1, -1}, {0, -1, -1}
}
@sgeos
sgeos / simplex_noise_improved.ex
Created August 8, 2016 04:44
Elixir translation of Stefan Gustavson's open source simplex noise implementation with improved 4D rank ordering.
# A speed-improved simplex noise algorithm for 2D, 3D and 4D
# translated from Java into Elixir.
#
# Based on example code by Stefan Gustavson (stegu@itn.liu.se).
# Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).
# Better rank ordering method for 4D by Stefan Gustavson in 2012.
# Translated into Elixir by Brendan Sechter (bsechter@sennue.com).
#
# The Java version could be speeded up even further, but it's useful
# as it is. Assessment of Java optimazations for the Elixir version
@sgeos
sgeos / simplex_noise_reference.ex
Last active August 13, 2016 14:55
Simplex noise reference implementation in Elixir.
# Reference:
# http://www.csee.umbc.edu/~olano/s2002c36/ch02.pdf
# https://www.google.com/patents/US6867776
# A complete implementation of a function returning a value that
# conforms to the new method is given below.
# Translated from Java class definition to Elixir module.
defmodule SimplexNoiseReference do
use Bitwise
@sgeos
sgeos / exrm_ecto_create_drop_tasks.sh
Last active September 13, 2016 09:39
exrm PostgreSQL/MySQL release equivalents for `mix ecto.create` and `mix ecto.drop`.
# PostgreSQL `mix ecto.create` equivalent
psql -c "CREATE USER ${DB_USER} WITH PASSWORD '${DB_PASSWORD}';"
createdb "${DB_NAME}"
psql -c "GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} to ${DB_USER};"
# PostgreSQL `mix ecto.drop` equivalent
dropdb "${DB_NAME}"
dropuser "${DB_USER}"
# PostgresSQL interactive terminal
@sgeos
sgeos / qsort_ascending.c
Last active July 8, 2023 06:37
C qsort example. It takes a list of values from the command line and sorts them in ascending order.
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
void usage(const char *pProgramName) {
printf("Usage: %s x y z ...\n", pProgramName);
printf("Example: %s 818 -3 566 5 12 100 12 25\n", pProgramName);
printf(" This program will sort numbers in ascending order.\n");
}
// ChatGPT Prompt
// Please write a Rust function to generate rooms in a Rogue style dungeon.
// Thoughts:
// As far as basic structure goes, this works. It needs a lot of work to be useful.
use rand::Rng;
struct Dungeon {
width: usize,
@sgeos
sgeos / no_std_rust_string_ffi_example.rs
Last active July 27, 2023 01:23
no_std_rust_string_ffi_example.rs
#![no_std]
extern crate alloc;
extern crate libc;
use alloc::{ boxed::Box, ffi::CString, string::{ String, ToString, } };
use hashbrown::HashMap;
use libc::{ c_char, c_void, printf, };
#[no_mangle]
@sgeos
sgeos / gimp-batch-coloring-book-convert.scm
Last active July 27, 2023 01:23
gimp-batch-coloring-book-convert.scm
(map
(lambda (image)
(gimp-image-undo-group-start image)
(define fullpath (car (gimp-image-get-filename image)))
(define filename (car (reverse (strbreakup fullpath "/"))))
(define path (car (strbreakup fullpath filename)))
(define basefilename (car (strbreakup filename ".")))
(define xcfpath (string-append path basefilename ".xcf"))
(define linepath (string-append path "bw_" basefilename ".png"))