Skip to content

Instantly share code, notes, and snippets.

View carterpeel's full-sized avatar
📈
O(logn) enthusiast

Carter carterpeel

📈
O(logn) enthusiast
  • Grand Rapids, Michigan
  • 03:18 (UTC -04:00)
View GitHub Profile
@carterpeel
carterpeel / Video.java
Created October 31, 2020 01:56 — forked from idear1203/Video.java
Play .mp4 video using Java MediaPlayer for 5 seconds. After that, the video will be closed.
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.DoubleProperty;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.util.Duration;
@carterpeel
carterpeel / types.go
Created June 21, 2021 18:13
KVMTop Struct
package main
type systemMetrics struct {
Domains []struct {
UUID string `json:"UUID"`
CPUCores int64 `json:"cpu_cores"`
CPUOtherSteal int64 `json:"cpu_other_steal"`
CPUOtherTotal int64 `json:"cpu_other_total"`
CPUSteal int64 `json:"cpu_steal"`
CPUTotal int64 `json:"cpu_total"`
@carterpeel
carterpeel / Syslog-Aggregator.xml
Created June 24, 2021 16:09
Example XML definition for a syslog aggregator virtual machine
<domain type='kvm'>
<name>Syslog-Aggregator</name>
<uuid>71d383a1-05bc-4cdd-9439-8440f248eec2</uuid>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://centos.org/centos/8"/>
</libosinfo:libosinfo>
</metadata>
<memory unit='KiB'>14336000</memory>
<currentMemory unit='KiB'>14336000</currentMemory>
This file has been truncated, but you can view the full file.
A
a
aa
aal
aalii
aam
Aani
aardvark
aardwolf
Aaron
@carterpeel
carterpeel / boyer-moore.go
Created August 1, 2021 18:33
Boyer-More algorithm, ingests a []byte slice and returns the index of the first occurrence of `substr`. (this is particularly useful for large `substr` values)
package bm
import "bytes"
func BoyerMooreIndex(s, substr []byte) int {
d := CalculateSlideTable(substr)
return IndexWithTable(&d, s, substr)
}
func IndexWithTable(d *[256]int, s, substr []byte) int {
@carterpeel
carterpeel / fastbinary_test.go
Created January 30, 2022 16:38
Binary type switch is slow
package fastbinary
import (
"bytes"
"encoding/binary"
"io"
"testing"
)
func BenchmarkInternalBinary_Read(b *testing.B) {
@carterpeel
carterpeel / binary_read.go
Created January 30, 2022 16:46
binary.Read()
// Read reads structured binary data from r into data.
// Data must be a pointer to a fixed-size value or a slice
// of fixed-size values.
// Bytes read from r are decoded using the specified byte order
// and written to successive fields of the data.
// When decoding boolean values, a zero byte is decoded as false, and
// any other non-zero byte is decoded as true.
// When reading into structs, the field data for fields with
// blank (_) field names is skipped; i.e., blank field names
// may be used for padding.
@carterpeel
carterpeel / play.go
Created January 30, 2022 18:54
Player
func (p *audioPlayer) Play(session *rtsp.Session) {
log.Logger.WithField("category", "AirPlay Player").Warnf("Starting new session")
p.curSession = session
decoder := codec.GetCodec(session)
go func(dc *codec.Handler) {
var ok bool
for {
select {
/* Is using a pre-allocated buffer for a chan receiver more ideal than:
[buf, ok := <- session.DataChan]? */
@carterpeel
carterpeel / asyncio.go
Created February 7, 2022 20:32
Async IO in go
package asyncio
import (
"io"
"log"
"sync"
)
type AsyncMultiWriter struct {
mu *sync.Mutex
@carterpeel
carterpeel / tickpool.go
Created February 28, 2022 14:45
Ticker Pool
package tickpool
import (
"sync"
"time"
)
func init() {
mu = &sync.Mutex{}
pool = &sync.Pool{