Skip to content

Instantly share code, notes, and snippets.

@myrkvi
Created March 10, 2014 07:12
Show Gist options
  • Save myrkvi/9460685 to your computer and use it in GitHub Desktop.
Save myrkvi/9460685 to your computer and use it in GitHub Desktop.
Filler
#lang racket
(require racket/gui/base)
; Create the main window.
(define frame (new frame% [label "Filler"]
[min-width 300]
[min-height 240]
[style '(no-resize-border)]
))
; Create the status line
(send frame create-status-line)
; Create the text field for the file name.
(define file-text (new text-field% [parent frame]
[label "File:\t\t"]
[init-value "filled.txt"]
))
; Create the text field for the filler text
(define filler-text (new text-field% [parent frame]
[label "Filler:\t"]
[init-value "egg\n&\nbacon"]
[style '(multiple)]
))
; Select amount of times to repeat the task.
(define repeat-text (new text-field% [parent frame]
[label "Repetitions:\t"]
[init-value "500"]
))
; Create the button to start the filler.
(define filler-button (new button% [parent frame]
[label "Fill!"]
[callback (lambda (button event)
(send frame set-status-text "Started ...")
(let ([file (open-output-file (send file-text get-value) #:exists 'replace)]
[fill (send filler-text get-value)]
[f (eval (read (open-input-string (send repeat-text get-value))))])
(for ([i f])
(display fill file)
(display "\r\n" file))
(close-output-port file))
(send frame set-status-text "Finished.")
)]))
(send frame show #t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment