Skip to content

Instantly share code, notes, and snippets.

@hvoecking
hvoecking / translate.go
Last active March 28, 2024 13:52
Golang reflection: traversing arbitrary structures
// Traverses an arbitrary struct and translates all stings it encounters
//
// I haven't seen an example for reflection traversing an arbitrary struct, so
// I want to share this with you. If you encounter any bugs or want to see
// another example please comment.
//
// The MIT License (MIT)
//
// Copyright (c) 2014 Heye Vöcking
//
@DmitrySoshnikov
DmitrySoshnikov / dfs-bfs-non-recursive.js
Created October 19, 2015 05:40
Non-recursive DFS and BFS algorithms
/**
* Depth-first and Breadth-first graph traversals.
*
* In this diff we implement non-recursive algorithms for DFS,
* and BFS maintaining an explicit stack and a queue.
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* MIT Style license
*/
@nitoyon
nitoyon / rgb.go
Created January 1, 2016 16:08
Generate Animation GIF with Golang
package main
import (
"fmt"
"image"
"image/color"
"image/gif"
"math"
"os"
)
@magnetikonline
magnetikonline / README.md
Last active March 14, 2024 13:29
NSSM - the Non-Sucking Service Manager cheatsheet.
@border
border / mgoExample.go
Created August 27, 2012 15:33
mgo example
package main
import (
"fmt"
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
"time"
)
type Person struct {
@hyg
hyg / gist:9c4afcd91fe24316cbf0
Created June 19, 2014 09:36
open browser in golang
func openbrowser(url string) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
@yakuter
yakuter / cancel-io-copy.go
Created April 25, 2021 19:25
IO Copy cancellation
// Source: https://ixday.github.io/post/golang-cancel-copy/
import (
"io"
"context"
)
// here is some syntaxic sugar inspired by the Tomas Senart's video,
// it allows me to inline the Reader interface
type readerFunc func(p []byte) (n int, err error)
@naholyr
naholyr / _service.md
Created December 13, 2012 09:39
Sample /etc/init.d script

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
@bemasher
bemasher / rewrite.js
Created January 13, 2014 11:50
Relatively painless magnet uri generation for torrentz.eu. There's some extra scaffolding for extension related stuff but this is the main guts.
// Relatively painless magnet uri generation for torrentz.eu. Digging reveals
// that the torrent hash and id (torrentz.eu specific) are stored as hidden
// inputs for the comment system. All that's required is some Ajax and string
// parsing for the announce list and some html injection to add the link to
// the page.
// Get the torrent name, hash and id (for announce list lookup)
var name = $(".download>h2>span").first().text();
var hash = $(':input[name="hash"]').first().val()
var torrent = $(':input[name="torrent"]').first().val()
@bradleypeabody
bradleypeabody / gist:185b1d7ed6c0c2ab6cec
Last active November 29, 2023 22:08
golang, convert UTF-16 to UTF-8 string
package main
// http://play.golang.org/p/fVf7duRtdH
import "fmt"
import "unicode/utf16"
import "unicode/utf8"
import "bytes"
func main() {