Skip to content

Instantly share code, notes, and snippets.

View dtoebe's full-sized avatar

Daniel Toebe dtoebe

View GitHub Profile
@dtoebe
dtoebe / main.go
Created January 3, 2017 11:52
WRITE A SIMPLE MARKDOWN EDITOR WITH GO-QML - main.go - 3
//main.qml
...
import {
...
}
var ctx qml.Context //Global var to set the qml context
...
@dtoebe
dtoebe / main.qml
Created January 3, 2017 11:50
WRITE A SIMPLE MARKDOWN EDITOR WITH GO-QML - main.qml - 2
//assets/main.qml
...
TextArea {
id: mdarea
...
text: mdtxt //A variable name to reference from the Golang code
}
TextArea {
id: rtarea
@dtoebe
dtoebe / main.qml
Created January 3, 2017 11:49
WRITE A SIMPLE MARKDOWN EDITOR WITH GO-QML - main.qml - 1
//assets/main.qml
import QtQuick 2.3 //Needed to import all base QML entities
import QtQuick.Controls 1.4 //Needed for ApplicationWindow and TextArea
import QtQuick.Layouts 1.0 //For the RowLayout
ApplicationWindow { //The base entity so we can set a toolbar later and the layout
width: 640 //Default width
height: 480 //Default height
color: "#f1f1f1" //Background Color
@dtoebe
dtoebe / main.go
Created January 3, 2017 11:48
WRITE A SIMPLE MARKDOWN EDITOR WITH GO-QML - main.go - 2
//main.go
...
func run() error {
engine := qml.NewEngine() //Create the QML engine
engine.On("quit", func() { os.Exit(0) }) //If quit is called from QML the Golang program will gracefully quit
component, err := engine.LoadFile("assets/main.qml") //Load the QML file
if err != nil {
@dtoebe
dtoebe / main.go
Created January 3, 2017 11:47
WRITE A SIMPLE MARKDOWN EDITOR WITH GO-QML - main.go - 1
// main.go
package main
import (
"fmt"
"os"
"github.com/atotto/clipboard"
"github.com/russross/blackfriday"
@dtoebe
dtoebe / main.go
Created January 3, 2017 11:43
GENERATING DATAURI IMAGES WITH GO - main.go - 3
//main.go
...
func main() {
...
for ... {...}
// Here we allocate and create a buffer that can easily be
// turned into a []byte
@dtoebe
dtoebe / main.go
Created January 3, 2017 11:41
GENERATING DATAURI IMAGES WITH GO - main.go - 2
//main.go
package main
import (...)
func main() {
// Seed the std random number generator
rand.Seed(time.Now().UTC().UnixNano())
// We will leave out creating the png image file since we
@dtoebe
dtoebe / main.go
Created January 3, 2017 11:39
GENERATING DATAURI IMAGES WITH GO - main.go -1
//main.go
package main
import (
"fmt"
"image"
"image/color"
"image/draw"
"image/png"
"math/rand"
@dtoebe
dtoebe / main.go
Created January 3, 2017 11:30
EMBED OTHER BINARIES IN GOLANG BINARY - main.go - 2
// ./main.go
package main
import "os"
// When we run `go generate` from the cli it will run the
// `go run` command outlined below
// **Important: sure to include the comment below for the generator to see**
//go:generate go run generators/generator.go
@dtoebe
dtoebe / generators.go
Last active May 11, 2020 14:05
EMBED OTHER BINARIES IN GOLANG BINARY - generators.go - 1
// ./generators/generator.go
package main
//Much of this file is from http://stackoverflow.com/questions/17796043/golang-embedding-text-file-into-compiled-executable
import (
"fmt"
"io/ioutil"