Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zupzup
zupzup / main.go
Created July 14, 2017 12:46
Example for Basic AST Traversal in Go
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/printer"
"go/token"
"log"
"os"
@zupzup
zupzup / main.go
Last active April 2, 2024 15:17
ElasticSearch to Prometheus Exporter in Go
package main
import (
"context"
"github.com/go-chi/chi"
"github.com/go-chi/render"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
"gopkg.in/olivere/elastic.v6"
@zupzup
zupzup / main.go
Created March 20, 2017 10:03
Go TCP Proxy / Port Forwarding Example (https://zupzup.org/go-port-forwarding/)
package main
import (
"flag"
"fmt"
"io"
"log"
"net"
"os"
"os/signal"
@zupzup
zupzup / main.rs
Created December 2, 2020 12:49
Timeular Webhooks Call List Subscriptions
println!("listing subscriptions...");
let subscriptions = list_subscriptions(&token).await?;
println!("subscriptions: {:?}", subscriptions);
@zupzup
zupzup / main.rs
Created December 2, 2020 12:47
Timeular Webhooks List Subscriptions
#[derive(Deserialize, Debug)]
struct SubscriptionsResponse {
subscriptions: Vec<Subscription>,
}
#[derive(Deserialize, Debug)]
struct Subscription {
id: String,
event: String,
target_url: String,
@zupzup
zupzup / shell
Created December 2, 2020 12:26
Timeular Webhooks Response 2
time entry was created with data: TrackingStoppedPayload { user_id: "1234", event_type: "trackingStopped", data: TrackingStoppedData { new_time_entry: Some(TimeEntry { id: "1234", activity: Activity { id: "1234", name: "Misc", color: "#17bbd2", integration: "zei", space_id: "1234", device_side: None }, duration: Duration { started_at: "2020-11-30T07:08:52.203", stopped_at: "2020-11-30T08:08:59.789" }, note: Note { text: None, tags: [], mentions: [] } }) } }
@zupzup
zupzup / shell
Created December 2, 2020 12:26
Timeular Webhooks Response 1
tracking was started with data: TrackingStartedPayload { user_id: "1234", event_type: "trackingStarted", data: TrackingStartedData { current_tracking: Tracking { id: 1234, activity: Activity { id: "1234", name: "Misc", color: "#17bbd2", integration: "zei", space_id: "1234", device_side: None }, started_at: "2020-11-30T07:08:52.203", note: Note { text: None, tags: [], mentions: [] } } } }
@zupzup
zupzup / shell
Created December 2, 2020 12:25
Timeular Webhooks Test
PUBLIC_URL=the-url-from-localtunnel TMLR_API_KEY=secret TMLR_API_SECRET=secret cargo run
@zupzup
zupzup / main.rs
Created December 2, 2020 12:25
Timeular Webhooks Server
let health_route = warp::path!("health").and_then(health_handler);
warp::serve(
started_tracking_route
.or(stopped_tracking_route)
.or(health_route),
)
.run(([0, 0, 0, 0], 8000))
.await;
Ok(())
@zupzup
zupzup / main.rs
Created December 2, 2020 12:25
Timeular Webhooks Types
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
struct TrackingStartedPayload {
user_id: String,
event_type: String,
data: TrackingStartedData,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]