Skip to content

Instantly share code, notes, and snippets.

View dockimbel's full-sized avatar

Nenad Rakocevic dockimbel

View GitHub Profile
@meijeru
meijeru / form.reds
Created May 3, 2011 08:20
FORM function in Red/System (improved version)
Red/System [
Title: "Form"
Purpose: {formats an integer in a c-string, as signed decimal or as hex}
Author: "Rudolf W. MEIJER"
File: %form-number.reds
Version: 0.7
Date: 27-May-2011
Notes: {Improved version, not final}
]
@meijeru
meijeru / %stringf.reds
Created May 7, 2011 17:44
String manipulation functions in Red/System, first working version
Red/System [
Title: "String functions"
Purpose: {proposed library functions for c-string manipulation}
Author: "Rudolf W. MEIJER"
File: %stringf.reds
Version: 0.1.0
Date: 27-May-2011
]
#import [
@meijeru
meijeru / reds-lex-grammar.r
Created June 25, 2011 10:18
Reds lexical grammar (is called by Reds lexer)
REBOL [
Title: "Grammar for Red/System lexical analysis"
Date: 1-Jul-2011
Name: "reds-lex-grammar"
Version: 1.0.0
File: %/G/Projects/Common/RED/red-system/sources/reds-lexer/reds-lex-grammar.r
Home: http://users.telenet.be/rwmeijer
Author: "Rudolf W. Meijer"
@meijeru
meijeru / reds-lexer.r
Created June 25, 2011 10:21
Reds lexer (drives separator + grammar)
REBOL [
Title: "Red/System lexical analysis"
Date: 1-Jul-2011
Name: "Reds lexer"
Type: none
Version: 1.0.0
File: %/G/Projects/Common/RED/red-system/sources/reds-lexer/reds-lexer.r
Home: http://users.telenet.be/rwmeijer
@meijeru
meijeru / unicode.reds
Created October 25, 2011 15:25
Encoding/decoding between Unicode and UTF-8: Red/System version
Red/System []
utf8-to-codepoint: func [ ; yields an integer >= 0 and < 1114112, or -1
u [c-string!] ; should have length 1 to 4
/local b1 b2 b3 b4
][
either 1 = length? u
[
b1: as-integer u/1
either b1 < 128 [
@meijeru
meijeru / unicode-multiple.r
Created October 25, 2011 17:02
UTF-8 string to block of Unicode codepoints conversion: REBOL
REBOL []
utf8-to-cps: func [ ; yields a block of integers >= 0 and < 1114112
; coding errors are skipped
u [binary!]
/local bcp b1 b2 b3 b4
][
bcp: make block! length? u ; overestimated
while [not tail? u][
b1: u/1
@meijeru
meijeru / unicode-multiple.reds
Created October 30, 2011 12:08
UTF-8 string to block of Unicode codepoints conversion: Red/System
Red/System []
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; function utf8-to-cps (cps = codepoints)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This function decodes UTF-8 information supplied as bytes in argument u
; and uses the argument res to store the array of codepoints
; (integers >= 0 and < 10FFFFh); the space for this array should have been
; allocated by the caller; an upper limit for the size of the array in bytes
@dockimbel
dockimbel / sym-test.reds
Created January 22, 2012 23:53
Simple math function bindings generates a missing symbol on Linux (works ok on Win/OSX)
Red/System []
#import [
LIBC-file cdecl [
sin: "sin" [
x [float!]
return: [float!]
]
]
]
@dockimbel
dockimbel / sub64.reds
Created January 24, 2012 23:59
Rough implementation of 64-bit integer subtraction
Red/System []
int64!: alias struct! [high [integer!] low [integer!]]
sub64: func [
a [int64!]
b [int64!]
return: [int64!]
/local
diff [int64!] offset [integer!]
@jboner
jboner / latency.txt
Last active July 26, 2024 04:31
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD