Skip to content

Instantly share code, notes, and snippets.

struct List(Vec<i32>);
impl fmt::Display for List {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Dereference `self` and create a reference to `vec`
// via destructuring.
let List(ref vec) = *self;
try!(write!(f, "["));
// Iterate over `vec` in `v` while enumerating the iteration
#[derive(Debug)]
struct Color {
red: u8,
green: u8,
blue: u8,
}
impl fmt::Display for Color {
// `f` is a buffer, this method must write the formatted string into it
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "RGB ({0}, {1}, {2}) 0X{0:02.X}{1:02.X}{2:02.X}",

Keybase proof

I hereby claim:

  • I am hosszukalman on github.
  • I am kalmanhosszu (https://keybase.io/kalmanhosszu) on keybase.
  • I have a public key ASBWmnbk2aBlLeHf_mKw8vymXp_I3m_K0-m6U2yua7I8hwo

To claim this, I am signing this object:

package main
import (
"fmt"
"time"
)
func main() {
fmt.Println("Hello, playground")
start := time.Now()
package main
import (
"fmt"
"time"
)
func Start() (f Foo) {
fmt.Println("start with type")
return
@hosszukalman
hosszukalman / clear_struct.go
Created June 25, 2019 06:19
Permission based struct clearing
package main
import (
"fmt"
"reflect"
)
type User struct {
Permissions []string
}
@hosszukalman
hosszukalman / merge_structs.go
Created June 25, 2019 06:21
Permission based struct patch/merge
package main
import (
"encoding/json"
"fmt"
"reflect"
)
type User struct {
Permissions []string
@hosszukalman
hosszukalman / Caddyfile
Last active July 11, 2019 11:25
Monorepo with golang back-end, front-end and Caddy server
yourhost.dev:80 yourhost.dev:443 {
tls self_signed
proxy /api backend:8080 {
without /api
websocket
}
log stdout
errors stderr
@hosszukalman
hosszukalman / iota.go
Created September 12, 2019 14:51
Golang's iota
package main
import (
"fmt"
)
const zero = iota // Iota is the first in decalration scope, so it should be 0
const (
a = -2
@hosszukalman
hosszukalman / regex_copy_rename.sh
Created September 17, 2019 07:57
Copy and rename files based on regex
#!/bin/bash
find . -type f | perl -pe 'print $_; s/-english.html/-romanian.html/' | xargs -n2 cp