Skip to content

Instantly share code, notes, and snippets.

View dockimbel's full-sized avatar

Nenad Rakocevic dockimbel

View GitHub Profile
@dockimbel
dockimbel / ftoi.reds
Created June 12, 2012 20:28
Float32! to integer! conversion routine
Red/System [
Title: "Float32! to integer! conversion routine"
Author: "Nenad Rakocevic"
Rights: "Copyright (C) 2011 Nenad Rakocevic. All rights reserved."
License: "BSD-3 - https://github.com/dockimbel/Red/blob/origin/BSD-3-License.txt"
Note: "Thanks to François Jouen for providing me the C code for ftoi()"
]
float-to-integer: func [
f [float32!] ;-- float 32-bit value to convert
int64_t ipow(int64_t base, uint8_t exp) {
static const uint8_t highest_bit_set[] = {
0, 1, 2, 2, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 255, // anything past 63 is a guaranteed overflow with base > 1
@rgchris
rgchris / rebol.ebnf
Last active December 12, 2015 06:08
EBNF Notation describing the REBOL (and family) Message Format
/*
REBOL Syntax
2012 by Christopher Ross-Gill
Based in Part on REBOLSource / REBOL Syntax by Earl, Ladislav and Steeve
https://github.com/rebolsource/rebol-syntax/
Designed for use with:
http://railroad.my28msec.com/rr/ui
For Future Ref:
make object! [
; Private Unicode Area for encoded delimiters and octets
url-pua-start: #"^(e000)"
url-pua-end: #"^(e0ff)"
delimiter: charset ":/?#[]@!$&'()*+,;="
hex-digit: charset [#"0" - #"9" #"a" - #"f" #"A" - #"F"]
ascii: charset [#"^(00)" - #"^(7f)"]
@qtxie
qtxie / random.reds
Last active December 18, 2015 19:09
Mersenne Twister algorithm Red/System implementation -- generates a random number using the Mersenne Twister algorithm. Reference http://code.google.com/p/c-standard-library/source/browse/src/internal/_rand.c
Red/System [
Title: "Mersenne Twister Random Function"
Author: "XieQ"
Tabs: 4
Purpose: {
Generates a random number using the Mersenne Twister algorithm.
Reference http://code.google.com/p/c-standard-library/source/browse/src/internal/_rand.c
}
]
@meijeru
meijeru / split.red
Last active September 28, 2015 14:48
Red mezzanine function to split a string
Red [
Title: "Split mezzanine"
Purpose: {split a string}
Author: "Rudolf W. MEIJER"
File: %split.red
Version: "0.0.0"
Date: "10-May-2015"
Rights: "(c) Copyright 2015 Rudolf W. MEIJER"
License: "TBD" ; source license (URL or full text)
]
@Oldes
Oldes / wav-reader-test.reds
Created September 14, 2015 14:23
Experimental WAV file parser
Red/System [
Title: "Red/System stream-io test - WAV reader"
Author: "Oldes"
]
#define handle! [pointer! [integer!]]
#define GENERIC_WRITE 40000000h
#define GENERIC_READ 80000000h
#define FILE_SHARE_READ 00000001h
Red []
forth: context [
prog: [1 2 3 4 5 6 7 8 '+ '+ '* 150 '+ '* '+ '* '*]
registers: ['eax 'ebx 'ecx 'edx]
register-taint: [] ; registers we've touched in this set
register-goop: [] ; registers we need to pop to use
register-sets: 0
next-register: head registers
Red [
Title: "Tile game"
Purpose: {An implementation in Red of the 4x4 sliding tile puzzle}
Author: "Rudolf W. MEIJER (meijeru)"
File: %tile-game.red
Needs: 'View
Usage: {
Click on any tile that is adjacent to the empty space
and it will shift to that space.
Try to obtain a given configuration, e.g. 1 to 15 in order.
Red []
random/seed 1337
; produces a series of chromosomes within [0, dna] of each supplied maximum
make-dna-strand: func[dna
/local dna-length result][
dna-length: length? dna
result: make block! dna-length
foreach chromosome dna [