Skip to content

Instantly share code, notes, and snippets.

View padurean's full-sized avatar

Valentin Padurean (Ogg) padurean

View GitHub Profile
@padurean
padurean / ExecuteJavaScriptDynamically.scala
Created June 25, 2019 14:51
Execute JavaScript dynamically in Scala
def main(args: Array[String]): Unit = {
import javax.script.ScriptEngineManager
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
val engine = new ScriptEngineManager().getEngineByMimeType("text/javascript")
// val script = "-1000 * %d" format 3
val endless = "(function foo() { foo(); })()"
val result = Await.result(Future(engine.eval(endless)), 3.millis)
println(result)
// Example of how third-party imports and multiple files can be used in Go playground
package main
import (
"fmt"
"github.com/common-nighthawk/go-figure"
"your.universe/worlds"
)
package main
import (
"fmt"
"math"
)
func makeBatches(batchSize int, size int) [][]int {
batches := [][]int{}
nbBatches := int(math.Ceil(float64(size) / float64(batchSize)))
@padurean
padurean / copy.go
Created May 12, 2020 12:47 — forked from r0l1/copy.go
Copy a directory tree (preserving permissions) in Go.
/* MIT License
*
* Copyright (c) 2017 Roland Singer [roland.singer@desertbit.com]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
// Untar takes a destination path and a reader; a tar reader loops over the tarfile
// creating the file structure at 'dst' along the way, and writing any files
func Untar(dst string, r io.Reader) error {
gzr, err := gzip.NewReader(r)
if err != nil {
return err
}
defer gzr.Close()
// Tar takes a source and variable writers and walks 'source' writing each file
// found to the tar writer; the purpose for accepting multiple writers is to allow
// for multiple outputs (for example a file, or md5 hash)
func Tar(src string, writers ...io.Writer) error {
// ensure the src actually exists before trying to tar it
if _, err := os.Stat(src); err != nil {
return fmt.Errorf("Unable to tar files - %v", err.Error())
}
var tokenEncoder = base64.RawURLEncoding
// parsePublicTokenPayload parses the public (unencrypted) token payload
// works even with expired tokens (that do not pass verification)
func parsePublicTokenPayload(token string) (*JSONToken, error) {
tokenPieces := strings.Split(token, ".")
if len(tokenPieces) < 3 {
// version.purpose.payload or version.purpose.payload.footer
// see: https://tools.ietf.org/id/draft-paragon-paseto-rfc-00.html#rfc.section.2
return nil, errors.New("malformed token: expected at least 3 pieces")
{
"workbench.colorCustomizations": {
"editorBracketMatch.border": "#0000",
"[Palenight Italic]": {
"editorBracketMatch.background": "#030407"
}
},
"editor.tokenColorCustomizations": {
"[Joker Light (rainglow)]": {
"functions": "#007CBE",
@padurean
padurean / ca_and_cert_golang_demo.go
Created May 30, 2020 10:31 — forked from shaneutt/LICENSE
Golang: Demonstrate creating a CA Certificate, and Creating and Signing Certs with the CA
package main
import (
"bytes"
"crypto/rand"
"crypto/rsa"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
@padurean
padurean / programming-as-theory-building.md
Created June 1, 2020 15:52 — forked from onlurking/programming-as-theory-building.md
Programming as Theory Building - Peter Naur

Programming as Theory Building

Peter Naur

Peter Naur's classic 1985 essay "Programming as Theory Building" argues that a program is not its source code. A program is a shared mental construct (he uses the word theory) that lives in the minds of the people who work on it. If you lose the people, you lose the program. The code is merely a written representation of the program, and it's lossy, so you can't reconstruct