Skip to content

Instantly share code, notes, and snippets.

View dockimbel's full-sized avatar

Nenad Rakocevic dockimbel

View GitHub Profile
@dockimbel
dockimbel / eval2.red
Created April 3, 2018 10:12
Test script for Red/View Android backend
Red [
Title: "Red Android bridge demo"
Author: "Nenad Rakocevic"
File: %eval2.red
Config: [type: 'dll libRed?: no libRedRT?: yes export-ABI: 'cdecl]
Tabs: 4
Needs: 'View
Rights: "Copyright (C) 2013-2017 Nenad Rakocevic. All rights reserved."
License: {
Distributed under the Boost Software License, Version 1.0.
Red [
Purpose: "Implements a Pomodoro timer"
Note: "Original code from https://gitter.im/red/red/gui-branch?at=5ab95dae2b9dfdbc3a25636a"
]
Pomodoro: does [
context [
t: diff: b1: b2: end: none
view/no-wait [
title "Pomodoro"
@dockimbel
dockimbel / walk-files.red
Created March 21, 2018 08:41
Red source files header updater
Red []
dive: function [path action [block!] filter [block!]][
bind action 'path
if filter [bind filter 'path]
foreach file read path [
if dir? file [dive append copy path file action filter]
if any [not filter do filter][do action]
]
@dockimbel
dockimbel / persist-faces.red
Last active March 22, 2018 04:18
Save and reload a View face tree
Red [
Purpose: "Demo how to serialize/deserialize a face tree on disk"
]
mold-face: function [root [object!] return: [string!]][
foreach-face root [
face/parent: none face/state: none
if font: face/font [font/parent: none font/state: none]
if para: face/para [para/parent: none]
]
@dockimbel
dockimbel / parse-info.red
Last active October 24, 2017 08:46
Function to get stats about internal parse states usage for a given parsing job.
Red [
Title: "Parse Info"
Purpose: {
Provides some stats about internal parse states usage for a given parsing job.
Could be used as a way to compare efficiency of different parsing strategies.
}
Date: 06-Oct-2017
]
context [
@dockimbel
dockimbel / closure-by-value.red
Last active October 4, 2017 16:19
"Capture by value" closure generator
Red [
Purpose: {Implementation of a "capture-by-value" closure generator}
Date: 4-Oct-2017
]
collect-words: function [
spec [any-list!]
/deep
/set
/to-set
Red [
Note: "https://gitter.im/red/red?at=59d0e788f7299e8f539496d3"
]
time-it: func [block /count ct /local t baseline][
ct: any [ct 1]
t: now/time/precise
loop ct [do []]
baseline: now/time/precise - t
t: now/time/precise
turtle: #()
win: layout [ panel [
tfield: base 500x500 white draw []
origin tfield/offset tlayer: base 500x500 255.255.255.255 draw [] ]
panel [
text "History" return history: text-list 200x350 data [] return
panel [ button "Save" [save request-file history/data]
button "Load" [commands: load request-file foreach cmd commands [process-cmd cmd]] ]
return status: text "" 200x25 ]
@dockimbel
dockimbel / dyn-board.red
Last active July 8, 2017 15:52
Dynamic View usage example: drawing a board of buttons
Red [
Title: "Dynamic View usage example"
Author: "Nenad Rakocevic"
Date: 08/07/2017
]
generate: function [board [pair!] sz [pair!] return: [block!]][
pane: make block! sz/x * sz/y
pos: 1x1
count: 1
@dockimbel
dockimbel / arity-of.red
Created April 24, 2017 02:51 — forked from greggirwin/arity-of.red
Red arity-of function
; We have other reflective functions (words-of, body-of, etc.), but
; this is a little higher level, sounded fun to do, and may prove
; useful as we write more Red tools. It also shows how to make your
; own typesets and use them when parsing.
arity-of: function [
"Returns the fixed-part arity of a function spec"
spec [any-function! block!]
/with refs [refinement! block!] "Count one or more refinements, and add their arity"
][