Skip to content

Instantly share code, notes, and snippets.

View radutopala's full-sized avatar
🦅
Building in Go @trisoftro #golang

Radu Topala radutopala

🦅
Building in Go @trisoftro #golang
View GitHub Profile
@thanhminhmr
thanhminhmr / README.md
Last active March 28, 2025 12:34
Go doesn't have ternary, so created one...

go-ternary

Yes, I know—yet another attempt at bringing a ternary-like experience to Go. But hey, Go doesn’t have one, and I wasn’t around when the last million were written.

Why?

Because Go doesn't have a ternary operator, and according to the official FAQ, it likely never will. The reasoning? To prevent developers from writing "impenetrably complex expressions." But let's be real—poor coding practices exist in all forms. Instead of outright banning a useful construct, wouldn’t compiler warnings for overly complicated ternary expressions have been a more reasonable approach?

Since that's not happening, here’s go-ternary—because sometimes, a one-liner is just nicer than an if-else.

@rkibria
rkibria / gospinningcube.go
Last active May 3, 2023 09:40
Generate a .gif showing a spinning 3d wireframe cube with hidden lines in Golang
package main
import (
"fmt"
"image"
"image/color"
"image/gif"
"math"
"os"
)
package main
import (
"fmt"
"io/ioutil"
"net/http"
"sync"
"time"
"go.uber.org/ratelimit"
@bradfitz
bradfitz / sqlplay.go
Created June 23, 2021 17:23
sqlplay.go
package main
import (
"database/sql"
"flag"
"fmt"
"html"
"io"
"io/ioutil"
"log"
@0187773933
0187773933 / GolangSSHTunnelForwardAndReverse.go
Last active January 17, 2025 06:43
Golang SSH Forward and Reverse Tunnel
package main
import (
"context"
"fmt"
"os"
"os/signal"
"path"
"sync"
"syscall"
@m-radzikowski
m-radzikowski / script-template.sh
Last active March 27, 2025 02:37
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
<script type="module">
export default class RemoteContent extends HTMLElement {
constructor() {
super();
this.parser = new DOMParser();
this.shadow = this.attachShadow({mode: 'open'});
this.append = this.shadow.appendChild.bind(this.shadow);
this.shadow.innerHTML = 'loading…';
}
@izzygld
izzygld / Wysiwyg.vue
Created January 9, 2019 14:06
Adding a “show html” button in Quill (Wysiwyg).
<template>
<div>
<vue-editor v-model="content" ref="editor" :editor-options="toolbarOptions" @text-change="updateValue" useCustomImageHandler @imageAdded="uploadImage"></vue-editor>
</div>
</template>
<script>
import Vue from "vue";
import axios from 'axios'
let VueEditor, Quill;
@thiagozs
thiagozs / gomock.md
Last active February 13, 2025 18:36
Tutorial gomock

08/16/17 by  Sergey Grebenshchikov

No Comments

This is a quick tutorial on how to test code using the GoMock mocking library and the standard library testing package testing.

GoMock is a mock framework for Go. It enjoys a somewhat official status as part of the github.com/golang organization, integrates well with the built-in testing package, and provides a flexible expectation API.

@mohanpedala
mohanpedala / bash_strict_mode.md
Last active April 8, 2025 09:15
set -e, -u, -o, -x pipefail explanation