Skip to content

Instantly share code, notes, and snippets.

View danesparza's full-sized avatar
:octocat:
The best way to predict the future is to invent it - Alan Kay

Dan Esparza danesparza

:octocat:
The best way to predict the future is to invent it - Alan Kay
View GitHub Profile
@danesparza
danesparza / logging.go
Created September 17, 2022 23:40 — forked from asdine/logging.go
Send zerolog errors to Sentry
package logger
import (
"encoding/json"
"fmt"
"io"
"log"
"os"
"runtime"
"time"
@danesparza
danesparza / client.html
Created February 16, 2022 14:11
Small golang / html Server Sent Events (SSE) proof of concept
<html>
<head>
<meta charset="UTF-8">
<title>Server-sent events demo</title>
</head>
<body>
<button>Close the connection</button>
<ul>
</ul>
@danesparza
danesparza / main.go
Created June 2, 2021 13:41
Motion detection using Raspberry Pi and a PIR
package main
import (
"flag"
"fmt"
"os"
"time"
"github.com/stianeikeland/go-rpio"
)
@danesparza
danesparza / talkingskull.ino
Created October 13, 2020 19:02
Updated jawduino code to control a servo based on sound
#include <Servo.h> // Standard servo library
Servo myservo;
#define SERVO_PIN 9 // Set to the controller pin for the servo
int servo_pos = 0;
int val1; // Floating value 1
int val2; // Floating value 2
int val3; // Floating value 3
@danesparza
danesparza / command.go
Created June 14, 2020 18:33
Start (and kill) a command with arguments from go
package main
import (
"log"
"os/exec"
"time"
)
func main() {
// Start a process:
@danesparza
danesparza / main.go
Created October 7, 2019 12:48
Send a Slack notification to a channel using an incoming webhook on an app
package main
import (
"bytes"
"encoding/json"
"errors"
"log"
"net/http"
"time"
)
@danesparza
danesparza / main.go
Created May 22, 2019 18:37
Create a QR code
package main
import (
"log"
qrcode "github.com/skip2/go-qrcode"
)
func main() {
err := qrcode.WriteFile("https://www.danesparza.net", qrcode.Medium, 128, "qr.png")
@danesparza
danesparza / lastqueries.sql
Created February 27, 2019 19:18
Last 50 queries run on SQL server
SELECT TOP 50 * FROM(SELECT COALESCE(OBJECT_NAME(s2.objectid),'Ad-Hoc') AS ProcName,
execution_count,s2.objectid,
(SELECT TOP 1 SUBSTRING(s2.TEXT,statement_start_offset / 2+1 ,
( (CASE WHEN statement_end_offset = -1
THEN (LEN(CONVERT(NVARCHAR(MAX),s2.TEXT)) * 2)
ELSE statement_end_offset END)- statement_start_offset) / 2+1)) AS sql_statement,
last_execution_time
FROM sys.dm_exec_query_stats AS s1
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS s2 ) x
WHERE sql_statement NOT like 'SELECT TOP 50 * FROM(SELECT %'
@danesparza
danesparza / main.go
Last active February 4, 2019 18:02
Test of ical library
package main
import (
"fmt"
"log"
"os"
"time"
"github.com/danesparza/ical"
"github.com/teambition/rrule-go"
@danesparza
danesparza / main.go
Created January 14, 2019 21:26
Command execution (with pipes) in Go / golang
package main
import (
"log"
"os/exec"
)
func main() {
// First, query the OS to get a list of Wifi AP SSIDs