Skip to content

Instantly share code, notes, and snippets.

View ilmsg's full-sized avatar
😍
love me love my bug

Eak Netpanya ilmsg

😍
love me love my bug
View GitHub Profile
@ilmsg
ilmsg / go-shebang-story.md
Created April 19, 2023 01:35 — forked from posener/go-shebang-story.md
Story: Writing Scripts with Go

Story: Writing Scripts with Go

This is a story about how I tried to use Go for scripting. In this story, I’ll discuss the need for a Go script, how we would expect it to behave and the possible implementations; During the discussion I’ll deep dive to scripts, shells, and shebangs. Finally, we’ll discuss solutions that will make Go scripts work.

Why Go is good for scripting?

While python and bash are popular scripting languages, C, C++ and Java are not used for scripts at all, and some languages are somewhere in between.

@ilmsg
ilmsg / main.go
Created April 16, 2023 18:34 — forked from taka-wang/main.go
golang mutex
// refer to http://stackoverflow.com/questions/8286806/go-programming-language-mutual-concurrent-execution
// https://gobyexample.com/mutexes
package main
import "sync"
var m sync.Mutex
var wg sync.WaitGroup
func routine1() {
func DoReq() error {
resp, err := http.Get("http://localhost:8080/ping")
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return errors.New("bad response")
}
package main
import (
pixel "example/pixel"
"log"
"os"
"os/signal"
"syscall"
"time"
@ilmsg
ilmsg / gist:6a9ec7155d4e9b08fe6abb2fa6ba14c4
Created January 19, 2023 17:17 — forked from shopglobal/gist:75870369efd042031f67e98976892850
How To Set Up Automatic Deployment with Git with a VPS
Introduction
For an introduction to Git and how to install, please refer to the introduction tutorial.
This article will teach you how to use Git when you want to deploy your application. While there are many ways to use Git to deploy our application, this tutorial will focus on the one that is most straightforward. I assume you already know how to create and use a repository on your local machine. If not, please refer to this tutorial.
When you use Git, the workflow generally is toward version control only. You have a local repository where you work and a remote repository where you keep everything in sync and can work with a team and different machines. But you can also use Git to move your application to production.
Server Setup
Our fictitious workspace:
@ilmsg
ilmsg / beacon.py
Created December 3, 2022 06:05 — forked from N3MIS15/beacon.py
micropython iBeacon example
import struct
import ubluetooth as bt
from micropython import const
MANUFACTURER_ID = const(0x004C)
DEVICE_TYPE = const(0x02)
DATA_LENGTH = const(0x15)
BR_EDR_NOT_SUPPORTED = const(0x04)
FLAG_BROADCAST = const(0x01)
MANUFACTURER_DATA = const(0xFF)
@ilmsg
ilmsg / gin_jwt_middleware.go
Created November 23, 2022 06:00 — forked from mrcrilly/gin_jwt_middleware.go
Gin JWT Middleware (Example)
package main
import (
"errors"
"net/http"
"strconv"
"strings"
"time"
"github.com/dgrijalva/jwt-go"
@ilmsg
ilmsg / main.go
Created November 21, 2022 09:54 — forked from konojunya/main.go
Sample using gin's BindJSON
package main
import (
"fmt"
"log"
"github.com/gin-gonic/gin"
)
type CreateParams struct {
@ilmsg
ilmsg / client.go
Created November 11, 2022 01:44 — forked from vmarmol/client.go
Simple Go-based HTTP streaming via HTTP and websockets.
package main
import (
"encoding/json"
"flag"
"io"
"net/http"
"github.com/golang/glog"
"golang.org/x/net/websocket"
@ilmsg
ilmsg / dockerfile.md
Created November 5, 2022 01:26 — forked from kevwan/dockerfile.md
The simplest way to write Dockerfile!

1. choose a simple linux image

For example alpine, it's only about 5MB.

2. set timezone if necessary

RUN apk add --no-cache tzdata
ENV TZ America/New_York