Skip to content

Instantly share code, notes, and snippets.

View BetterProgramming's full-sized avatar

BetterProgramming

View GitHub Profile
struct Provider: TimelineProvider {
private let quoteManager = QuoteManager()
[...]
func getSnapshot(in context: Context, completion: @escaping (QuoteEntry) -> ()) {
if context.isPreview {
let quote = Quote(quote: "Roses are red", author: "Nobody knows")
completion(QuoteEntry(date: Date(), quote: quote))
} else {
let quote = quoteManager.getSingleQuote()
completion(QuoteEntry(date: Date(), quote: quote))
@main
struct DailyQuote_Complications: Widget {
let kind: String = "ro.bartis.DailyQuote.Complications"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
DailyQuote_ComplicationsEntryView(entry: entry)
}
.configurationDisplayName("Daily Quote")
.description("This is a complication that shows you a new quote evey day")
}
struct DailyQuote_ComplicationsEntryView : View {
@Environment(\.widgetFamily) var widgetFamily
var entry: Provider.Entry
var body: some View {
switch widgetFamily {
case .accessoryCorner:
ComplicationCorner()
case .accessoryCircular:
ComplicationCircular()
struct ComplicationInline : View {
var body: some View {
Text("This will be a quote")
.widgetAccentable(true)
.unredacted()
}
}
struct ComplicationCircular : View {
var body: some View {
Text("This will be a quote")
func Start(w io.Writer) error {
tracing.Lock()
defer tracing.Unlock()
if err := runtime.StartTrace(); err != nil {
return err
}
go func() {
for {
data := runtime.ReadTrace()
if data == nil {
func Trace(w io.Writer) error {
if err := runtime.StartTrace(); err != nil {
return err
}
defer runtime.StopTrace()
go func() {
for {
data := runtime.ReadTrace()
if data == nil {
break
func (l *loggingT) setV(pc uintptr) Level {
fn := runtime.FuncForPC(pc)
file, _ := fn.FileLine(pc)
// The file is something like /a/b/c/d.go. We want just the d.
if strings.HasSuffix(file, ".go") {
file = file[:len(file)-3]
}
if slash := strings.LastIndex(file, "/"); slash >= 0 {
file = file[slash+1:]
}
package main
import (
"fmt"
"runtime"
)
func main() {
for i := 0 ; i< 4; i++ {
test(i)
func (h *boringHMAC) Reset() {
if h.needCleanup {
C._goboringcrypto_HMAC_CTX_cleanup(&h.ctx)
} else {
h.needCleanup = true
// Note: Because of the finalizer, any time h.ctx is passed to cgo,
// that call must be followed by a call to runtime.KeepAlive(h),
// to make sure h is not collected (and finalized) before the cgo
// call returns.
runtime.SetFinalizer(h, (*boringHMAC).finalize)
func (s server) ServeMemProfile(ws *websocket.Conn) {
defer ws.Close()
var payload struct {
MemStats runtime.MemStats
GCStats debug.GCStats
NumGoroutine int
}
for {
payload.NumGoroutine = runtime.NumGoroutine()
runtime.ReadMemStats(&payload.MemStats)