Skip to content

Instantly share code, notes, and snippets.

@maxk42
maxk42 / compiling-python.md
Created July 14, 2024 19:35
Compiling python to executable via cython

I'm creating this gist because it has taken me far too long to find information on how to build python into an executable via cython. There are two key pieces of information you need after installing cython and a compiler: (I'll use gcc for this example.)

  1. Compiler flags need to be linked via the python3-config command.
  2. The python3-config command and the cython command both need to be invoked with the --embed flag.

For this exercise, we'll start with a file called hello.py with the following contents:

print("Hello, World!")
@maxk42
maxk42 / tiny.go
Created May 10, 2018 19:43
Tiny "Hello World" server in go with no dependencies except net/http
package main
import "net/http"
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r * http.Request) {
w.Write([]byte("Hello, World!\n"))
})
http.ListenAndServe(":80", nil)
}
// Node.js CheatSheet.
// Download the Node.js source code or a pre-built installer for your platform, and start developing today.
// Download: http://nodejs.org/download/
// More: http://nodejs.org/api/all.html
// 0. Synopsis.
// http://nodejs.org/api/synopsis.html
@maxk42
maxk42 / website.go
Last active January 16, 2022 01:08
Serving static and dynamic content together in golang
// This assumes your web app is running in a directory which has a subdirectory named 'public/' and
// that there is an 'img/' subdirectory in 'public/' containing an image named 'kitten.jpg'
package main
import (
"fmt"
"net/http"
)
@maxk42
maxk42 / README.md
Last active May 19, 2018 06:11
Simple demonstration of generics-like features in Go.

POLYMORPHISM AND GENERICS IN GO

Lately, Go has been getting a lot of flack for its lack of generics and parametric polymorphism. Whereas it doesn't have a specific language feature called "generics", generic type operations are very simple to implement. Here is a simple implementation of a generic collection type in Go demonstrating how it's done. Essentially, the type interface{} acts as a placeholder for any type. By making use of the empty interface, you can pass any type to a function much like you can in dynamically-typed languages.

Edit: Thanks to https://gist.github.com/mfenniak and https://gist.github.com/dominikh for pointing out that the add() function was equivalent to go's built-in append()