Skip to content

Instantly share code, notes, and snippets.

View soypat's full-sized avatar
🎴

Patricio Whittingslow soypat

🎴
View GitHub Profile
@soypat
soypat / _out.go
Created December 2, 2021 19:40
Interface documentation generation from methods.
package main
type Impl struct{}
func (Impl) X() {
}
type Xer interface{ X() } // X This is the xer implementation
// Second line
@soypat
soypat / helpers.go
Created September 3, 2021 02:27
Creating STL cylinders in go using sdfx
package helpers
import (
"github.com/deadsy/sdfx/sdf"
)
// Spaces sdf3's located at one point.
func DirectionalSpacing(shapes []sdf.SDF3, dir sdf.V3, baseSep float64) (spacings []sdf.V3) {
if dir.Equals(sdf.V3{}, 0) {
panic("direction must not be zero")
@soypat
soypat / fsnotify.go
Last active January 27, 2022 11:59
fsnotify tool
package main
import (
"context"
"fmt"
"io/fs"
stdlog "log"
"os"
"os/exec"
"os/signal"
@soypat
soypat / sub4section.cls
Created August 18, 2021 20:36
subsubsubsubsection for Latex
%----------------Lo de 4th layer de subsectrion
\titleclass{\subsubsubsection}{straight}[\subsection]
\newcounter{subsubsubsection}[subsubsection]
\renewcommand\thesubsubsubsection{\thesubsubsection.\arabic{subsubsubsection}}
\renewcommand\theparagraph{\thesubsubsubsection.\arabic{paragraph}} % optional; useful if paragraphs are to be numbered
\titleformat{\subsubsubsection}
{\normalfont\normalsize\bfseries}{\thesubsubsubsection}{1em}{}
@soypat
soypat / fastisqrt.go
Created May 23, 2021 19:04
Fast Inverse Root from Quake implemented in Golang
package quake
import "unsafe"
type float = float32
// FastISqrt implements Quake fast inverse square root
func FastISqrt(number float) float {
type long = uint64
const threehalf = 3. / 2.
@soypat
soypat / gomap.go
Created April 16, 2021 15:08
Ping addresses on a network for discovery. Use CIDR addresses, i.e. 192.168.1.0/24 (pings 256 addresses)
package main
import (
"errors"
"fmt"
"net"
"os"
"os/signal"
"strconv"
"sync"
@soypat
soypat / macroni.go
Last active November 5, 2021 02:14
Evaluate bitwise expressions and macros. i.e: 0xa3 &^ 0b001
package main
import (
"fmt"
"os"
"reflect"
"strings"
"github.com/cosmos72/gomacro/fast"
"github.com/spf13/pflag"
@soypat
soypat / sleep.go
Created February 12, 2021 18:02
Cgo usleep vs. pure Go time.Sleep. Run with `go test -bench=.`
package ctest
// #include <time.h>
// void wait(int usec)
// {
// usleep(usec);
// }
import "C"
import "time"
@soypat
soypat / syncAndGo.sh
Created February 7, 2021 13:10
Remote folder sync and Go execution. Ideal for Raspberry Pi
git_dir="software-v2"
project_path="$(git rev-parse --show-toplevel 2> /dev/null)/$git_dir"
[email protected]
if [ $? -eq 0 ]; then
# name of the project folder
project_name=`basename $project_path`
@soypat
soypat / su_bash.md
Last active February 10, 2021 17:05
  • # start comment on line. For examples # shall denote a file or argument of a command to facilitate examples

operators

  • #cmd_output > #file write output of command to file
  • #cmd_output >> #file append output to file
  • #cmd_output | #cmd redirect output to a command's input
  • #cmd1 && #cmd2 runs second command only if first one exited succesfully
  • #cmd & runs command in background